gpt4 book ai didi

python - 连接操作 : Dimensions of inputs should match

转载 作者:太空狗 更新时间:2023-10-30 01:05:58 27 4
gpt4 key购买 nike

我正在使用 tensorflow 和 python 开发深度学习模型:

  • 首先,使用 CNN 层获取特征。
  • 其次, reshape 特征图,我想使用LSTM层。

但是,尺寸不匹配的错误...

ConcatOp:输入的维度应该匹配:shape[0] = [71,48] vs. shape[1] = [1200,24]

W_conv1 = weight_variable([1,conv_size,1,12])
b_conv1 = bias_variable([12])

h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1)+ b_conv1)
h_pool1 = max_pool_1xn(h_conv1)

W_conv2 = weight_variable([1,conv_size,12,24])
b_conv2 = bias_variable([24])

h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
h_pool2 = max_pool_1xn(h_conv2)

W_conv3 = weight_variable([1,conv_size,24,48])
b_conv3 = bias_variable([48])

h_conv3 = tf.nn.relu(conv2d(h_pool2, W_conv3) + b_conv3)
h_pool3 = max_pool_1xn(h_conv3)


print(h_pool3.get_shape())
h3_rnn_input = tf.reshape(h_pool3, [-1,x_size/8,48])

num_layers = 1
lstm_size = 24
num_steps = 4

lstm_cell = tf.nn.rnn_cell.LSTMCell(lstm_size, initializer = tf.contrib.layers.xavier_initializer(uniform = False))
cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell]*num_layers)
init_state = cell.zero_state(batch_size,tf.float32)


cell_outputs = []
state = init_state
with tf.variable_scope("RNN") as scope:
for time_step in range(num_steps):
if time_step > 0: scope.reuse_variables()
cell_output, state = cell(h3_rnn_input[:,time_step,:],state) ***** Error In here...

最佳答案

当您输入到 rnn 单元格时,输入张量和状态张量的批量大小应该相同。

在错误消息中,它说 h3_rnn_input[:,time_step,:] 的形状为 [71,48]state[1200,24]

的形状

您需要做的是使第一个维度 (batch_size) 相同。

如果不需要数字 71,请检查 Convolution 部分。步幅/填充可能很重要。

关于python - 连接操作 : Dimensions of inputs should match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41088064/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com