Beispiel #1
0
def test_init_LocalNet():
    """
    Testing init of LocalNet as expected
    """
    local_test = loc.LocalNet(
        image_size=[1, 2, 3],
        out_channels=3,
        num_channel_initial=3,
        extract_levels=[1, 2, 3],
        out_kernel_initializer="he_normal",
        out_activation="softmax",
    )

    # Asserting initialised var for extract_levels is the same - Pass
    assert local_test._extract_levels == [1, 2, 3]
    # Asserting initialised var for extract_max_level is the same - Pass
    assert local_test._extract_max_level == 3
    # Asserting initialised var for extract_min_level is the same - Pass
    assert local_test._extract_min_level == 1

    # Assert downsample blocks type is correct, Pass
    assert all(
        isinstance(item, type(layer.DownSampleResnetBlock(12)))
        for item in local_test._downsample_blocks
    )
    #  Assert number of downsample blocks is correct (== max level), Pass
    assert len(local_test._downsample_blocks) == 3

    # Assert upsample blocks type is correct, Pass
    assert all(
        isinstance(item, type(layer.LocalNetUpSampleResnetBlock(12)))
        for item in local_test._upsample_blocks
    )
    #  Assert number of upsample blocks is correct (== max level - min level), Pass
    assert len(local_test._upsample_blocks) == 3 - 1

    # Assert upsample blocks type is correct, Pass
    assert all(
        isinstance(item, type(layer.Conv3dWithResize(12, filters=3)))
        for item in local_test._extract_layers
    )
    #  Assert number of upsample blocks is correct (== extract_levels), Pass
    assert len(local_test._extract_layers) == 3
Beispiel #2
0
    def test_init(self, image_size, extract_levels):
        network = loc.LocalNet(
            image_size=image_size,
            out_channels=3,
            num_channel_initial=3,
            extract_levels=extract_levels,
            out_kernel_initializer="he_normal",
            out_activation="softmax",
        )

        # asserting initialised var for extract_levels is the same - Pass
        assert network._extract_levels == extract_levels
        # asserting initialised var for extract_max_level is the same - Pass
        assert network._extract_max_level == max(extract_levels)
        # asserting initialised var for extract_min_level is the same - Pass
        assert network._extract_min_level == min(extract_levels)

        # assert downsample blocks type is correct, Pass
        assert all(
            isinstance(item, layer.DownSampleResnetBlock)
            for item in network._downsample_blocks
        )
        # assert number of downsample blocks is correct (== max level), Pass
        assert len(network._downsample_blocks) == max(extract_levels)

        # assert upsample blocks type is correct, Pass
        assert all(
            isinstance(item, layer.LocalNetUpSampleResnetBlock)
            for item in network._upsample_blocks
        )
        # assert number of upsample blocks is correct (== max level - min level), Pass
        assert len(network._upsample_blocks) == max(extract_levels) - min(
            extract_levels
        )

        # assert upsample blocks type is correct, Pass
        assert all(
            isinstance(item, layer.Conv3dWithResize) for item in network._extract_layers
        )
        # assert number of upsample blocks is correct (== extract_levels), Pass
        assert len(network._extract_layers) == len(extract_levels)
Beispiel #3
0
    def test_call(self, image_size, extract_levels):
        # initialising LocalNet instance
        network = loc.LocalNet(
            image_size=image_size,
            out_channels=3,
            num_channel_initial=3,
            extract_levels=extract_levels,
            out_kernel_initializer="he_normal",
            out_activation="softmax",
        )

        # pass an input of all zeros
        inputs = tf.constant(
            np.zeros(
                (5, image_size[0], image_size[1], image_size[2], 3), dtype=np.float32
            )
        )
        # get outputs by calling
        output = network.call(inputs)
        # expected shape is (5, 1, 2, 3, 3)
        assert all(x == y for x, y in zip(inputs.shape, output.shape))
Beispiel #4
0
def test_call_LocalNet():
    """
    Asserting that output shape of LocalNet call method
    is correct.
    """
    out = 3
    im_size = [1, 2, 3]
    #  Initialising LocalNet instance
    global_test = loc.LocalNet(
        image_size=im_size,
        out_channels=out,
        num_channel_initial=3,
        extract_levels=[1, 2, 3],
        out_kernel_initializer="glorot_uniform",
        out_activation="sigmoid",
    )
    # Pass an input of all zeros
    inputs = np.zeros((5, im_size[0], im_size[1], im_size[2], out))
    #  Get outputs by calling
    output = global_test.call(inputs)
    #  Expected shape is (5, 1, 2, 3, 3)
    assert all(x == y for x, y in zip(inputs.shape, output.shape))
def test_local_return():
    """
    Testing that build_backbone func returns an object
    of type LocalNet from backbone module when initialised
    with the associated LocalNet config.
    """
    out = util.build_backbone(
        image_size=(1, 2, 3),
        out_channels=1,
        model_config={
            "backbone": "local",
            "local": {
                "num_channel_initial": 4,
                "extract_levels": [1, 2, 3]
            },
        },
        method_name="ddf",
    )
    assert isinstance(
        out,
        type(
            local_net.LocalNet([1, 2, 3], 4, 4, [1, 2, 3], "he_normal",
                               "sigmoid")),
    )