0

I am trying to make an adversarial image for the inceptionV3 model with tensorflow. For that I use a specific loss on the pixel of my input image. This works well

model_input_layer = model.layers[0].input
model_output_layer = model.layers[-1].output

cost_function = model_output_layer[0, object_type_to_fake]
gradient_function = K.gradients(cost_function, model_input_layer)[0]
grab_cost_and_gradients_from_model = K.function([model_input_layer, K.learning_phase()], [cost_function, gradient_function])

Now I would like to make only certain pixels trainable to create a patch on a certain square and not on the all input image. I have tried to use variable = tf.slice(model_input_layer, [0, 100, 100, 0], [-1, 100, 100, -1]) but it does not work. Does anyone has already done this ?

Samos
  • 111
  • 6
  • Try `var = tf.Variable(tf.slice(model_input_layer, [0, 100, 100, 0], [-1, 100, 100, -1]))`? – zihaozhihao Oct 03 '19 at 18:50
  • Thank you for your answer but unfortunately it does not work. I tried `var = tf.Variable(tf.slice(model_input_layer, [0, 100, 100, 0], [-1, 100, 100, -1]), validate_shape=False)` but then the `K.gradient` method returns `None`. – Samos Oct 07 '19 at 11:46

0 Answers0