我一直使用Keas(版本1.1.1)LSTM和Theano作爲後端,沒有任何問題。現在我想切換到Tensorflow(版本0.8.0),並且無法獲得一個簡單的示例。該問題可以歸結爲從this Keras-Tensorflow interface tutorial複製的以下代碼段。使用Keras LSTM和Tensorflow時的輸入形狀問題
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_shape 1)
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.
任何建議:
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)
而且在執行最後一行我得到了下面的錯誤?
試過了。這是行不通的。 – Joe
剛剛在另一臺機器上嘗試了上面的代碼,使用Ubundu 14.04,Tensorflow 0.9.0和Keras的相同版本。它運行沒有問題。我之前的運行是在Tensorflow較低版本的CentOS盒子上運行的。不確定是操作系統問題還是Tensorflow問題。升級Tensorflow後會回報。 – Joe