NELSONZHAO / zhihu

This repo contains the source code in my personal column (https://zhuanlan.zhihu.com/zhaoyeyu), implemented using Python 3.6. Including Natural Language Processing and Computer Vision projects, such as text generation, machine translation, deep convolution GAN and other actual combat code.
https://zhuanlan.zhihu.com/zhaoyeyu
3.5k stars 2.14k forks source link

运行报ValueError: Trying to share variable rnn/multi_rnn_cell/cell_0/basic_lstm_cell/kernel, but specified shape (1024, 2048) and found shape (595, 2048). #7

Open callwhl opened 6 years ago

callwhl commented 6 years ago

运行报ValueError: Trying to share variable rnn/multi_rnn_cell/cell_0/basic_lstm_cell/kernel, but specified shape (1024, 2048) and found shape (595, 2048). 再执行dynamic_rnn时报的 我的tensorflow版本1.3.0,python版本3.5.2

找到原因了,构建lstm的代码lstm = tf.contrib.rnn.BasicLSTMCell(lstm_size),当你构建多层lstm时由于都是用的这一个lstm所以就报以上错误,正确的做法是: for i in range(num_layers): lstm = tf.contrib.rnn.BasicLSTMCell(lstm_size) drop = tf.contrib.rnn.DropoutWrapper(lstm, output_keep_prob=keep_prob) stack_drop.append(drop) cell = tf.contrib.rnn.MultiRNNCell(stack_drop, state_is_tuple = True)

gdpinchina commented 6 years ago

it works!

onlyff commented 6 years ago

NameError: name 'stack_drop' is not defined

Lolothomasi commented 6 years ago

It works! Thanks a lot for sharing. 'stack_drop' need to be defined as list.

parahaoer commented 6 years ago

修改后报错: ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("rnn/transpose_1:0", shape=(100, 100, 512), dtype=float32)' 该怎么改?求大佬相助!

stepsma commented 6 years ago

@parahaoer build output 函数,将concat的参数调过来就可以了 seq_output = tf.concat(lstm_output, 1)

RunningPhoton commented 6 years ago

thanks, it solved my problem

HavendGithub commented 6 years ago

第一个问题: ValueError: Trying to share variable rnn/multi_rnn_cell/cell_0/basic_lstm_cell/kernel, but specified shape (1024, 2048) and found shape (595, 2048). 解决方案: build_lstm函数 stack_drop=[] for i in range(num_layers): lstm = tf.nn.rnn_cell.BasicLSTMCell(lstm_size) drop = tf.nn.rnn_cell.DropoutWrapper(lstm, output_keep_prob=keep_prob) stack_drop.append(drop) cell = tf.nn.rnn_cell.MultiRNNCell(stack_drop, state_is_tuple = True)

第二个问题: ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("rnn/transpose_1:0", shape=(100, 100, 512), dtype=float32)' 解决方案: build_output函数 seq_output = tf.concat(lstm_output, 1)