问题
In Neural Networks and Deep Learning, there's an object called network3 (which is a PY file, written for python 2.7 and theano 0.7). I modified it to run with python 3.6 and theano 1.0.3. However, when I run the following code:
import network3
from network3 import Network
from network3 import ConvPoolLayer , FullyConnectedLayer , SoftmaxLayer
training_data , validation_data , test_data = network3.load_data_shared()
mini_batch_size = 10
net = Network([FullyConnectedLayer(n_in=784, n_out=100),
SoftmaxLayer(n_in=100, n_out=10)], mini_batch_size)
net.SGD(training_data , 60, mini_batch_size , 0.1, validation_data , test_data)
It returned a lot of errors that have similar pattern like this:
ERROR (theano.gof.opt): Optimization failure due to: constant_folding
ERROR (theano.gof.opt): node: MakeVector{dtype='int64'}(TensorConstant{10}, TensorConstant{100})
AttributeError: module 'numpy.core.multiarray' has no attribute '_get_ndarray_c_version'
Then the last paragraph in the output was:
AttributeError: ('The following error happened while compiling the node',
Elemwise{Composite{(i0 * (i1 + i2))}}(TensorConstant{10}, TensorConstant{1}, <TensorType(int64, scalar)>)
, '\n', "module 'numpy.core.multiarray' has no attribute '_get_ndarray_c_version'")
I think line 1379 caused the error:
1298 libraries=self.libraries(),
1299 header_dirs=self.header_dirs(),
-> 1300 c_compiler=self.c_compiler(),
1301 )
1302
~\AppData\Local\Continuum\Anaconda3\lib\site-packages\theano\gof\cc.py in cmodule_key_(self, fgraph, no_recycling, compile_args, libraries, header_dirs, insert_config_hash, c_compiler)
1377 # DynamicModule always add the include <numpy/arrayobject.h>
1378 sig.append('NPY_ABI_VERSION=0x%X' %
-> 1379 np.core.multiarray._get_ndarray_c_version())
1380 if c_compiler:
1381 sig.append('c_compiler_str=' + c_compiler.version_str())
AttributeError: ('The following error happened while compiling the node', Elemwise{Composite{(i0 * (i1 + i2))}}(TensorConstant{10}, TensorConstant{1}, <TensorType(int64, scalar)>), '\n', "module 'numpy.core.multiarray' has no attribute '_get_ndarray_c_version'")
I have googled the issues but couldn't find relevant solution. Could you please help?
Thanks in advance.
回答1:
What is your numpy version? Open a python terminal and run the following lines from numpy import __version__
and then print(__version__)
. In the numpy version (1.14.2
) that I am using this function is well defined.
Sometimes a package update can depreciate a function or even remove a function but also propose a new function to replace the older one. I don't know if that is the case but be always aware of this possibility.
来源:https://stackoverflow.com/questions/55024382/error-theano-gof-opt-optimization-failure-due-to-constant-folding