classes_for_target = conf.class_names for i in range(len(pc_classes)): pc_class_name = pc_classes[i] if pc_class_name not in classes_for_attack: continue save_dir = create_dir(osp.join(output_path, pc_class_name)) print('Classify shape class %s (%d out of %d classes) ' % (pc_class_name, i + 1, len(pc_classes))) start_time = time.time() # prepare target point clouds source_recon_ref, target_recon_ref = prepare_data_for_attack( pc_classes, [pc_class_name], classes_for_target, reconstructions, slice_idx, attack_pc_idx, conf.num_pc_for_target, nn_idx, correct_pred) # load data load_dir = osp.join(classifier_data_path, pc_class_name) if flags.data_type == 'target': # add axis to keep the interface of dist_weight as the first dim pc_recon = np.expand_dims(target_recon_ref, axis=0) elif flags.data_type in ['adversarial', 'before_defense']: adversarial_pc_recon = np.load( osp.join(load_dir, 'adversarial_pc_recon.npy')) # take adversarial point clouds of selected dist weight per attack source_target_norm_min_idx = np.load( osp.join(load_dir, 'analysis_results', 'source_target_norm_min_idx.npy'))
# transfer attack to the AE model for i in range(len(pc_classes)): pc_class_name = pc_classes[i] if pc_class_name not in classes_for_attack: continue save_dir = create_dir(osp.join(output_path, pc_class_name)) print('transfer shape class %s (%d out of %d classes) ' % (pc_class_name, i + 1, len(pc_classes))) start_time = time.time() # prepare target point clouds source_pc, target_pc = prepare_data_for_attack( pc_classes, [pc_class_name], classes_for_target, point_clouds, slice_idx, attack_pc_idx, conf.num_pc_for_target, nn_idx, correct_pred) _, target_ae_loss_ref = prepare_data_for_attack( pc_classes, [pc_class_name], classes_for_target, ae_loss, slice_idx, attack_pc_idx, conf.num_pc_for_target, nn_idx, correct_pred) _, target_recon_ref = prepare_data_for_attack( pc_classes, [pc_class_name], classes_for_target, reconstructions, slice_idx, attack_pc_idx, conf.num_pc_for_target, nn_idx, correct_pred) target_ae_loss_ref = target_ae_loss_ref.reshape(-1) # load data load_dir = osp.join(attack_path, pc_class_name) adversarial_pc_input = np.load( osp.join(load_dir, 'adversarial_pc_input.npy')) adversarial_pc_recon = np.load(
# Attack the AE model for i in range(len(pc_classes)): pc_class_name = pc_classes[i] if pc_class_name not in classes_for_attack: continue # Build Adversary and AE model reset_tf_graph() ae = AdvAE(conf.experiment_name, conf) save_dir = create_dir(osp.join(conf.train_dir, pc_class_name)) # prepare data for attack source_pc, target_pc = prepare_data_for_attack(pc_classes, [pc_class_name], classes_for_target, point_clouds, slice_idx, attack_pc_idx, flags.num_pc_for_target, nn_idx, correct_pred) _, target_latent = prepare_data_for_attack(pc_classes, [pc_class_name], classes_for_target, latent_vectors, slice_idx, attack_pc_idx, flags.num_pc_for_target, nn_idx, correct_pred) _, target_ae_loss_ref = prepare_data_for_attack( pc_classes, [pc_class_name], classes_for_target, ae_loss, slice_idx, attack_pc_idx, flags.num_pc_for_target, nn_idx, correct_pred) target_ae_loss_ref = target_ae_loss_ref.reshape(-1) buf_size = 1 # Make 'training_stats' file to flush each output line regarding training.
sess = tf.Session('') for i in range(len(pc_classes)): pc_class_name = pc_classes[i] if pc_class_name not in classes_for_attack: continue print('compute knn dists for shape class %s (%d out of %d classes) ' % (pc_class_name, i + 1, len(pc_classes))) start_time = time.time() # prepare data for attack source_pc, _ = prepare_data_for_attack(pc_classes, [pc_class_name], classes_for_target, point_clouds, slice_idx, attack_pc_idx, conf.num_pc_for_target, nn_idx, correct_pred) # load data load_dir = osp.join(attack_dir, pc_class_name) adversarial_pc_input = np.load( osp.join(load_dir, 'adversarial_pc_input.npy')) # take adversarial point clouds of selected dist weight per attack source_target_norm_min_idx = np.load( osp.join(load_dir, 'analysis_results', 'source_target_norm_min_idx.npy')) adversarial_pc_input = get_quantity_at_index([adversarial_pc_input], source_target_norm_min_idx)