没有名为nanguardmod的模块

2024-10-03 04:36:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我的theano程序中有一个错误导致了NaN值。doc建议使用nanguardmode来追踪问题的根源。在

当我从doc网页复制/粘贴这一行时:

from theano.compile.nanguardmode import NanGuardMode

我得到:

^{pr2}$

键入以下内容时找不到nanguardmode的任何符号:

help(theano.compile)

你知道为什么nanguardmode缺席吗?我该怎么解决这个问题?在

编辑:

谢谢你的回复。在

关于我的Theano版本,我找不到如何检查它。但我认为它是最新的:我大约一个月前从安装网页安装的。64M位。在

关于detect\u nan hack:事情变得更奇怪了!在

第一:如果我尝试使用:

post_func=theano.compile.monitormode.detect_nan

我得到:

File "C:\SciSoft\WinPython-64bit-2.7.9.4\python-2.7.10.amd64\lib\site-packages\theano\compile\monitormode.py", line 87, in detect_nan
if (not isinstance(numpy.random.RandomState, output[0]) and

NameError: global name 'numpy' is not defined

事实上,numpy不是在monitormode模块中导入的。。。那是已知的窃听器吗?在

第二:如果我尝试使用detect_ngnan的复制/粘贴,nan会神奇地消失。其他一切都保持不变,在我的theano函数中没有detect iu nan(迭代训练模型),我在迭代5得到nan:

epoch 1, valid 28.582677 %, train 27.723320 % 0.546633
epoch 2, valid 27.814961 %, train 25.681751 % 0.500522
epoch 3, valid 27.263780 %, train 24.262972 % 0.478799
epoch 4, valid 26.938976 %, train 23.209021 % 0.463017
epoch 5, valid 50.000000 %, train 50.000000 % nan

(最后一个数字是成本价值)

当我添加

mode=theano.compile.MonitorMode(post_func=detect_nan)

对于函数,至少在迭代100次(甚至更多)之前没有出现任何nan。在

epoch 1, valid 28.582677 %, train 27.723320 % 0.546633
epoch 2, valid 27.814961 %, train 25.681751 % 0.500522
epoch 3, valid 27.263780 %, train 24.262972 % 0.478799
epoch 4, valid 26.938976 %, train 23.209021 % 0.463017
epoch 5, valid 26.289370 %, train 22.320902 % 0.450454
... etc ...

这是怎么回事???在


Tags: numpy网页doc粘贴traintheanonanpost
1条回答
网友
1楼 · 发布于 2024-10-03 04:36:56

NanGuardMode于5月1日被移到Theano的最新版本(来自PyLearn2),这是在3月26日版本0.7发布之后,因此您需要从GitHub中upgrade to the bleeding edge version来使用NanGuardMode。在

或者,您可以使用debug FAQ中的detect_nan示例:

import numpy

import theano

# This is the current suggested detect_nan implementation to
# show you how it work.  That way, you can modify it for your
# need.  If you want exactly this method, you can use
# ``theano.compile.monitormode.detect_nan`` that will always
# contain the current suggested version.

def detect_nan(i, node, fn):
    for output in fn.outputs:
        if (not isinstance(output[0], numpy.random.RandomState) and
            numpy.isnan(output[0]).any()):
            print '*** NaN detected ***'
            theano.printing.debugprint(node)
            print 'Inputs : %s' % [input[0] for input in fn.inputs]
            print 'Outputs: %s' % [output[0] for output in fn.outputs]
            break

x = theano.tensor.dscalar('x')
f = theano.function([x], [theano.tensor.log(x) * x],
                    mode=theano.compile.MonitorMode(
                        post_func=detect_nan))

相关问题 更多 >