AI-RESEARCHER-2024 commited on
Commit
f3b88a9
·
verified ·
1 Parent(s): de076a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -20,8 +20,6 @@ mnist_examples = []
20
  for digit in range(10):
21
  idx = np.where(y_test == digit)[0][0]
22
  mnist_examples.append([x_test[idx]])
23
- # Resize the examples to 100 by 100
24
- mnist_examples = [[cv2.resize(example[0], DIMS)] for example in mnist_examples]
25
 
26
  # Function to preprocess the image
27
  def preprocess_image(image):
@@ -100,13 +98,15 @@ epsilon = 0.1 # Tweak epsilon to change the intensity of perturbation
100
  adversarial_examples = []
101
 
102
  for i in range(10):
103
- img = tf.convert_to_tensor(test_images[i:i+1])
104
- label = test_labels[i:i+1]
105
- label = tf.reshape(label, [1, 1])
106
-
107
  perturbations = create_adversarial_pattern(img, label)
108
  adv_x = fgsm_attack(img, epsilon, perturbations)
109
  adversarial_examples.append([cv2.resize(adv_x.numpy().squeeze(), DIMS)])
 
 
 
 
110
 
111
  class GradioInterface:
112
  def __init__(self):
 
20
  for digit in range(10):
21
  idx = np.where(y_test == digit)[0][0]
22
  mnist_examples.append([x_test[idx]])
 
 
23
 
24
  # Function to preprocess the image
25
  def preprocess_image(image):
 
98
  adversarial_examples = []
99
 
100
  for i in range(10):
101
+ img = tf.convert_to_tensor(mnist_examples[i][0])
102
+ label = tf.reshape(tf.convert_to_tensor([i]), [1, 1])
 
 
103
  perturbations = create_adversarial_pattern(img, label)
104
  adv_x = fgsm_attack(img, epsilon, perturbations)
105
  adversarial_examples.append([cv2.resize(adv_x.numpy().squeeze(), DIMS)])
106
+
107
+ # Resize the examples to 100 by 100
108
+ mnist_examples = [[cv2.resize(example[0], DIMS)] for example in mnist_examples]
109
+
110
 
111
  class GradioInterface:
112
  def __init__(self):