type) # process_data_for_right = process_three_layer(m, n, k, datas1, datas2, datas3, type,save_path) # result_for_right = np.hstack((result_for_right, process_data_for_right)) # process结束后 # 保存激活数据信息 # print(result_for_right.shape) # np.save(os.path.join(save_path, str(layer_nums) + '_hidden_layers_coverage.npy'), result_for_right) del right_datas gc.collect() # 错误数据的激活信息保存 for attack_type in [ 'fgsm', 'gaussian_noise', 'saliency_map', 'uniform_noise' ]: wrong_datas = data_provider.get_wrong_active_data_with_attack_type( '../data/mnist', dataset, layer_nums, attack_type) # process_wrong_datas and save coverage data # 默认我们用相邻两层 result_for_wrong = np.empty((len(wrong_datas), 0)) for layer_num in range(layer_nums - 2): layer1 = layer_num layer2 = layer_num + 1 layer3 = layer_num + 2 datas1 = np.array( [list(item) for item in wrong_datas[:, layer1]]) datas2 = np.array( [list(item) for item in wrong_datas[:, layer2]]) datas3 = np.array( [list(item) for item in wrong_datas[:, layer3]]) print(datas1.shape) print(datas2.shape)
threshold = 0 m = 1 n = 1 for type in [0, 1, 2]: for layer_num in [3, 5, 10]: for attack_type in [ 'fgsm', 'gaussian_noise', 'saliency_map', 'uniform_noise' ]: now = time.time() print( str(layer_num) + ' hidden layers model process type' + str(type) + '...wrong...' + attack_type) plt.figure datas = data_provider.get_wrong_active_data_with_attack_type( '../data/mnist/', 'mnist', layer_num, type=attack_type) datas = data_provider.shuffle_mnist_data(datas) # datas = np.array(random.sample(list(datas), sample_nums)) total_data = [] process_data = [] layers = [] for j in range(layer_num - 1): datas1 = np.array([list(item) for item in datas[:, j]]) datas2 = np.array([list(item) for item in datas[:, j + 1]]) datas1[datas1 > threshold] = 1 datas2[datas2 > threshold] = 1 datas1[datas1 <= threshold] = 0 datas2[datas2 <= threshold] = 0 total_comb_num, coverage_data = two_layer(m, n, datas1,