Ejemplo n.º 1
0
    def call(self, inputs, training=None, **kwargs):
        layer_util.check_inputs(inputs, 2, "ResidualBlock")

        return self._act(
            self._norm(inputs=self._conv3d(inputs=inputs[0]), training=training)
            + inputs[1]
        )
Ejemplo n.º 2
0
    def build(self, input_shape):
        super(LocalNetUpSampleResnetBlock, self).build(input_shape)
        layer_util.check_inputs(input_shape, 2, "UpSampleResnetBlock build")

        output_shape = input_shape[1][1:4]
        self._deconv3d_block = Deconv3dBlock(
            filters=self._filters, output_shape=output_shape, strides=2
        )
        if self._use_additive_upsampling:
            self._additive_upsampling = AdditiveUpSampling(output_shape=output_shape)
Ejemplo n.º 3
0
    def call(self, inputs, training=None, **kwargs):
        layer_util.check_inputs(inputs, 2, "UpSampleResnetBlock call")

        inputs_nonskip, inputs_skip = inputs[0], inputs[1]
        h0 = self._deconv3d_block(inputs=inputs_nonskip, training=training)
        if self._use_additive_upsampling:
            h0 += self._additive_upsampling(inputs=inputs_nonskip)
        r1 = h0 + inputs_skip
        r2 = self._conv3d_block(inputs=h0, training=training)
        h1 = self._residual_block(inputs=[r2, r1], training=training)
        return h1
Ejemplo n.º 4
0
    def build(self, input_shape):
        """
        :param input_shape: list [nonskip_tensor_shape, skip_tensor_shape]
        :return: None
        """
        super(LocalNetUpSampleResnetBlock, self).build(input_shape)
        layer_util.check_inputs(input_shape, 2, "UpSampleResnetBlock build")

        output_shape = input_shape[1][1:4]
        self._deconv3d_block = Deconv3dBlock(
            filters=self._filters, output_shape=output_shape, strides=2
        )
        if self._use_additive_upsampling:
            self._additive_upsampling = AdditiveUpSampling(output_shape=output_shape)
Ejemplo n.º 5
0
    def call(self, inputs, training=None, **kwargs):
        """
        :param inputs: list = [inputs_nonskip, inputs_skip]
        :param training (bool): training flag for normalization layers (default: None)
        :param kwargs:
        :return:
        """
        layer_util.check_inputs(inputs, 2, "UpSampleResnetBlock call")

        inputs_nonskip, inputs_skip = inputs[0], inputs[1]
        h0 = self._deconv3d_block(inputs=inputs_nonskip, training=training)
        if self._use_additive_upsampling:
            h0 += self._additive_upsampling(inputs=inputs_nonskip)
        r1 = h0 + inputs_skip
        r2 = self._conv3d_block(inputs=h0, training=training)
        h1 = self._residual_block(inputs=[r2, r1], training=training)
        return h1
Ejemplo n.º 6
0
def test_check_inputs():
    """
    Test check_inputs by confirming that it accepts proper
    types and handles a few simple cases.
    """
    # Check inputs list - Pass
    assert layer_util.check_inputs([], 0) is None

    # Check inputs tuple - Pass
    assert layer_util.check_inputs((), 0) is None

    # Check inputs int - Fail
    with pytest.raises(ValueError) as execinfo:
        layer_util.check_inputs(0, 0)
    msg = " ".join(execinfo.value.args[0].split())
    assert "Inputs should be a list or tuple" in msg

    # Check inputs float - Fail
    with pytest.raises(ValueError) as execinfo:
        layer_util.check_inputs(0.0, 0)
    msg = " ".join(execinfo.value.args[0].split())
    assert "Inputs should be a list or tuple" in msg

    # Check size float - Fail
    with pytest.raises(ValueError) as execinfo:
        layer_util.check_inputs([1], 0.5)
    msg = " ".join(execinfo.value.args[0].split())
    assert "Inputs should be a list or tuple of size" in msg

    # Check size 0 - Pass
    assert layer_util.check_inputs([], 0) is None
    assert layer_util.check_inputs((), 0) is None

    # Check size 0 - Fail
    with pytest.raises(ValueError) as execinfo:
        layer_util.check_inputs([0], 0)
    msg = " ".join(execinfo.value.args[0].split())
    assert "Inputs should be a list or tuple of size" in msg
    with pytest.raises(ValueError) as execinfo:
        layer_util.check_inputs((0, ), 0)
    msg = " ".join(execinfo.value.args[0].split())
    assert "Inputs should be a list or tuple of size" in msg

    # Check size 1 - Pass
    assert layer_util.check_inputs([0], 1) is None
    assert layer_util.check_inputs((0, ), 1) is None

    # Check size 1 - Fail
    with pytest.raises(ValueError) as execinfo:
        layer_util.check_inputs([], 1)
    msg = " ".join(execinfo.value.args[0].split())
    assert "Inputs should be a list or tuple of size" in msg
    with pytest.raises(ValueError) as execinfo:
        layer_util.check_inputs((), 1)
    msg = " ".join(execinfo.value.args[0].split())
    assert "Inputs should be a list or tuple of size" in msg