Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'tensorflow' has no attribute 'get_variable'

I am trying to run this line of code :

var_init_1 = tf.get_variable("var_init_1", [1, 2], dtype=tf.int32,  initializer=tf.zeros_initializer)
print(var_init_1.shape)

It should give an output the shape of tensor of zeros.

But why I'm getting an error like this:

AttributeError                            Traceback (most recent call last)
<ipython-input-37-3cc73aa1818e> in <module>
----> 1 var_init_1 = tf.get_variable("var_init_1", [1, 2], dtype=tf.int32,  initializer=tf.zeros_initializer)
      2 print(var_init_1.shape)

AttributeError: module 'tensorflow' has no attribute 'get_variable'
like image 919
aksr Avatar asked Dec 07 '19 13:12

aksr


3 Answers

Replace tf.get_variable with tf.Variable.

like image 64
HajarM Avatar answered Nov 19 '22 19:11

HajarM


Mentioning the Solution for the benefit of the community.

Downgrading to Tensorflow 1.X Version (1.14 or 1.15) has resolved the issue, as Tensorflow version 2.0 doesn't support get_variable().

like image 32
Tensorflow Support Avatar answered Nov 19 '22 20:11

Tensorflow Support


tf.Variable does not work for initilizer. Use this instead of tf.compat.v1.get_variable instead of tf.Variable. This works tensorflow 2.0 and above.

like image 3
Nafees Ahmed Avatar answered Nov 19 '22 21:11

Nafees Ahmed