Fix Tensor’ object has no attribute ‘assign’ Error in TensorFlow – TensorFlow Tutorial

By | July 5, 2021

In this tutorial, we will introduce how to fix Tensor’ object has no attribute ‘assign’ error. You can do by following our steps.

Look at this example code:

train_op = tf.group(train_op, [global_step.assign(new_global_step)])

In this code:

global_step.assign(new_global_step)

It will assign new_global_step to global_step.

However, running this code, you will get this error: Tensor’ object has no attribute ‘assign’

How to fix this attribute error?

We can use tf.assign(). For example:

train_op = tf.group(train_op, [tf.assign(global_step, new_global_step)])

Then, you will find this error is fixed.

Leave a Reply

Your email address will not be published. Required fields are marked *