コード例 #1
0
ファイル: test_layer.py プロジェクト: knvsmadhav/DeepReg
def test_localNetUpSampleResnetBlock():
    """
    Test the layer.LocalNetUpSampleResnetBlock class, its default attributes and its call() function.
    """
    batch_size = 5
    channels = 4
    input_size = (32, 32, 16)
    output_size = (64, 64, 32)

    nonskip_tensor_size = (batch_size, ) + input_size + (channels, )
    skip_tensor_size = (batch_size, ) + output_size + (channels, )

    # Test __init__() and build()
    model = layer.LocalNetUpSampleResnetBlock(8)
    model.build([nonskip_tensor_size, skip_tensor_size])

    assert model._filters == 8
    assert model._use_additive_upsampling is True

    assert isinstance(model._deconv3d_block, type(layer.Deconv3dBlock(8)))
    assert isinstance(model._additive_upsampling,
                      type(layer.AdditiveUpSampling(output_size)))
    assert isinstance(model._conv3d_block, type(layer.Conv3dBlock(8)))
    assert isinstance(model._residual_block,
                      type(layer.LocalNetResidual3dBlock(8)))
コード例 #2
0
ファイル: test_layer.py プロジェクト: knvsmadhav/DeepReg
def test_deconv3dBlock():
    """
    Test the layer.Deconv3dBlock class and its default attributes. No need to test the call() function since a
    concatenation of tensorflow classes
    """

    deconv3dBlock = layer.Deconv3dBlock(8)

    assert isinstance(deconv3dBlock._deconv3d, layer.Deconv3d)
    assert deconv3dBlock._deconv3d._Conv3DTranspose is None

    deconv3dBlock._deconv3d.build((8, 8))

    assert isinstance(
        deconv3dBlock._deconv3d._Conv3DTranspose,
        type(tf.keras.layers.Conv3DTranspose(8, 3)),
    )
    assert tuple(deconv3dBlock._deconv3d._kernel_size) == (3, 3, 3)
    assert tuple(deconv3dBlock._deconv3d._strides) == (1, 1, 1)
    assert deconv3dBlock._deconv3d._padding == "same"
    assert deconv3dBlock._deconv3d._Conv3DTranspose.use_bias is False

    assert isinstance(deconv3dBlock._act._act, type(tf.keras.activations.relu))
    assert isinstance(deconv3dBlock._norm._norm,
                      type(tf.keras.layers.BatchNormalization()))
コード例 #3
0
ファイル: local_net.py プロジェクト: vsaase/DeepReg
    def __init__(
        self,
        filters: int,
        output_padding: Union[int, Tuple, List],
        kernel_size: Union[int, Tuple, List],
        padding: str,
        strides: Union[int, Tuple, List],
        output_shape: Tuple,
        name: str = "AdditiveUpsampling",
    ):
        """
        Addictive up-sampling layer.

        :param filters: number of channels for output
        :param output_padding: padding for output
        :param kernel_size: arg for deconv3d
        :param padding: arg for deconv3d
        :param strides: arg for deconv3d
        :param output_shape: shape of the output tensor
        :param name: name of the layer.
        """
        super().__init__(name=name)
        self.deconv3d = layer.Deconv3dBlock(
            filters=filters,
            output_padding=output_padding,
            kernel_size=kernel_size,
            strides=strides,
            padding=padding,
        )
        self.resize = layer.Resize3d(shape=output_shape)
コード例 #4
0
    def build_up_sampling_block(
        self,
        filters: int,
        output_padding: Union[Tuple[int, ...], int],
        kernel_size: Union[Tuple[int, ...], int],
        padding: str,
        strides: Union[Tuple[int, ...], int],
        output_shape: Tuple[int, ...],
    ) -> Union[tf.keras.Model, tfkl.Layer]:
        """
        Build a block for up-sampling.

        This block changes the tensor shape (width, height, depth),
        but it does not changes the number of channels.

        :param filters: number of channels for output
        :param output_padding: padding for output
        :param kernel_size: arg for deconv3d
        :param padding: arg for deconv3d
        :param strides: arg for deconv3d
        :param output_shape: shape of the output tensor
        :return: a block consists of one or multiple layers
        """
        return layer.Deconv3dBlock(
            filters=filters,
            output_padding=output_padding,
            kernel_size=kernel_size,
            strides=strides,
            padding=padding,
        )
コード例 #5
0
ファイル: test_layer.py プロジェクト: knvsmadhav/DeepReg
def test_upsampleResnetBlock():
    """
    Test the layer.UpSampleResnetBlock class and its default attributes. No need to test the call() function since a
    concatenation of tensorflow classes
    """
    batch_size = 5
    channels = 4
    input_size = (32, 32, 16)
    output_size = (64, 64, 32)

    input_tensor_size = (batch_size, ) + input_size + (channels, )
    skip_tensor_size = (batch_size, ) + output_size + (channels // 2, )

    model = layer.UpSampleResnetBlock(8)
    model.build([input_tensor_size, skip_tensor_size])

    assert model._filters == 8
    assert model._concat is False
    assert isinstance(model._conv3d_block, type(layer.Conv3dBlock(8)))
    assert isinstance(model._residual_block, type(layer.Residual3dBlock(8)))
    assert isinstance(model._deconv3d_block, type(layer.Deconv3dBlock(8)))
コード例 #6
0
def test_deconv3d_block():
    """
    Test the layer.Deconv3dBlock class and its default attributes.
    """

    deconv3d_block = layer.Deconv3dBlock(8)

    assert isinstance(deconv3d_block._deconv3d, layer.Deconv3d)
    assert deconv3d_block._deconv3d._deconv3d is None

    deconv3d_block._deconv3d.build((8, 8))

    assert isinstance(
        deconv3d_block._deconv3d._deconv3d, tf.keras.layers.Conv3DTranspose
    )
    assert tuple(deconv3d_block._deconv3d._kernel_size) == (3, 3, 3)
    assert tuple(deconv3d_block._deconv3d._strides) == (1, 1, 1)
    assert deconv3d_block._deconv3d._padding == "same"
    assert deconv3d_block._deconv3d._deconv3d.use_bias is False

    assert isinstance(deconv3d_block._act._act, type(tf.keras.activations.relu))
    assert isinstance(deconv3d_block._norm._norm, tf.keras.layers.BatchNormalization)