55

I am doing a deep learning course on udacity. For the first assignment whenI tried to run the script which is below the problem 1 , I got this error. So I tried to uninstall PIL and pillow and then installed these individually but I didnot succeeded. I need help guy. I am using tensorflow docker image with python notebook.

# These are all the modules we'll be using later. Make sure you can import them
# before proceeding further.
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import scipy
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
# Config the matplotlib backend as plotting inline in IPython
%matplotlib inline 

url = 'http://commondatastorage.googleapis.com/books1000/'
last_percent_reported = None

def download_progress_hook(count, blockSize, totalSize):
    percent = int(count * blockSize * 100 / totalSize)

   if last_percent_reported != percent:
     if percent % 5 == 0:
  sys.stdout.write("%s%%" % percent)
  sys.stdout.flush()
else:
  sys.stdout.write(".")
  sys.stdout.flush()

last_percent_reported = percent

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/1_notmnist.ipynb

You can see the code here. I got error in the code block after problem 1 Error Image

I tried each and everything describe here in these two links or solutions:

Solution 1 on stackoverflow

Solution 2 on stackoverflow

Operating System:

using docker and tensorflow is installed in a container with IPython notebook.

The output from python -c "import tensorflow; print(tensorflow.version)".

0.11.0

Community
  • 1
  • 1
Muneeb Ul HaXan
  • 551
  • 1
  • 4
  • 5

5 Answers5

71

pip install pillow

Then replace from IPython.display import display, Image with from IPython.display import display from PIL import Image

Yohanna
  • 869
  • 7
  • 6
15

I met the same problem. But I am using a different setting for the tensorflow. OS: Ubuntu 14.04 LTS. Installation using Anaconda. I solved it by following the warnings in Pillow installation. It may not be useful for a docker installation of tensorflow though.

Here are the steps I did. First enter the tensorflow environment,

source activate tensorflow

Then uninstall PIL and install Pillow

conda uninstall PIL
conda install Pillow

Then in the provided code, replace

from IPython.display import display, Image

by

from IPython.display import display
from PIL import Image

That's all. Re-run the code and it works without PIL error.

rort1989
  • 263
  • 2
  • 9
  • 4
    Note: you might need to restart spyder for the change to take effect. (Thanks SanjeevKumar for pointing this out!) – Zain Rizvi May 30 '18 at 02:43
  • Thank You. I learning Artifficial Intelligence in Udemy and in the class 255 i got this situation. I using Ubuntu 16.04. Thank you again. – LUISAO Jun 25 '18 at 14:25
2

I solved this issue by uninstalling Jupyter and re-installed it properly. The problem was linked to the notebook kernel. My terminal and my notebook didn't have the same kernel. To check it, I did in my virtualenv:

jupyter-kernelspec list

then go to your kernel directories lists and open the json file (something like /Library/Jupyter/kernels/virtualenv/kernel.json)

and check than the Python link is the same than in the output of which python.

If not, create another kernel for your virtualenv.

A. Attia
  • 1,630
  • 3
  • 20
  • 29
  • This answer got me a good portion of the way there. To create another kernel for my virtualenv, I had to refer to this document, http://ipython.readthedocs.io/en/stable/install/kernel_install.html, the "Kernels for Different Environments" section. – Tyler Byers Sep 22 '17 at 19:39
1

As for Windows users who use Anaconda, there is likely a simple solution to your problem. If you've installed 'tensorflow' with pip, or a pip variant (ie. pip3), then you will have to install tensorflow again, but this time with the command conda install tensorflow.

-2

Install PIL in anaconda, then:

from PIL import Image
model.fit_generator(
        train_generator,
        steps_per_epoch=2000 // batch_size,
        epochs=50,
        validation_data=validation_generator,
        validation_steps=800 // batch_size)
model.save_weights('first_try.h5') 

output will display like: Epoch 1/50
 34/125 [=======>......................] - ETA: 7:23 - loss: 0.7237 - acc: 0.5478 ... comntinue 
nnyby
  • 4,748
  • 10
  • 49
  • 105
Sneha Mule
  • 641
  • 8
  • 6