问题描述
我正在尝试使用tf.contrib.rnn.ConvLSTMCell API和tf.nn.dynamic_rnn API在Tensorflow(1.4)中构建seq2seq模型,但是输入尺寸出现错误. /p>
我的代码是:
# features is an image sequence with shape [600, 400, 10],
# so features is a tensor with shape [batch_size, 600, 400, 10]
features = tf.transpose(features, [0,3,1,2])
features = tf.reshape(features, [params['batch_size'],10,600,400])
encoder_cell = tf.contrib.rnn.ConvLSTMCell(conv_ndims=2,
input_shape=[600, 400,1],
output_channels=5,
kernel_shape=[7,7],
skip_connection=False)
_, encoder_state = tf.nn.dynamic_rnn(cell=encoder_cell,
inputs=features,
sequence_length=[10]*params['batch_size'],
dtype=tf.float32)
我收到以下错误
ValueError: Conv Linear expects all args to be of same Dimension: [[2, 600, 400], [2, 600, 400, 5]]
看一下tf的实现,似乎dynamic_rnn的输入仅是3维的,而隐藏状态是4维的.我试图将输入作为嵌套元组传递,但没有用.
问题类似于 TensorFlow dynamic_rnn回归器:ValueError尺寸不匹配,但是略有不同,因为他们使用的是普通的LSTMCell(对我有用).
谁能给我一个最小的示例,如何将这两个API一起使用?谢谢!
同时,我弄清楚了如何一起使用这两个API.诀窍是将5D张量作为输入传递到tf.nn.dynamic_rnn(),其中最后一个维度是空间网格上的矢量"的大小(来自2D到3D的输入转换,受到实施依据的论文的启发: https://arxiv.org/pdf/1506.04214.pdf ).在我的情况下,矢量大小为1,不过我还是必须扩大尺寸.
在纠正此错误的同时,出现了另一个问题:在上文第3.1节中提到的论文中,他们陈述了convLSTM的方程式.他们将Hadamard乘积用于连接到单元格输出C的权重.在Tensorflow中打印我的ConvLSTMCell的权重,似乎他们根本没有使用权重Wci,Wcf和Wco.那么,有人可以告诉我TF ConvLSTMCell的确切实现吗?
顺便说一句.张量流ConvSTMCell的输出是C还是H(在本文中表示)?
I'm trying to build a seq2seq model in tensorflow (1.4) using the tf.contrib.rnn.ConvLSTMCell API together with the tf.nn.dynamic_rnn API, but I got an error with the dimension of the inputs.
My code is:
# features is an image sequence with shape [600, 400, 10],
# so features is a tensor with shape [batch_size, 600, 400, 10]
features = tf.transpose(features, [0,3,1,2])
features = tf.reshape(features, [params['batch_size'],10,600,400])
encoder_cell = tf.contrib.rnn.ConvLSTMCell(conv_ndims=2,
input_shape=[600, 400,1],
output_channels=5,
kernel_shape=[7,7],
skip_connection=False)
_, encoder_state = tf.nn.dynamic_rnn(cell=encoder_cell,
inputs=features,
sequence_length=[10]*params['batch_size'],
dtype=tf.float32)
I get the following error
ValueError: Conv Linear expects all args to be of same Dimension: [[2, 600, 400], [2, 600, 400, 5]]
Looking at the tf implementation, it seems that the inputs to dynamic_rnn is only 3-dimensional in contrary to the hidden state, which is 4-dimensional. I tried to pass the input as a nested tuple, but it didn't work.
The problem is similar to TensorFlow dynamic_rnn regressor: ValueError dimension mismatch, it's slightly different though, as they're using a plain LSTMCell (which worked for me).
Can anyone give me a minimal example how to use these 2 APIs together?Thanks!
In the meantime I figured out how to use the 2 APIs together. The trick is to pass a 5D-Tensor as input to tf.nn.dynamic_rnn(), where the last dimension is the size of the "vector on the spatial grid" (which comes from the transformation of the input from 2D to 3D, inspired by the paper on which the implementation is based: https://arxiv.org/pdf/1506.04214.pdf). In my case the vector size is 1, I have to expand the dimension anyway though.
While fixing this error another issue emerged: In the paper mentioned above in section 3.1 they state the equations for the convLSTM. They use the Hadamard-product for weights connected to the cell outputs C. Printing the weights of my ConvLSTMCell in Tensorflow, it seems like they don't use the weights Wci, Wcf and Wco at all. So, can anybody tell me the exact implementation of the TF ConvLSTMCell?
Btw. the output of the tensorflow ConvSTMCell is C or H (in the notation of the paper)?
这篇关于ValueError:ConvLSTMCell和dynamic_rnn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!