Fix AttributeError: module ‘tensorflow’ has no attribute ‘AUTO_REUSE’ – TensorFlow Tutorial

By | November 7, 2019

When you are running tensorflow application, you may find this attribute error: AttributeError: module ‘tensorflow’ has no attribute ‘AUTO_REUSE’. In this tutorial, we will tell you how to fix this error.

As to code:

def weight():
  with tf.variable_scope("foo", reuse=tf.AUTO_REUSE):
    v = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='w')
  return v

Run it, you may find result like:

tensorflow has no attribution AUTO_REUSE

Why this error occur?

The reason is our tensorflow version cannot suppor this attribute, tf.AUTO_REUSE is imported in tensorflow 1.4, our tensorflow is 1.2.1

How to check tensorflow? Read this tutorial.

Print TensorFlow Version for Beginners

How to fix this error?

1.Update your tensorflow version

If you want to update tensorflow to a specific version, you can refer to this tutorial.

Anaconda Install or Update TensorFlow to Specific Version

2.Use true replace tf.AUTO_REUSE

As to use, we edit code to:

def weight():
  with tf.variable_scope("weight", reuse = True):
    v = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='w')
  return v

Then this error is fixed.

Leave a Reply

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