Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从theano函数内部打印值?_Python_Machine Learning_Theano - Fatal编程技术网

Python 如何从theano函数内部打印值?

Python 如何从theano函数内部打印值?,python,machine-learning,theano,Python,Machine Learning,Theano,我最近从Matlab/C++转到theano,并具有以下功能 train_model = theano.function([x_in, y_index], classifier.cost, updates=updates, givens={ x: x_in,

我最近从Matlab/C++转到theano,并具有以下功能

train_model = theano.function([x_in, y_index],
                          classifier.cost,
                          updates=updates,
                          givens={
                              x: x_in,
                              y: y_in[y_index]})
我想在每次迭代中打印两层网络之间的值(用于调试、更好地控制函数等)
我已尝试编辑设置分类器的函数,以便它打印(使用print()或theano.printing.print/theano.pp()),并且在设置模型时,我得到的只是一个打印。

在您的示例中
分类器。cost
是一个表达式,可能由基于相同输入的多个其他表达式组成。您可以将这些中间表达式中的任何一个转换为函数,就像使用
分类器一样

f_first_layer = theano.function([x], first_layer)

然后,您可以调用并打印此函数的输出,例如,每次调用
列车模型后。如果您在
train\u model
之前调用它,使用的参数与您将在后面调用
train\u model
的参数相同,那么您将获得层的精确输出,因为它们将由
train\u model
进行评估(在
train\u model
之后调用它将因更新而有所不同)。

好的,为了分享知识,例如,我所做的是:f_first_layer=theano.function([x],[cost,print_val]),它返回了我想要控制的值,谢谢你的回答非常感谢你的更新!这看起来是最有用的方法。