Exemple #1
0
def test_mask_applied():
    test_image = tf.ones([10, 40, 40, 1], dtype=np.uint8)
    result_image = random_cutout(test_image, 20, seed=1234)
    total_expected_masked_count = 20 * 20 * test_image.shape[0]

    np.testing.assert_equal(
        np.sum(result_image) + total_expected_masked_count, np.sum(test_image))
Exemple #2
0
def test_batch_size():
    test_image = tf.random.uniform([10, 40, 40, 1],
                                   dtype=np.float32,
                                   seed=1234)
    result_image = random_cutout(test_image, 20, seed=1234)
    np.testing.assert_allclose(tf.shape(result_image), [10, 40, 40, 1])
    means = np.mean(result_image, axis=(1, 2, 3))
    np.testing.assert_allclose(len(set(means)), 10)
Exemple #3
0
def test_different_channels():
    for channel in [0, 1, 3, 4]:
        test_image = tf.ones([1, 40, 40, channel], dtype=np.uint8)
        cutout_area = tf.zeros([4, 4], dtype=np.uint8)
        cutout_area = tf.pad(cutout_area, ((0, 36), (0, 36)), constant_values=1)
        expect_image = to_4D_image(cutout_area)
        expect_image = tf.tile(expect_image, [1, 1, 1, channel])
        result_image = random_cutout(test_image, 20, seed=1234)
        np.testing.assert_allclose(tf.shape(result_image), tf.shape(expect_image))
Exemple #4
0
def test_channel_first():
    test_image = tf.ones([10, 1, 40, 40], dtype=np.uint8)
    cutout_area = tf.zeros([4, 4], dtype=np.uint8)
    cutout_area = tf.pad(cutout_area, ((0, 36), (0, 36)), constant_values=1)
    expect_image = tf.expand_dims(cutout_area, 0)
    expect_image = tf.expand_dims(expect_image, 0)
    expect_image = tf.tile(expect_image, [10, 1, 1, 1])
    result_image = random_cutout(test_image,
                                 20,
                                 seed=1234,
                                 data_format="channels_first")
    np.testing.assert_allclose(tf.shape(result_image), tf.shape(expect_image))
Exemple #5
0
def test_mask_larger_than_image():
    test_image = tf.ones([10, 40, 40, 1], dtype=np.uint8)
    result_image = random_cutout(test_image, 60, seed=1234)
    np.testing.assert_equal(np.sum(result_image), 0)