0
votes

I have been using Keras (version 1.1.1) LSTM with Theano as backend without any problem. Now I would like to switch to Tensorflow (version 0.8.0) and could not get a simple example to work. The problem can be boiled down to following code snippet copied from this Keras-Tensorflow interface tutorial.

from keras.layers import LSTM
import tensorflow as tf

my_graph = tf.Graph()
with my_graph.as_default():
    x = tf.placeholder(tf.float32, shape=(None, 20, 64))
    y = LSTM(32)(x)  

And I got following error when last line is executed:

File "/home/xxx/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/engine/topology.py", line 529, in call return self.call(x, mask)

File "/home/xxx/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/layers/recurrent.py", line 227, in call input_length=input_shape1)

File "/home/xxx/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/backend/tensorflow_backend.py", line 1306, in rnn axes = [1, 0] + list(range(2, len(outputs.get_shape()))) File "/usr/local/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 462, in len raise ValueError("Cannot take the length of Shape with unknown rank.")

ValueError: Cannot take the length of Shape with unknown rank.

Any suggestions?

1

1 Answers

0
votes

You can't mix tensorflow as keras like that. Keras keeps track of the shape of its tensors separately from how tensorflow does.

Try using x = Input(shape=(20,64))