Reputation: 85
Basically this problem TensorFlow: Is there a way to convert a list with None type to a Tensor?
The answer tells why it's not possible but no workaround
I'm trying to make an autoencoder which has some conolutional layers that are flattened into some fully connected layers and reexpanded to the original dimension. However, when I'm trying to expand the output of the flattened layer into a tensor, I get the problem Tried to convert 'shape' to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: (?, 14, 32, 128)
This is essentially what the network looks like
X=tf.placeholder(tf.float32,shape=[None, height, width, channel])
conv = Conv2D(32, (3, 3), activation='relu', padding='same')(X)
h1=actf(tf.matmul(conv,w)+b)
output = Conv2D(32, (3, 3), activation='relu', padding='same')(tf.reshape(h1, conv.shape))
How can I reshape the output of the the middle layer without specifying a batch size?
I've also tried
output = Conv2D(32, (3, 3), activation='relu', padding='same')(tf.reshape(h1, [None, 14, 32, 128]))
which gives the following error Failed to convert object of type <class 'list'> to Tensor. Contents: [None, 14, 32, 128]
Upvotes: 3
Views: 7612
Reputation: 181
You should use -1
instead of None
to specify the dimension which should be calculated automatically. Try tf.reshape(h1, [-1] + conv.shape.as_list()[1:])
.
Upvotes: 9