PCGrad
PCGrad copied to clipboard
Anyone with a problem like this? (AttributeError: 'NoneType' object has no attribute 'op')
Anyone with a problem like this? (AttributeError: 'NoneType' object has no attribute 'op')
losses Out[159]: [<tf.Tensor 'add_17:0' shape=() dtype=float32>, <tf.Tensor 'add_17:0' shape=() dtype=float32>]
train_step = optimizer.minimize(losses) Traceback (most recent call last):
File "
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\training\optimizer.py", line 399, in minimize grad_loss=grad_loss)
File "F:\Pan_cancer\OmiVAE-master\PCGrad_tf.py", line 40, in compute_gradients if grad is not None], axis=0), loss)
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\functional_ops.py", line 459, in map_fn maximum_iterations=n)
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3209, in while_loop result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2941, in BuildLoop pred, body, original_loop_vars, loop_vars, shape_invariants)
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2878, in _BuildLoop body_result = body(*packed_vars_for_body)
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3179, in
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\functional_ops.py", line 448, in compute packed_fn_values = fn(packed_values)
File "F:\Pan_cancer\OmiVAE-master\PCGrad_tf.py", line 39, in
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\gradients_impl.py", line 532, in gradients gate_gradients, aggregation_method, stop_gradients)
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\gradients_impl.py", line 588, in _GradientsHelper from_ops = [t.op for t in xs]
File "C:\Users\USER\Anaconda3\envs\tensorflow3\lib\site-packages\tensorflow\python\ops\gradients_impl.py", line 588, in
AttributeError: 'NoneType' object has no attribute 'op'
Use the code below right before where the tf.gradients is called, hopefully this will fix it:
if var_list is None:
var_list = (
variables.trainable_variables() +
ops.get_collection(ops.GraphKeys.TRAINABLE_RESOURCE_VARIABLES))
else:
var_list = nest.flatten(var_list)
Use the code below right before where the
tf.gradientsis called, hopefully this will fix it:if var_list is None: var_list = ( variables.trainable_variables() + ops.get_collection(ops.GraphKeys.TRAINABLE_RESOURCE_VARIABLES)) else: var_list = nest.flatten(var_list)
It cannot and some new variables are involved causing errors.
+1,how to solve this problem?
I got the same issue
+1, I got the same issue
who can give an answer?really thanks
The default value of var_list is None. To compute the gradients between each loss and var_list, var_list should be specified first.
if var_list is None:
var_list = (
variables.trainable_variables() +
ops.get_collection(ops.GraphKeys.TRAINABLE_RESOURCE_VARIABLES))
else:
var_list = nest.flatten(var_list)
# pylint: disable=protected-access
var_list += ops.get_collection(ops.GraphKeys._STREAMING_MODEL_PORTS)
# pylint: enable=protected-access
if not var_list:
raise ValueError("No variables to optimize.")