- Tensorflow 2.10.1 (с CUDA) (ошибка с TensorFlow) < /li>
pytorch 1.13.1+cu116 - art (состязательная достопримечательность)
Код: Выделить всё
WARNING:tensorflow: Calling GradientTape.gradient on a persistent tape inside its context is significantly less efficient than calling it outside the context (it causes the gradient ops to be recorded on the tape, leading to increased CPU and memory usage). Only call GradientTape.gradient inside the context if you actually want to trace the gradient in order to compute higher order derivatives.
И вот мой код:
import torch
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing.image import load_img, img_to_array
from tensorflow.keras.applications.inception_v3 import InceptionV3
from art.attacks.evasion import FastGradientMethod, BasicIterativeMethod, CarliniL2Method, CarliniLInfMethod, \
ProjectedGradientDescent, DeepFool, ThresholdAttack, PixelAttack, SpatialTransformation, SquareAttack, ZooAttack, \
BoundaryAttack, HopSkipJump, SaliencyMapMethod, SimBA, AutoProjectedGradientDescent, HopSkipJump, ElasticNet
from art.estimators.classification import TensorFlowV2Classifier
for i, image_path in enumerate(imagenet_stubs.get_image_paths()):
im = tf.keras.preprocessing.image.load_img(image_path, target_size=(299, 299))
im = tf.keras.preprocessing.image.img_to_array(im)
if 'tractor.jpg' in image_path:
x = np.array(im)
x = (np.expand_dims(x, axis=0) / 255.0).astype(np.float32)
y = np.array([name_to_label("tractor")])
model = InceptionV3(include_top=True, weights='imagenet', classifier_activation='softmax')
loss = tf.keras.losses.CategoricalCrossentropy(from_logits=False)
classifier = TensorFlowV2Classifier(model=model,
nb_classes=nb_classes,
loss_object=loss,
preprocessing=preprocessing,
preprocessing_defences=None,
clip_values=clip_values,
input_shape=input_shape)
# DeepFool is an Untargeted Attack ONLY
attack = DeepFool(classifier=classifier,
epsilon=0.02,
max_iter=100,
)
# Generate adversarial examples (DeepFool is untargeted only)
x_adv = attack.generate(x=x) # UNTARGETED ATTACK
< /code>
Это не ошибка, я знаю, что код компиляется. Но это так долго. С Deepfool я могу подождать 20 минут, но, например, с EAD, после 2 часов, результатов не появляется. Всегда загрузка. < /P>
Сводка:
Я пытался создать состязательные атаки (DeepFool /EAD), но вместо быстрой атаки на одну картину я получил ошибка GradientTape < /code>, которая результатов, которые код собирает в течение нескольких часов, прежде чем получить некоторые результаты, что слишком долго. атака быстро?
Подробнее здесь: https://stackoverflow.com/questions/794 ... -efficient