Пример #1
0
def test_add_pattern_bd(art_warning, get_default_mnist_subset,
                        image_dl_estimator):
    try:
        image = add_pattern_bd(x=np.ones((4, 4, 4, 3)),
                               distance=2,
                               pixel_value=0)
        assert image.shape == (4, 4, 4, 3)
        assert np.min(image) == 0

        image = add_pattern_bd(x=np.ones((3, 3, 3)), distance=2, pixel_value=0)
        assert image.shape == (3, 3, 3)
        assert np.min(image) == 0

        image = add_pattern_bd(x=np.ones((2, 2)), distance=2, pixel_value=0)
        assert image.shape == (2, 2)
        assert np.min(image) == 0

        with pytest.raises(ValueError):
            _ = add_pattern_bd(x=np.ones((5, 5, 5, 5, 5)),
                               distance=2,
                               pixel_value=0)

    except ARTTestException as e:
        art_warning(e)
 def poison_func_1(self, x):
     max_val = np.max(self.x_train_mnist)
     return np.expand_dims(add_pattern_bd(x.squeeze(3),
                                          pixel_value=max_val),
                           axis=3)
Пример #3
0
 def mod(x):
     return perturbations.add_pattern_bd(x, pixel_value=255)
Пример #4
0
 def mod(x):
     original_dtype = x.dtype
     x = np.transpose(x, (0, 2, 3, 1)).astype(np.float32)
     x = add_pattern_bd(x)
     x = np.transpose(x, (0, 3, 1, 2)).astype(np.float32)
     return x.astype(original_dtype)
Пример #5
0
 def mod(x):
     original_dtype = x.dtype
     x = add_pattern_bd(x)
     return x.astype(original_dtype)