我正在开发一个带有张量流和python的深度学习模型:
但是,尺寸不匹配的错误......
ConcatOp:输入的尺寸应匹配: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...
private void dgvFattDdt_SelectionChanged(object sender, EventArgs e)
{
if(dgvFattDdt.RowCount == 1)
{
dgvFattDdt.ClearSelection();
return;
}
foreach (DataGridViewRow row in dgvFattDdt.SelectedRows)
{
//here I save the data of the row into textboxes
txtColli.Text = row.Cells[1].Value.ToString();
txtDescMerce.Text = row.Cells[2].Value.ToString();
txtUM.Text = row.Cells[3].Value.ToString();
txtIso.Text = row.Cells[4].Value.ToString();
txtLordo.Text = row.Cells[5].Value.ToString();
txtTara.Text = row.Cells[6].Value.ToString();
txtPrezzo.Text = row.Cells[8].Value.ToString();
cbIVA.Text = row.Cells[10].Value.ToString();
selectedRow = row.Index;
ex_Colli = Convert.ToInt32(row.Cells[1].Value.ToString());
decimal.TryParse(row.Cells[9].Value.ToString(), out ex_Importo);
int.TryParse(row.Cells[10].Value.ToString(), out ex_Iva);
//------------------------------
dgvFattDdt.Rows.RemoveAt(row.Index);
}
}
答案 0 :(得分:4)
输入到rnn单元格时,输入张量和状态张量的批量大小应相同。
在错误消息中,它显示h3_rnn_input[:,time_step,:]
的形状为[71,48]
而state
的形状为[1200,24]
您需要做的是使第一个维度(batch_size)相同。
如果不打算使用数字71,请检查卷积部分。跨步/填充可能很重要。
答案 1 :(得分:0)
您必须考虑正确的号码 h3_rnn_input [:,time_step ,:] 和 州 以便不按batch_size划分剩余数。(如果有剩余数,则会引发错误)
那么,关于您的代码:
h3_rnn_input[:,time_step,:] has shape of [71,48]
state has shape of [1200,24]
如果我们认为例如batch_size等于90,则:
71/90=0.78 ===> error
1200/90=13.33 ===> error
但是如果我们考虑以下形状和批量大小,那么我们就没有任何问题:
h3_rnn_input[:,time_step,:] has shape of [**60**,48]
state has shape of [**1200**,24]
batch_size=30
然后
60/30=2 ======> ok without any error
1200/30=40 ======> ok without any error