gpt4 book ai didi

theano - Theano.function中 'givens'变量的用途

转载 作者:行者123 更新时间:2023-12-03 11:56:04 25 4
gpt4 key购买 nike

我正在阅读http://deeplearning.net/tutorial/logreg.html给出的逻辑函数代码。我对函数的inputsgivens变量之间的区别感到困惑。计算微型批次中的模型所犯错误的函数是:

 test_model = theano.function(inputs=[index],
outputs=classifier.errors(y),
givens={
x: test_set_x[index * batch_size: (index + 1) * batch_size],
y: test_set_y[index * batch_size: (index + 1) * batch_size]})

validate_model = theano.function(inputs=[index],
outputs=classifier.errors(y),
givens={
x: valid_set_x[index * batch_size:(index + 1) * batch_size],
y: valid_set_y[index * batch_size:(index + 1) * batch_size]})

为什么不能/不会仅创建x&y共享输入变量并在创建实际模型实例时对其进行定义?

最佳答案

givens参数允许您分离模型的描述和输入变量的确切定义。这是给定参数所做的结果:修改图形以在编译之前进行编译。换句话说,我们在图中用给定的键值替换关联的值。

在深度学习教程中,我们使用普通的Theano变量来构建模型。我们使用givens来加速GPU。在这里,如果我们将数据集保留在CPU上,则在每次函数调用时,我们都会将一个微型批处理传输到GPU。由于我们在数据集上进行了多次迭代,因此最终将数据集多次传输到了GPU。由于数据集足够小,无法容纳在GPU上,因此我们将其放入一个共享变量中,以便在有可用数据集的情况下将其传输到GPU(如果禁用了图形处理单元,则保留在中央处理器上)。然后,在编译函数时,我们用对应于要使用的数据集的最小批量的 slice 交换输入。然后,Theano函数的输入只是我们要使用的微型批处理的索引。

关于theano - Theano.function中 'givens'变量的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26879157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com