ImportError:没有名为keras.preprocessing的模块

时间:2017-03-10 18:13:49

标签: python-3.x tensorflow keras

遵循教程:

http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/#comment-419896

使用这些文件:

 https://github.com/fchollet/deep-learning-models

根据我的执行方式,我会得到2个不同的错误:

在PyCharm中运行:

 Using TensorFlow backend.
 usage: test_imagenet.py [-h] -i IMAGE
 test_imagenet.py: error: the following arguments are required: -i/--image

在cmd行中运行:

     C:\Users\AppData\Local\Programs\Python\Python35\Scripts>python deep-learning-models/test_imagenet.py --image deep-learning-models/images/dog.jpg
Traceback (most recent call last):
  File "deep-learning-models/test_imagenet.py", line 2, in <module>
    from keras.preprocessing import image as image_utils
ImportError: No module named keras.preprocessing

我该如何解决?

3 个答案:

答案 0 :(得分:1)

python项目中的每个依赖项都需要使用pipeasy_install或源代码安装。您必须按照here所述安装keras模块。

答案 1 :(得分:1)

这发生在我身上。事实证明我正在使用一个未被激活的pyvenv。只需在Linux / Mac上运行source bin/activate或在Windows上运行Scripts\activate.bat

答案 2 :(得分:0)

如果您在运行上述脚本之外解决此问题,那么最好...您可以在命令行环境中尝试以确保它在脚本之外工作:

>>> import keras
    Using TensorFlow backend.
>>> keras.__version__
    '1.2.1'
>>> keras.preprocessing
    <module 'keras.preprocessing' from '/usr/local/lib/python2.7/dist-packages/keras/preprocessing/__init__.pyc'>
>>> from keras.preprocessing import image as image_utils
>>>

确保安装了最新版本的keras。如果你上面的工作,那么上面的脚本无法找到keras包可能是环境问题。但是,如果上面不起作用或部分工作,你需要先删除它再次安装keras ..

$ pip install keras --user