Reputation: 93
I am new to Tensorflow and I met an error while trying to run some sample codes.
import tensorflow as tf
g1 = tf.Graph()
with g1.as_default():
v = tf.get_variable("v", initializer=tf.zeros_initializer(shape=[1]))
Running the code above gives the error: TypeError: __init__() got an unexpected keyword argument 'shape'.
The comment below says that tf.zeros_initializer does not accept 'shape' argument according to the documentation. I tried
v = tf.get_variable("v", initializer=tf.zeros_initializer())
and it says ValueError: Shape of a new variable (v) must be fully defined, but instead was .
So, what kind of argument/expression should I use to define the shape without causing a type error?
I cannot find how to solve it online. Please help. Thank you
Upvotes: 1
Views: 15413
Reputation: 93
It appears that the book I'm using is a bit out of date. The following code appears to work so far.
v = tf.get_variable("v", shape=[1], initializer=tf.zeros_initializer)
I will check if it actually works with more code added later.
Upvotes: 4