def test_attack_convergence(bn_model, bn_criterion, bn_images, bn_labels): attack = BoundaryAttack(bn_model, bn_criterion) advs = attack(bn_images, bn_labels, unpack=False, verbose=True) for adv in advs: assert adv.perturbed is not None assert adv.distance.value < np.inf attack2 = BoundaryAttack(bn_model, bn_criterion) bn_images2 = np.array([adv.perturbed for adv in advs]) advs2 = attack2(bn_images2, bn_labels, unpack=False, iterations=5000) for adv in advs2: # should converge assert adv.perturbed is not None assert adv.distance.value < np.inf
def test_attack(bn_model, bn_criterion, bn_images, bn_labels): attack = BoundaryAttack(bn_model, bn_criterion) advs = attack(bn_images, bn_labels, unpack=False, iterations=200, verbose=True) for adv in advs: assert adv.perturbed is not None assert adv.distance.value < np.inf
def test_attack_parameters3(bn_model, bn_criterion, bn_images, bn_labels): attack = BoundaryAttack(bn_model, bn_criterion) np.random.seed(2) starting_point = np.random.uniform(0, 1, size=bn_images[0].shape).astype( bn_images.dtype) advs = attack(bn_images, bn_labels, unpack=False, iterations=200, starting_point=starting_point, log_every_n_steps=2, tune_batch_size=30, threaded_rnd=False, threaded_gen=False, verbose=True) for adv in advs: assert adv.perturbed is not None assert adv.distance.value < np.inf