dataset_logics = node_to_logics[node_name] sparse_thred_filter, sparse_nonzero_filter = logic_plot_hist_save( dataset_logics, filter_count, ) thred_filter_all[node_name] = sparse_thred_filter nonzero_filter_all[node_name] = sparse_nonzero_filter print(f"all") print_logic_per_class(thred_filter_all) def count_logics_exp(): count_logics() if __name__ == "__main__": mode.debug() # mode.local() # ray_init("gpu") ray_init(log_to_driver=False, # num_cpus = 10, ) tf.set_random_seed(3) np.random.seed(3) random.seed(3) count_logics_exp()
def random_targeted(attack_fn, class_start: int, class_end: int): return partial( attack_fn, criterion=TargetClass( target_class=random.randint(class_start, class_end)), ) if __name__ == "__main__": # mode.debug() mode.distributed() # mode.local() # ray_init("gpu") ray_init() threshold = 0.5 # threshold = 1 # threshold = 0.8 attacks = { "FGSM": [FGSM], "BIM": [IterativeGradientSignAttack], "JSMA": [SaliencyMapAttack], "DeepFool": [DeepFoolAttack], # "DeepFool_full": [DeepFoolAttack, dict(subsample=None)], "CWL2": [CarliniL2], } label = "early" # label = "best_in_10" # label = "worst_in_10"
data_format="channels_first", num_gpus = num_gpus, cache=False ) generate_examples( example_fn=example_fn, class_ids=class_ids, image_ids=image_ids, attack_name=attack_name, attack_fn=attack_fn, generate_adversarial_fn=generate_adversarial_fn, transforms = transforms, transform_name = transform_name, **arch_args, ) if __name__ == "__main__": mode.debug() # mode.local() ray_init( log_to_driver=False ) tf.set_random_seed(3) np.random.seed(3) random.seed(3) generate_mnist_examples()
global debug parser = argparse.ArgumentParser(description='Save traces') # Required arguments parser.add_argument('--debug', action='store_true', default=False) args = parser.parse_args() debug = args.debug if debug: mode.debug() train_images_per_class = 10 test_images_per_class = 5 chunksize = 1 else: mode.local() # ray_init("gpu") ray_init( log_to_driver=False, num_cpus=1, # num_gpus=0, ) compute_logics( logic_name="unary", logic_fn=mask_to_logic_fn, trace_key=TraceKey.WEIGHT )