Alessandro Gaballo
Alessandro Gaballo

Reputation: 770

Tensorflow - retrieve variable (shape must be fully defined)

I'm training a convnet with Tensorflow but I'm having troubles with it, so I'm trying to figure out what's happening. I've defined some variable in the following way:

with tf.variable_scope('myscope') as scope:
    var = some_value

But when I try to retrieve it:

var = tf.get_variable('myscope/var')

I get the following:

ValueError: Shape of a new variable (myscope/var) must be fully defined, but instead was <unknown>.

I think there might be something wrong with my tensors, because when I print the output shape I get (?, 10) while I should have the batch size instead of the ?. Here's my code for completeness.

Upvotes: 0

Views: 740

Answers (1)

Jeyanth Chandru
Jeyanth Chandru

Reputation: 11

I had experienced the same problem. The shape is undefined if it has a ?, which means it can take any value. It works well if you manually define your shape (like [10, 10] instead of [?,10]) while declaring the tensor variable.

Upvotes: 0

Related Questions