ConvLSTMCell的Tensorflow错误:输入的尺寸应匹配

时间:2018-02-22 07:12:55

标签: python tensorflow lstm convolution recurrent-neural-network

我尝试根据Tensorflow文档提供<div class="mySlides fade"> <a class="prev" onclick="plusSlides(-1)">&#10094;</a> <a class="next" onclick="plusSlides(1)">&#10095;</a> </div> <div class="wrapper"> <div class="imagelandscape"><img src="http://image.JPG" style= " display: block; max-height:auto; width:100%; "></div> </div>输入参数但仍然出现此错误:

ConvLSTMCell

我的代码是:

InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [10,64,64,1] vs. shape[1] = [1,64,64,16]
     [[Node: rnn/while/rnn/Encoder_1/concat = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](rnn/while/TensorArrayReadV3, rnn/while/Switch_4:1, rnn/while/rnn/Encoder_1/split/split_dim)]]

1 个答案:

答案 0 :(得分:1)

试试这个:

num_channels = 1
img_size = 64
filter_size1 = 5
num_filters1 = 16

x = tf.placeholder(tf.float32, shape=[None,None,img_size,img_size,num_channels],
                   name='x')
InputShape = [img_size, img_size, num_channels]
encoder_1_KernelShape = [filter_size1, filter_size1]
rnn_cell = ConvLSTMCell(2, InputShape, num_filters1, encoder_1_KernelShape,
                        use_bias=True, forget_bias=1.0, name='Encoder_1')

initial_state = rnn_cell.zero_state(10, dtype=tf.float32)
encoder_1_outputs, encoder_1_state = tf.nn.dynamic_rnn(rnn_cell, x,
                                                       initial_state=initial_state,
                                                       dtype=tf.float32)

with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  x_train = np.zeros([10, 1, img_size, img_size, num_channels], dtype=np.float32)
  sess.run(encoder_1_outputs, feed_dict={x: x_train})

请注意,x中的第一个维度是batch_size(示例中等于10),第二个维度是sequence_num(等于1)。