0

I am using FGSM attack using cleverhans. My code is as follows:

logits_model = tf.keras.Model(model_1.input, model_1.layers[-1].output)
target_label = tf.one_hot(3, depth=19)
adv_sample = fast_gradient_method.fast_gradient_method(logits_model, x, eps = 0.9, norm = 2, y = target_label, targeted = True)

I am getting this error

loss = loss_fn(labels=y, logits=model_fn(x))

   ValueError: `labels.shape` must equal `logits.shape` except for the last dimension. Received: labels.shape=(19,) and logits.shape=(1, 19)

I reshaped my targeted_label using target_label = np.reshape(target_label, (1, 19)), got this error

ValueError: `labels.shape.rank` must equal `logits.shape.rank - 1`. Received: labels.shape=(1, 19) of rank 2 and logits.shape=(1, 19) of rank 2

I reshaped my targeted_label using

target_label = np.reshape(target_label, (1, 19)), got this error

ValueError: `labels.shape.rank` must equal `logits.shape.rank - 1`. Received: labels.shape=(1, 19) of rank 2 and logits.shape=(1, 19) of rank 2
gogotech
  • 1
  • 1
  • Hi @gogotech, There is difference between dataset labels shape and the model output shape which is causing this error. Please provide the standalone code along with model definition code to replicate the error and fix the issue. – TF_Renu Patel Jun 13 '23 at 18:18

0 Answers0