need PIL to import image - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: need PIL to import image (/thread-26469.html) |
need PIL to import image - ErnestTBass - May-02-2020 The following python code when run gives the error. import cv2 import numpy as np import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from tensorflow.keras import Model, Input, regularizers from tensorflow.keras.layers import Dense, Conv2D, MaxPool2D, UpSampling2D from tensorflow.keras.callbacks import EarlyStopping from keras.preprocessing import image import glob from PIL import Image from tqdm import tqdm import warnings; warnings.filterwarnings('ignore') # In[22]: #!wget https://vis-www.cs.umass.edu/lfw/lfw.tgz get_ipython().system('tar -xvzf lfw.tgz') face_images = glob.glob('lfw/**/*jpg') # In[23]: all_images = [] for i in tqdm(face_images): img = image.load_img(i, target_size=(80,80,3)) img = image.img_to_array(img) img = img/255. all_images.append(img) # In[ ]: # function to reduce image resolution while keeping the image size constant def pixalate_image(image, scale_percent = 40): width = int(image.shape[1] * scale_percent / 100) height = int(image.shape[0] * scale_percent / 100) dim = (width, height) small_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA) # scale back to original size width = int(small_image.shape[1] * 100 / scale_percent) height = int(small_image.shape[0] * 100 / scale_percent) dim = (width, height) low_res_image = cv2.resize(small_image, dim, interpolation = cv2.INTER_AREA) return low_res_image # In[ ]: all_images = np.array(all_images) # split data into train and validation data train_x, val_x = train_test_split(all_images, random_state=32, test_size=0.1)The code gives the error and traceback I did install PIL or should I say Pillow. It was no trouble to install. I ran the code and got this error. It says it needs PIL.image to load . What am I doing wrong? How do I fix it?I am running python 3.7 as show below. Python 3.7.6 | packaged by conda-forge | (default, Mar 5 2020, 15:27:18) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>Any help appreciated. Thanks in advance. Respectfully, ErnestTBass RE: need PIL to import image - menator01 - May-03-2020 I don't know if this will help much but, when I was working with images and running the code from atom, I had to use full path. Running from the shell I did not. RE: need PIL to import image - Larz60+ - May-03-2020 PIL is part of pillow. install as pillow, import as PIL |