DJ Howarth
DJ Howarth

Reputation: 582

ImportError: No module named keras.preprocessing

Following the tutorial:

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

Using these files:

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

I get 2 separate errors depending on how I execute:

Running in PyCharm:

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

Running in cmd line:

     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

How do I resolve?

Upvotes: 4

Views: 53483

Answers (4)

Ahmed faisal
Ahmed faisal

Reputation: 1

from keras.models import Sequential
from keras  import legacy_tf_layer
from keras.preprocessing import image as image_utils
from keras.preprcessing.text import Toknizer
import pandas as pd
from sklearn.model_selection import train_test_spli

Upvotes: 0

ham-sandwich
ham-sandwich

Reputation: 4050

This happened to me. It turned out I was working in a pyvenv which wasn't activated. Just run source bin/activate on Linux/Mac or Scripts\activate.bat on Windows

Upvotes: 1

AvkashChauhan
AvkashChauhan

Reputation: 20576

Its best if you solve this problem outside running the above script... Here is what you can try in your command line environment to make sure it works outside your script:

>>> 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
>>>

Make sure you have latest version of keras installed. If you get above working then it could be the environment issue where above script is not able to find the keras package. However if above does not work or work partially you would need to install keras again by removing it first..

$ pip install keras --user

Upvotes: 3

Dhanush Gopinath
Dhanush Gopinath

Reputation: 5749

Every dependency in a python project need to be installed using pip or easy_install or from the source code. You will have to install the keras module as mentioned here.

Upvotes: 1

Related Questions