def recipe( sess, model, x, y, nb_classes, eps, clip_min, clip_max, eps_iter, nb_iter, report_path, eps_iter_small, batch_size, ): """ Mock recipe that just runs the Noise attack so the test runs fast """ attack_configs = [AttackConfig(Noise(model, sess), {"eps": eps})] new_work_goal = {config: 1 for config in attack_configs} goals = [Misclassify(new_work_goal=new_work_goal)] bundle_attacks( sess, model, x, y, attack_configs, goals, report_path, attack_batch_size=batch_size, eval_batch_size=batch_size, )
def test_misclassify_request_examples(): cfg = AttackConfig(None, None) goal = Misclassify(new_work_goal={cfg: 1}) correctness = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1], dtype=np.bool) run_counts = np.array([1, 1, 1, 0, 0, 0, 1, 1, 1, 0], dtype=np.int64) criteria = {'correctness': correctness} batch_size = 3 idxs = goal.request_examples(cfg, criteria, {cfg: run_counts}, batch_size) assert idxs.shape == (batch_size,) idxs = list(idxs) for already_misclassified in [0, 2, 4, 6, 8]: assert already_misclassified not in idxs for already_run in [1, 7]: assert already_misclassified not in idxs for needed in [3, 5, 9]: assert needed in idxs
def recipe(sess, model, x, y, nb_classes, eps, clip_min, clip_max, eps_iter, nb_iter, report_path, eps_iter_small): attack_configs = [AttackConfig(Noise(model, sess), {'eps': eps})] new_work_goal = {config: 1 for config in attack_configs} goals = [Misclassify(new_work_goal=new_work_goal)] bundle_attacks(sess, model, x, y, attack_configs, goals, report_path, attack_batch_size=batch_size, eval_batch_size=batch_size)