Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyone with a problem like this? (AttributeError: 'NoneType' object has no attribute 'op') #6

Open
SehwanMoon opened this issue Sep 16, 2020 · 7 comments

Comments

@SehwanMoon
Copy link

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 "", line 1, in
train_step = optimizer.minimize(losses)

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
body = lambda i, lv: (i + 1, orig_body(*lv))

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
for grad in tf.gradients(x, var_list)

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
from_ops = [t.op for t in xs]

AttributeError: 'NoneType' object has no attribute 'op'

@mnabian
Copy link

mnabian commented Sep 23, 2020

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)

@Coder-Yu
Copy link

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)

It cannot and some new variables are involved causing errors.

@scriptboy1990
Copy link

+1,how to solve this problem?

@silver1886
Copy link

I got the same issue

@Xls1994
Copy link

Xls1994 commented Feb 18, 2022

+1, I got the same issue

@momodagithub
Copy link

who can give an answer?really thanks

@EveDong
Copy link

EveDong commented Jul 21, 2022

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.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants