本文介绍了PyMC3 &Theano - Theano 代码在 pymc3 导入后停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些简单的theano代码完美运行,当我导入pymc3时停止工作

Some simple theano code that works perfectly, stop working when I import pymc3

这里有一些片段以重现错误:

Here some snipets in order to reproduce the error:

#Initial Theano Code (this works)
import theano.tensor as tsr

x = tsr.dscalar('x')
y = tsr.dscalar('y')
z = x + y

#Snippet 1
import pymc3 as pm
import theano.tensor as tsr

x = tsr.dscalar('x')
y = tsr.dscalar('y')
z = x + y

#Snippet 2
import theano.tensor as tsr
import pymc3 as pm

x = tsr.dscalar('x')
y = tsr.dscalar('y')
z = x + y

#Snippet 3
import pymc3 as pm

x = pm.theano.tensor.dscalar('x')
y = pm.theano.tensor.dscalar('y')
z = x + y

对于之前的每个片段,我都收到以下错误:

And I get the following error for each of the previous snippets:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/tom/anaconda/lib/python3.4/site-packages/theano/gof/op.py in __call__(self, *inputs, **kwargs)
    516                 try:
--> 517                     storage_map[ins] = [self._get_test_value(ins)]
    518                     compute_map[ins] = [True]

/Users/tom/anaconda/lib/python3.4/site-packages/theano/gof/op.py in _get_test_value(cls, v)
    478
--> 479         raise AttributeError('%s has no test value' % v)
    480

AttributeError: x has no test value

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-2-ef8582b040f8> in <module>()
      3 x = pm.theano.tensor.dscalar('x')
      4 y = pm.theano.tensor.dscalar('y')
----> 5 z = x + y

/Users/tom/anaconda/lib/python3.4/site-packages/theano/tensor/var.py in __add__(self, other)
    126     def __add__(self, other):
    127         try:
--> 128             return theano.tensor.basic.add(self, other)
    129         # We should catch the minimum number of exception here.
    130         # Otherwise this will convert error when Theano flags

/Users/tom/anaconda/lib/python3.4/site-packages/theano/gof/op.py in __call__(self, *inputs, **kwargs)
    523                         run_perform = False
    524                     elif config.compute_test_value == 'raise':
--> 525                         raise ValueError('Cannot compute test value: input %i (%s) of Op %s missing default value' % (i, ins, node))
    526                     elif config.compute_test_value == 'ignore':
    527                         # silently skip test

ValueError: Cannot compute test value: input 0 (x) of Op Elemwise{add,no_inplace}(x, y) missing default value

有什么想法吗?提前致谢

Any Ideas ?Thanks in advance

推荐答案

我认为这与 pymc3 设置 theano.config.compute_test_value = 'raise': https://github.com/pymc-devs/pymc3/blob/master/pymc3/model.py#L395

I think this is related to pymc3 setting theano.config.compute_test_value = 'raise': https://github.com/pymc-devs/pymc3/blob/master/pymc3/model.py#L395

您可以将 theano.config.compute_test_value 显式设置回 'ignore' 以消除错误.

You can explicitly set theano.config.compute_test_value back to 'ignore' to get rid of the error.

这篇关于PyMC3 &amp;Theano - Theano 代码在 pymc3 导入后停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 09:41