def test_add_single_bd(art_warning, get_default_mnist_subset, image_dl_estimator): try: image = add_single_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_single_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_single_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_single_bd(x=np.ones((5, 5, 5, 5, 5)), distance=2, pixel_value=0) except ARTTestException as e: art_warning(e)
def poison_func_2(self, x): max_val = np.max(self.x_train_mnist) return np.expand_dims(add_single_bd(x.squeeze(3), pixel_value=max_val), axis=3)
def mod(x): return perturbations.add_single_bd(x, pixel_value=255)