首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Tensorflow- bidirectional_dynamic_rnn:尝试重用RNNCell

Tensorflow- bidirectional_dynamic_rnn:尝试重用RNNCell
EN

Stack Overflow用户
提问于 2017-05-21 22:31:56
回答 1查看 1.3K关注 0票数 0

以下代码(取自- rnn.ipynb)

代码语言:javascript
运行
AI代码解释
复制
import tensorflow as tf
import numpy as np

tf.reset_default_graph()

# Create input data
X = np.random.randn(2, 10, 8)

# The second example is of length 6 
X[1,6:] = 0
X_lengths = [10, 6]

cell = tf.contrib.rnn.LSTMCell(num_units=64, state_is_tuple=True)

outputs, states  = tf.nn.bidirectional_dynamic_rnn(
    cell_fw=cell,
    cell_bw=cell,
    dtype=tf.float64,
    sequence_length=X_lengths,
    inputs=X)

output_fw, output_bw = outputs
states_fw, states_bw = states

提供了以下错误

tensorflow - 1.1 ( 2.7和3.5 )

代码语言:javascript
运行
AI代码解释
复制
ValueError: Attempt to reuse RNNCell <tensorflow.contrib.rnn.python.ops.core_rnn_cell_impl.LSTMCell object at 0x10ce0c2b0> 
with a different variable scope than its first use.  First use of cell was with scope 
'bidirectional_rnn/fw/lstm_cell', this attempt is with scope 'bidirectional_rnn/bw/lstm_cell'.  
Please create a new instance of the cell if you would like it to use a different set of weights.  
If before you were using: MultiRNNCell([LSTMCell(...)] * num_layers), change to:
 MultiRNNCell([LSTMCell(...) for _ in range(num_layers)]).  If before you were using the same cell 
 instance as both the forward and reverse cell of a bidirectional RNN, simply create two instances 
 (one for forward, one for reverse).  In May 2017, we will start transitioning this cell's behavior to use 
 existing stored weights, if any, when it is called with scope=None (which can lead to silent model degradation, 
 so this error will remain until then.)

,但它在中工作

tensorflow - 1.0.1用于python 3.5 (没有在python-2.7上进行测试)

我试过用我在网上找到的多个代码示例,但是

tf.nn.bidirectional_dynamic_rnn给出了与tensorflow - 1.1相同的错误

tensorflow 1.1中有bug吗?还是我只是遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-22 09:16:43

很抱歉你碰到这个。我可以确认错误出现在1.1 (docker run -it gcr.io/tensorflow/tensorflow:1.1.0 python)中,而不是在1.2 RC0 (docker run -it gcr.io/tensorflow/tensorflow:1.2.0-rc0 python)中。

因此,目前看来,1.2-rc0或1.0.1是您的选择。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44106036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档