6

I am a beginner to machine learning, so I was trying to create a model for recognizing images referenced from Keras blog. I have installed Anaconda 3 on windows 10 and all the packages like tensorflow, keras, scipy, numpy, pandas

from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
    from keras.models import Sequential
    from keras.layers import Conv2D, MaxPooling2D
    from keras.layers import Activation, Dropout, Flatten, Dense

    datagen = ImageDataGenerator(
    rotation_range=40,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    fill_mode='nearest')
    img = load_img('E:/ML_R&D/training_set/cats/cat.3919.jpg') # this Line is giving me error

I am using conda command and pillow using pip, but when I run a code taken from keras blog I got the error.

Ashwin Geet D'Sa
  • 6,346
  • 2
  • 31
  • 59
Rahul
  • 269
  • 2
  • 10
  • 25
  • please indicate *where exactly* in your code the error pops up – desertnaut Jul 23 '18 at 13:20
  • these lines which are giving error*********** img = load_img('E:\\ML_R&D\\cat.jpg') # this is a PIL image x = img_to_array(img) # this is a Numpy array with shape (300, 300, 3) – Rahul Jul 24 '18 at 10:31
  • 1) there cannot be *two* lines generating the error 2) please indicate the exact position *in the code* 3) if indeed the error happens so early in your program, do everyone here a favor and **remove** the rest of your code, which is irrelevant & useless for the question 4) include explicitly all your imports – desertnaut Jul 24 '18 at 10:57

4 Answers4

7

You will want to install the PIL package.

How do I install PIL/Pillow for Python 3.6?

pip install pillow

or

pip3 install pillow
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
4

the issue is solved, may be the problem was that I did not restarted my system after adding all the libraries. This issue can be closed.

Rahul
  • 269
  • 2
  • 10
  • 25
4

Step 1: Firstly make sure that the PIL is uninstalled as PIL and pillow cannot co-exist. For this open Anaconda Powershell Prompt and type pip uninstall pillow Then press y(yes) when asked. If you do not have pillow or PIL then proceed to step 2

Step 2: In the same powershell prompt, execute pip install pillow

Step 3: After the installation, close the jupyter notebook, anaconda, and restart your system.

Step 4: Now execute from keras.preprocessing.image import load_image . IT WILL WORK !!!

0

You didn't import the library. Use "import PIL"

CodeRed
  • 81
  • 6