python - 将输入参数传递给 Theano 函数的正确方法是什么?

标签 python theano deep-learning autoencoder

我正在使用安装了 Theano 库(更新版本)的 Python 2.7,我在定义 Theano 函数的输入参数方面遇到了问题。

代码是:

    corruption_level = T.scalar('corruption')  # % of corruption to use
    learning_rate = T.scalar('lr')  # learning rate to use

    fn = theano.function(
        inputs=[
            index,
            theano.In(corruption_level, value=0.2),
            theano.In(learning_rate, value=0.1)
        ],
        outputs=cost,
        updates=updates,
        givens={
            self.x: train_set_x[batch_begin: batch_end]
        }
    )

取自这里:

http://deeplearning.net/tutorial/code/SdA.py

它给了我这个错误,Eclipse:

NotImplementedError: In() instances and tuple inputs trigger the old
semantics, which disallow using updates and givens

所以,如果我以这种方式更改代码:

        fn = theano.function(
            inputs=[
                index,
                #theano.In(corruption_level, value=0.2),
                #theano.In(learning_rate, value=0.1)
                corruption_level,
                learning_rate
            ],
            outputs=cost,
            updates=updates,
            givens={
                self.x: train_set_x[batch_begin: batch_end]
            }
        )

它有效,但我无法传递 corruption_level 和 learning_rate 的值。

有人可以帮忙吗?谢谢!

卢卡

最佳答案

In 已被正式弃用,并且有计划的替代品。在几天内,它从 Theano 开发版本中删除了。但后来我们意识到最好保留它并更改它并摆脱我们计划的替代品。

在那段时间里,Theano 想要的东西和深度学习教程之间也存在一些不一致。

这是固定的。所以现在,更新到 Theano 0.8 或使用 Theano 的当前开发版本,它应该可以正常工作。

也许有相关问题的其他人可能需要在几天内更新深度学习教程代码,它使用的是我们删除的计划替代品。

theano.In() 现在像您的问题一样工作。

关于python - 将输入参数传递给 Theano 函数的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35622784/

相关文章:

machine-learning - 所有输入数组和目标数组必须具有相同数量的样本。”- 在单个图像上进行训练以检查模型在 keras 中是否有效

python - Theano 教程中的说明

keras - 卷积层的输出形状

python - 自定义权重初始化 tensorflow tf.layers.dense

encoding - 变压器模型中位置编码的实现细节?

numpy - 使用交叉熵时如何处理 log(0)

python - 将数字列表分成两组,使得一组中的数字与另一组中的数字没有任何共同因素

python - 如何使用 win32 在 Windows 中创建窗口焦点监听器

python - 优化正则表达式技术

python - 属性错误 : module 'attr' has no attribute 's'