"x = [x for x in list(data.columns) if x != y] # Create a list of feature names by including all columns from the dataset except the target variable.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"<ipython-input-8-4e138f0dc27c>:16: UserWarning: you are shuffling a 'Series' object which is not a subclass of 'Sequence'; `shuffle` is not guaranteed to behave correctly. E.g., non-numpy array/tensor objects with view semantics may contain duplicates after shuffling.\n",
"def pgd_attack(model, x, y, epsilon=0.5, alpha=0.04, num_iter=40, targeted=False, num_random_init=0, batch_size=128):\n",
" perturbed_x = tf.identity(x) # create a copy of the input\n",
"\n",
" for _ in range(num_iter):\n",
" with tf.GradientTape() as tape:\n",
" tape.watch(perturbed_x) # keep track of purturbed_x\n",
" loss = model(perturbed_x) #calculate loss\n",
"\n",
" gradients = tape.gradient(loss, perturbed_x) # calculate gradient of loss relevent to pur_x\n",
"\n",
" if targeted:\n",
" gradients = -gradients\n",
"\n",
" perturbed_x = tf.clip_by_value(perturbed_x + alpha * tf.sign(gradients), x - epsilon, x + epsilon) #update purtubate x and clip to stay in a specific range\n",
" perturbed_x = tf.clip_by_value(perturbed_x, 0, 1) # ensure pixel values are in [0, 1] range\n",