【问题标题】:theano shared variable has wrong shape in scan functiontheano 共享变量在扫描函数中的形状错误
【发布时间】:2016-08-21 02:33:38
【问题描述】:

我有一个形状为 (1, 500) 的 theano 共享变量,但是当传递给扫描函数时,形状变成了 (1, 1, 500)。示例代码 sn-p 如下。

y_t1 = theano.shared(name='y_t1', value=np.zeros((1, 500), dtype=theano.config.floatX))

def forward(X, y_t1):
    return y_t1

(hyp), _ = theano.scan(fn=forward, sequences=X, outputs_info=[y_t1])

y_t1 以 (1, 500) 的大小创建,并在函数“forward”之外报告其形状为 (1, 500),但在“forward”内部它具有形状 (1, 1, 500)。为什么会这样?

谢谢。

【问题讨论】:

    标签: python python-2.7 theano theano.scan


    【解决方案1】:

    把它作为

    (hyp), _ = theano.scan(fn=forward, sequences=X, outputs_info=y_t1)
    

    那么它应该可以正常工作。 (我已经删除了 output_info 中 y_t1 周围的括号)

    解释:Theano 将你在 = 之后传入的任何内容转换为张量。因此,如果您传入一个列表,它首先会转换为该形状的张量。因此,当您传入 [y_t1] 时,您基本上是在为您的输入添加一个额外的维度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 2016-07-18
      • 2013-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      相关资源
      最近更新 更多