save report after each goal is completed
@@ -376,6 +376,10 @@ def bundle_attacks_with_goal(sess, model, x, y, adv_x, attack_configs, run_count
while not goal.is_satisfied(criteria, run_counts):
run_batch_with_goal(sess, model, x, y, adv_x, criteria, attack_configs, run_counts,
goal, report, report_path)
+ # Save after finishing each goal.
+ # The incremental saves run on a timer. This save is needed so that the last
+ # few attacks after the timer don't get discarded
+ save(criteria, report, report_path, adv_x_val)
def run_batch_with_goal(sess, model, x, y, adv_x_val, criteria, attack_configs,
run_counts, goal, report, report_path):
@@ -433,6 +437,16 @@ def run_batch_with_goal(sess, model, x, y, adv_x_val, criteria, attack_configs,
if should_save:
report['time'] = new_time
goal.print_progress(criteria, run_counts)
+ save(criteria, report, report_path, adv_x_val)
+
+def save(criteria, report, report_path, adv_x_val):
+ """
+ Saves the report and adversarial examples.
+ :param criteria: dict, of the form returned by AttackGoal.get_criteria
+ :param report: dict containing a confidence report
+ :param report_path: string, filepath
+ :param adv_x_val: numpy array containing dataset of adversarial examples
+ """
print_stats(criteria['correctness'], criteria['confidence'], 'bundled')
serial.save(report_path, report)
