sunblaze-ucb / blackbox-attacks

Code used in 'Exploring the Space of Black-box Attacks on Deep Neural Networks' (https://arxiv.org/abs/1712.09491)
MIT License
61 stars 13 forks source link

how to solve the error “ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients”. thx! #2

Closed mesunhlf closed 4 years ago

mesunhlf commented 5 years ago

when i run the command "python train.py models/modelA --type=0 --num_epochs=6" i meet the error:

Traceback (most recent call last): File "/usr/lib/pycharm-community/helpers/pydev/pydevd.py", line 1596, in globals = debugger.run(setup['file'], None, None, is_module) File "/usr/lib/pycharm-community/helpers/pydev/pydevd.py", line 974, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/home/memoonhlf/github/blackbox-attacks/train.py", line 61, in main("models/modelB", 1) File "/home/memoonhlf/github/blackbox-attacks/train.py", line 41, in main tf_train(x, y, model, X_train, Y_train, data_gen, None, None) File "/home/memoonhlf/github/blackbox-attacks/tf_utils.py", line 86, in tftrain optimizer = tf.train.AdamOptimizer().minimize(out) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 350, in minimize ([str(v) for , v in grads_and_vars], loss)) ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables ["<tf.Variable 'convolution2d_1_W:0' shape=(8, 8, 1, 64) dtype=float32_ref>", "<tf.Variable 'convolution2d_1_b:0' shape=(64,) dtype=float32_ref>", "<tf.Variable 'convolution2d_2_W:0' shape=(6, 6, 64, 128) dtype=float32_ref>", "<tf.Variable 'convolution2d_2_b:0' shape=(128,) dtype=float32_ref>", "<tf.Variable 'convolution2d_3_W:0' shape=(5, 5, 128, 128) dtype=float32_ref>", "<tf.Variable 'convolution2d_3_b:0' shape=(128,) dtype=float32_ref>", "<tf.Variable 'dense_1_W:0' shape=(128, 10) dtype=float32_ref>", "<tf.Variable 'dense_1_b:0' shape=(10,) dtype=float32_ref>"] and loss Tensor("Reshape_13:0", shape=(?,), dtype=float32, device=/device:GPU:0).

zouying-sjtu commented 4 years ago

Found this in “tensorflow/contrib/keras/python/keras”

  def categorical_crossentropy(output, target, from_logits=False):
        Categorical crossentropy between an output tensor and a target tensor.
        Arguments:
            output: A tensor resulting from a softmax
                (unless `from_logits` is True, in which
                case `output` is expected to be the logits).
            target: A tensor of the same shape as `output`.
            from_logits: Boolean, whether `output` is the
                result of a softmax, or is a tensor of logits.
        Returns:
            Output tensor.