无法 运行 Theano CNN.py 文件用于不同的数据集

Unable to run the Theano CNN.py file for a different dataset

我已经将我的数据集完全转换为 mnist.pkl.gz 文件的形式,它 运行s 用于 Theano 深度学习教程中给出的 logistic_sgd.py 和 mlp.py 程序PDF(蒙特利尔大学)。然而,在 运行 宁 CNN.py 文件时,它给出了一个难以理解的巨大错误。任何成功地 运行 不同数据集的 CNN.py 程序的人都可以帮助我,因为我完全不知道错误是什么。 我的训练集有 1176 个条目,验证集和测试集各有 168 个条目。也许问题出在批量大小上。如果可以,有人可以建议我合适的批量大小吗?

我正在使用 Anaconda Bundle 附带的 Python 2.7 的 Spyder GUI。

打印“...建筑模型”后不久出现错误

代码片段:

print '... building the model'

# Reshape matrix of rasterized images of shape (batch_size, 28 * 28)
# to a 4D tensor, compatible with our LeNetConvPoolLayer
# (28, 28) is the size of MNIST images.
layer0_input = x.reshape((batch_size, 1, 28, 28))

# Construct the first convolutional pooling layer:
# filtering reduces the image size to (28-5+1 , 28-5+1) = (24, 24)
# maxpooling reduces this further to (24/2, 24/2) = (12, 12)
# 4D output tensor is thus of shape (batch_size, nkerns[0], 12, 12)
layer0 = LeNetConvPoolLayer(
    rng,
    input=layer0_input,
    image_shape=(batch_size, 1, 28, 28),
    filter_shape=(nkerns[0], 1, 5, 5),
    poolsize=(2, 2)
)

一旦发生错误就在控制台提示:

... bulding the modelWARNING (theano.gof.compilelock): Overriding existing lock by dead process '4396'(I am process '3624')
WARNING:theano.gof.compilelock:Overriding exisiting lock by dead process '4396' (I am process '3624')

然后出现如下错误信息。

错误信息:

Traceback (most recent call last):

  File "<ipython-input-17-931f7529f484>", line 1, in <module>
    runfile('C:/Users/pratik18v/Documents/Python Scripts/CNN.py', wdir='C:/Users/pratik18v/Documents/Python Scripts')

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 682, in runfile
    execfile(filename, namespace)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "C:/Users/pratik18v/Documents/Python Scripts/CNN.py", line 339, in <module>
    evaluate_lenet5()

  File "C:/Users/pratik18v/Documents/Python Scripts/CNN.py", line 218, in evaluate_lenet5
    y: test_set_y[index * batch_size: (index + 1) * batch_size]

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\compile\function.py", line 266, in function
    profile=profile)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\compile\pfunc.py", line 511, in pfunc
    on_unused_input=on_unused_input)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\compile\function_module.py", line 1466, in orig_function
    defaults)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\compile\function_module.py", line 1324, in create
    input_storage=input_storage_lists)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\link.py", line 519, in make_thunk
    output_storage=output_storage)[:3]

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\vm.py", line 897, in make_all
    no_recycling))

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\op.py", line 1002, in make_thunk
    compute_map, no_recycling)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\op.py", line 739, in make_thunk
    output_storage=node_output_storage)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\cc.py", line 1073, in make_thunk
    keep_lock=keep_lock)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\cc.py", line 1015, in __compile__
    keep_lock=keep_lock)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\cc.py", line 1442, in cthunk_factory
    key=key, lnk=self, keep_lock=keep_lock)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\cmodule.py", line 1076, in module_from_key
    module = lnk.compile_cmodule(location)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\cc.py", line 1354, in compile_cmodule
    preargs=preargs)

  File "C:\Users\pratik18v\Anaconda\lib\site-packages\theano\gof\cmodule.py", line 2010, in compile_str
    (status, compile_stderr.replace('\n', '. ')))

Exception: ('The following error happened while compiling the node', ConvOp{('imshp', (1, 28, 28)),('kshp', (5, 5)),('nkern', 20),('bsize', 100),('dx', 1),('dy', 1),('out_mode', 'valid'),('unroll_batch', 5),('unroll_kern', 2),('unroll_patch', False),('imshp_logical', (1, 28, 28)),('kshp_logical', (5, 5)),('kshp_logical_top_aligned', True)}(Reshape{4}.0, <TensorType(float64, 4D)>), '\n', "Compilation failed (return status=1): C:\Users\PRATIK~1\AppData\Local\Temp\cchTvCFS.o: In function `instantiate':\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:1128: undefined reference to `__imp_PyExc_TypeError'\r. C:\Users\PRATIK~1\AppData\Local\Temp\cchTvCFS.o: In function `run':\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:297: undefined reference to `__imp__Py_NoneStruct'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:322: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:328: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:356: undefined reference to `__imp_PyExc_NotImplementedError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:393: undefined reference to `__imp__Py_NoneStruct'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:408: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:442: undefined reference to `__imp_PyExc_NotImplementedError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:463: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:371: undefined reference to `__imp_PyExc_TypeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:377: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:1095: undefined reference to `__imp__Py_NoneStruct'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:1094: undefined reference to `__imp__Py_NoneStruct'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:1093: undefined reference to `__imp__Py_NoneStruct'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:477: undefined reference to `__imp__Py_NoneStruct'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:492: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:1058: undefined reference to `__imp_PyExc_NotImplementedError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:1029: undefined reference to `__imp__Py_NoneStruct'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:1064: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:457: undefined reference to `__imp_PyExc_TypeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:526: undefined reference to `__imp_PyExc_NotImplementedError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:547: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:414: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:761: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:767: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:541: undefined reference to `__imp_PyExc_TypeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:620: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:903: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:599: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:605: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:782: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:803: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:835: undefined reference to `__imp_PyExc_ValueError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:498: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:897: undefined reference to `__imp_PyExc_AssertionError'\r. C:/Users/pratik18v/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/tmpjmrfis/mod.cpp:827: undefined reference to `__imp_PyExc_ValueError'\r. C:\Users\PRATIK~1\AppData\Local\Temp\cchTvCFS.o: In function `_import_array':\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1654: undefined reference to `__imp_PyCObject_Type'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1655: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1656: undefined reference to `__imp_PyExc_ImportError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1677: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1677: undefined reference to `__imp_PyExc_ImportError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1636: undefined reference to `__imp_PyExc_ImportError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1699: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1699: undefined reference to `__imp_PyExc_ImportError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1642: undefined reference to `__imp_PyExc_AttributeError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1642: undefined reference to `__imp_PyExc_ImportError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1663: undefined reference to `__imp_PyExc_RuntimeError'\r. C:/Users/pratik18v/Anaconda/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1663: undefined reference to `__imp_PyExc_ImportError'\r. collect2.exe: error: ld returned 1 exit status\r. ", "[ConvOp{('imshp', (1, 28, 28)),('kshp', (5, 5)),('nkern', 20),('bsize', 100),('dx', 1),('dy', 1),('out_mode', 'valid'),('unroll_batch', 5),('unroll_kern', 2),('unroll_patch', False),('imshp_logical', (1, 28, 28)),('kshp_logical', (5, 5)),('kshp_logical_top_aligned', True)}(<TensorType(float64, (False, True, False, False))>, <TensorType(float64, 4D)>)]")

我鼓励您添加更多信息(谢谢),所以我觉得有义务尽我所能提供帮助,但不幸的是,这可能并不多。希望其他人可以添加更好的答案。

我认为您提供的代码片段中没有出现错误。是的,它是在“...构建模型”消息之后,但我认为它在更远的地方。它可能在 theano.function 调用时产生错误。

您的问题似乎出在系统的 C++ 工具链中。我建议搜索有关 "undefined reference to __imp_PyExc_ImportError" 消息的更多信息。

例如this Whosebug question建议在命令行中加入-D MS_WIN64。但这可能是一个内部命令行,而不是您最初使用的命令行。

我不明白为什么它适用于一个数据集而不适用于另一个数据集。

只有我的笔记本电脑出了点问题。在不同的计算机上 运行 没问题。