小编Dou*_*ang的帖子

ValueError:尝试使用与第一次使用不同的变量范围重用RNNCell

以下代码片段

import tensorflow as tf
from tensorflow.contrib import rnn

hidden_size = 100
batch_size  = 100
num_steps   = 100
num_layers  = 100
is_training = True
keep_prob   = 0.4

input_data = tf.placeholder(tf.float32, [batch_size, num_steps])
lstm_cell = rnn.BasicLSTMCell(hidden_size, forget_bias=0.0, state_is_tuple=True)

if is_training and keep_prob < 1:
    lstm_cell = rnn.DropoutWrapper(lstm_cell)
cell = rnn.MultiRNNCell([lstm_cell for _ in range(num_layers)], state_is_tuple=True)

_initial_state = cell.zero_state(batch_size, tf.float32)

iw = tf.get_variable("input_w", [1, hidden_size])
ib = tf.get_variable("input_b", [hidden_size])
inputs = [tf.nn.xw_plus_b(i_, iw, ib) for i_ in tf.split(input_data, num_steps, 1)]

if is_training …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

7
推荐指数
1
解决办法
3325
查看次数

标签 统计

python ×1

tensorflow ×1