WeiTang114 / MVCNN-TensorFlow

An Multi-View CNN (MVCNN) implementation with TensorFlow.
MIT License
120 stars 67 forks source link

Is it necessary to call opt.compute_gradients(total_loss) in model.py ? #10

Closed youkaichao closed 7 years ago

youkaichao commented 7 years ago

I once tried to write a customed optimizer and find compute_gradients is extremely ineffective.

    opt = tf.train.AdamOptimizer(lr)
    grads = opt.compute_gradients(total_loss)

# apply gradients
apply_gradient_op = opt.apply_gradients(grads, global_step=global_step)

Since you don't need the grad actually, I highly recommend you change the code to

    train =  tf.train.AdamOptimizer(lr).minimize(total_loss)
WeiTang114 commented 7 years ago

grads are used for visualization with tensorboard in line 271 in model.py:

    for grad,var in grads:
        if grad is not None:
            tf.summary.histogram(var.op.name + '/gradients', grad)

, which is very helpful for debugging, so I will keep it. Thanks!