import numpy as np import matplotlib.pyplot as plt from utils import display_image, mean_cov from attack import PGD_attack_fast #loading the training dataset train_cat = np.matrix(np.loadtxt('./dataset/train_cat.txt', delimiter=',')) train_grass = np.matrix(np.loadtxt('./dataset/train_grass.txt', delimiter=',')) #loading the test dataset Y = plt.imread('./dataset/cat_grass.jpg') / 255 truth = plt.imread('./dataset/truth.png') #computing the parameters for gaussian classifier (Training) mean_cat, cov_cat, pi_cat = mean_cov(train_cat, train_grass) mean_grass, cov_grass, pi_grass = mean_cov(train_grass, train_cat) #overlapping stride = 1 #Inference display_image(img_perturbed=Y, mean_cat=mean_cat, cov_cat=cov_cat, pi_cat=pi_cat, mean_grass=mean_grass, cov_grass=cov_grass, pi_grass=pi_grass, original_img=Y, truth=truth,
Adv_training_data = Adv_training_data_CW elif args.train=='PGD': Adv_training_data = Adv_training_data_PGD else: raise ValueError #loading the training dataset train_cat=np.matrix(np.loadtxt('./dataset/train_cat.txt',delimiter=',')) train_grass=np.matrix(np.loadtxt('./dataset/train_grass.txt',delimiter=',')) #loading the test dataset Y = plt.imread ('./dataset/cat_grass.jpg')/255 truth = plt.imread ('./dataset/truth.png') #computing the parameters for gaussian classifier (Training) mean_cat,cov_cat, pi_cat = mean_cov(train_cat,train_grass) mean_grass,cov_grass, pi_grass = mean_cov(train_grass,train_cat) Lamda = np.linspace (0,5.5,10) Alpha = np.linspace (0.00002, 0.0003,10) augmented_cat =train_cat augmented_grass = train_grass #parameters for blackbox attack mean_cat_defense = mean_cat cov_cat_defense = cov_cat pi_cat_defense = pi_cat mean_grass_defense = mean_grass cov_grass_defense = cov_grass pi_grass_defense = pi_grass
if args.train == 'CW': Adv_training_data = Adv_training_data_CW elif args.train == 'PGD': Adv_training_data = Adv_training_data_PGD else: raise ValueError #loading the training dataset train_cat = np.matrix(np.loadtxt('./dataset/train_cat.txt', delimiter=',')) train_grass = np.matrix(np.loadtxt('./dataset/train_grass.txt', delimiter=',')) #loading the test dataset Y = plt.imread('./dataset/cat_grass.jpg') / 255 truth = plt.imread('./dataset/truth.png') #computing the parameters for gaussian classifier (Training) mean_cat, cov_cat, pi_cat = mean_cov(train_cat, train_grass) mean_grass, cov_grass, pi_grass = mean_cov(train_grass, train_cat) Lamda = np.linspace(0.5, 5.5, 10) Alpha = np.linspace(0.00002, 0.0003, 10) augmented_cat = train_cat augmented_grass = train_grass #parameters for blackbox attack mean_cat_defense = mean_cat cov_cat_defense = cov_cat pi_cat_defense = pi_cat mean_grass_defense = mean_grass cov_grass_defense = cov_grass pi_grass_defense = pi_grass
global args args = parser.parse_args() print(args) #loading the training dataset train_cat=np.matrix(np.loadtxt('./dataset/train_cat.txt',delimiter=',')) train_grass=np.matrix(np.loadtxt('./dataset/train_grass.txt',delimiter=',')) #loading the test dataset Y = plt.imread ('./dataset/cat_grass.jpg')/255 truth = plt.imread ('./dataset/truth.png') #computing the parameters for gaussian classifier (Training) q1 = Quantize(n_bits=args.n_bits, quantize=args.quantize) mean_cat_defense,cov_cat_defense, pi_cat_defense = mean_cov(q1.forward(train_cat),q1.forward(train_grass)) mean_grass_defense,cov_grass_defense, pi_grass_defense = mean_cov(q1.forward(train_grass),q1.forward(train_cat)) if args.attack_type.lower() == 'whitebox': mean_cat_attack = mean_cat_defense cov_cat_attack = cov_cat_defense pi_cat_attack = pi_cat_defense mean_grass_attack = mean_grass_defense cov_grass_attack = cov_grass_defense pi_grass_attack = pi_grass_defense elif args.attack_type.lower() == 'blackbox': mean_cat_attack,cov_cat_attack, pi_cat_attack = mean_cov(train_cat,train_grass) mean_grass_attack,cov_grass_attack, pi_grass_attack = mean_cov(train_grass,train_cat) print("Inference without Quantization") #Inference display_image(img_perturbed = Y,