def run(self, start, end): rs = [] for filenames, xs, ys, ys_target in load_batches_imagenet_test(batch_size=1, x_min=MODEL.x_min, x_max=MODEL.x_max, x_shape=MODEL.x_shape, x_dtype=MODEL.x_dtype, y_dtype=MODEL.y_dtype, start=start, end=end, label_offset=LABEL_OFFSET, return_target_class=True): print(filenames) rs.append(self._run(xs, ys, ys_target)) return rs
def run(self, start, end): xs_adv = np.zeros((end - start,) + MODEL.x_shape) idx = 0 for filenames, xs, ys, ys_target in load_batches_imagenet_test(batch_size=1, x_min=MODEL.x_min, x_max=MODEL.x_max, x_shape=MODEL.x_shape, x_dtype=MODEL.x_dtype, y_dtype=MODEL.y_dtype, start=start, end=end, label_offset=LABEL_OFFSET, return_target_class=True): print(filenames) xs_adv[idx] = self._run(self, xs, ys, ys_target) idx += 1 return xs_adv
'alpha': ALPHA_L_2, 'session': SESSION, }) builder.iteration(ITERATION) builder.batch_size(BATCH_SIZE) builder.no_batch_pred(True) benchmark = builder.build(SESSION, MODEL, args.method, args.goal, args.distance_metric) os.makedirs(args.output_dir, exist_ok=True) for count, (filenames, xs, ys, ys_target) in enumerate( load_batches_imagenet_test(batch_size=BATCH_SIZE, x_min=MODEL.x_min, x_max=MODEL.x_max, x_shape=MODEL.x_shape, x_dtype=MODEL.x_dtype, y_dtype=MODEL.y_dtype, start=0, end=1000, label_offset=LABEL_OFFSET, return_target_class=True)): print(count * BATCH_SIZE, (count + 1) * BATCH_SIZE) output_filename = os.path.join(args.output_dir, '%d_rs.npy' % count) rs = benchmark.run(xs, ys, ys_target) np.save(output_filename, rs) SESSION.close()