Issue
I am following a image classification tutorial at Tensorflow. On running the following code-
import PIL
import tensorflow as tf
from tensorflow import keras
sunflower_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/592px-Red_sunflower.jpg"
sunflower_path = tf.keras.utils.get_file('Red_sunflower', origin=sunflower_url)
img = keras.preprocessing.image.load_img(sunflower_path, target_size=(180, 180))
I receive the following error at the last line.
ImportError: Could not import PIL.Image. The use of `load_img` requires PIL.
How can I fix the above issue?
Kindly note that I have pillow installed on my conda working environment (python=3.8, Tensorflow=2.3).
Solution
The error says that you don't have pillow
installed on your machine.
If you're using conda, then you have to do
conda install pillow
If you're not using conda, then I would just try
pip install pillow
Edit 1: In case you have PIL installed in a conda env already, then try
conda uninstall PIL
conda install Pillow
Edit 2: In case you may have an older version of Pillow installed that does not work with the version of TensorFlow/Keras installed in your env, reinstalling Pillow might help.
Answered By - Dr. Regex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.