Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行cnn.py时报错 #15

Open
LuM2016 opened this issue Nov 10, 2016 · 9 comments
Open

运行cnn.py时报错 #15

LuM2016 opened this issue Nov 10, 2016 · 9 comments

Comments

@LuM2016
Copy link

LuM2016 commented Nov 10, 2016

Traceback (most recent call last):

File "", line 1, in
debugfile('H:/DeepLearning/cnn_minst_keras/cnn.py', wdir='H:/DeepLearning/cnn_minst_keras')

File "D:\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 888, in debugfile
debugger.run("runfile(%r, args=%r, wdir=%r)" % (filename, args, wdir))

File "D:\Anaconda2\lib\bdb.py", line 400, in run
exec cmd in globals, locals

File "", line 1, in

File "D:\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)

File "D:\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)

File "h:/deeplearning/cnn_minst_keras/cnn.py", line 9, in
'''

File "D:\Anaconda2\lib\site-packages\keras\models.py", line 308, in add
output_tensor = layer(self.outputs[0])

File "D:\Anaconda2\lib\site-packages\keras\engine\topology.py", line 487, in call
self.build(input_shapes[0])

File "D:\Anaconda2\lib\site-packages\keras\layers\core.py", line 695, in build
name='{}_W'.format(self.name))

File "D:\Anaconda2\lib\site-packages\keras\initializations.py", line 36, in normal
return K.random_normal_variable(shape, 0.0, scale, name=name)

File "D:\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 145, in random_normal_variable
return variable(np.random.normal(loc=0.0, scale=scale, size=shape),

File "mtrand.pyx", line 1903, in mtrand.RandomState.normal (numpy\random\mtrand\mtrand.c:18479)

File "mtrand.pyx", line 234, in mtrand.cont2_array_sc (numpy\random\mtrand\mtrand.c:3092)

ValueError: negative dimensions are not allowed

@wepe
Copy link
Owner

wepe commented Nov 10, 2016

这份代码的backend使用的是theano,最新版keras默认后端tf。检查一下 .keras/keras.json 这份文件,参考 : #13 (comment)

@LuM2016
Copy link
Author

LuM2016 commented Nov 10, 2016

感谢,楼主的回答。程序是在后端为theano的情况下运行的。

@wepe
Copy link
Owner

wepe commented Nov 10, 2016

C盘下找.keras/keras.json,文件内容必须是:

{
    "image_dim_ordering": "th",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "theano"
}

@LuM2016
Copy link
Author

LuM2016 commented Nov 10, 2016

十分感谢楼主的解答。问题集解决,但是程序运行到model.fit(), python.exe 停止运行。初接触keras,还请楼主指点指点。谢谢。

@oyb001
Copy link

oyb001 commented Sep 3, 2017

我在centos 7.2 python 2.7环境执行,报以下错误,楼主之前使用的具体环境和模块版本是否可以提供一下。
[root@sz-xh_42f-op-test-cmdb-kafka keras]# python cnn.py
Using Theano backend.
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
/usr/lib64/python2.7/site-packages/scipy/init.py:110: UserWarning: Numpy 1.8.2 or above is recommended for this version of scipy (detected version 1.7.1)
UserWarning)
/usr/lib64/python2.7/site-packages/numpy/lib/utils.py:254: FutureWarning: Numpy has detected that you (may be) writing to an array returned
by numpy.diagonal or by selecting multiple fields in a record
array. This code will likely break in the next numpy release --
see numpy.diagonal or arrays.indexing reference docs for details.
The quick fix is to make an explicit copy (e.g., do
arr.diagonal().copy() or arr[['f0','f1']].copy()).
ai = a.array_interface
RuntimeError: module compiled against API version 9 but this version of numpy is 7
WARNING (theano.tensor.blas): Failed to import scipy.linalg.blas, and Theano flag blas.ldflags is empty. Falling back on slower implementations for dot(matrix, vector), dot(vector, matrix) and dot(vector, vector) (numpy.core.multiarray failed to import)
RuntimeError: module compiled against API version 9 but this version of numpy is 7
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
File "cnn.py", line 13, in
from keras.preprocessing.image import ImageDataGenerator
File "/usr/lib64/python2.7/site-packages/keras/preprocessing/image.py", line 10, in
from scipy import linalg
File "/usr/lib64/python2.7/site-packages/scipy/linalg/init.py", line 175, in
from .misc import *
File "/usr/lib64/python2.7/site-packages/scipy/linalg/misc.py", line 5, in
from .blas import get_blas_funcs
File "/usr/lib64/python2.7/site-packages/scipy/linalg/blas.py", line 155, in
from scipy.linalg import _fblas
ImportError: cannot import name _fblas

@junlulocky
Copy link
Collaborator

Hey @oyb001 ,

From your description, some comments, but not necessarily useful, I guess your python cannot find the package route correctly:

for windows:
sudo /bin/env pip uninstall name _fblas ## important
sudo /bin/env python pip install name _fblas

for MAC
sudo /usr/bin/env pip uninstall name _fblas ## important
sudo /usr/bin/env python pip install name _fblas

checkout this link for why use '/usr/bin/env' beforehand: http://www.junlulocky.com/blog/pythontricks

@junlulocky
Copy link
Collaborator

oops, please remove 'name' before _fblas.

@oyb001
Copy link

oyb001 commented Sep 7, 2017

@junlulocky ,python里面没有_fblas这边包
[root@sz-xh_42f-op-test-cmdb-kafka ~]# pip install blas
Collecting blas
Could not find a version that satisfies the requirement blas (from versions: )
No matching distribution found for blas
[root@sz-xh_42f-op-test-cmdb-kafka ~]# pip freeze |grep _fblas
[root@sz-xh_42f-op-test-cmdb-kafka ~]# pip install _fblas
Invalid requirement: '_fblas'
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 82, in init
req = Requirement(req)
File "/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/_vendor/packaging/requirements.py", line 96, in init
requirement_string[e.loc:e.loc + 8]))
InvalidRequirement: Invalid requirement, parse error at "'_fblas'"

[root@sz-xh_42f-op-test-cmdb-kafka ~]#

@oyb001
Copy link

oyb001 commented Oct 12, 2017

@junlulocky ,问题已解决,
步骤1:卸载Keras Theano Tensorflow
步骤2: 升级numpy至numpy-1.13.3版本

本人安装环境:
os:centos 7.2
python:2.7.5
theano: 0.8.2
tensorflow: 1.0.1
Using TensorFlow backend.
keras: 1.2.2
numpy:1.13.3
scipy==0.19.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants