Problem in image reading

import numpy as np
import os
from pathlib import Path
from keras.preprocessing import image

path = Path(“images”)

for folder_names in path.glob("*"):
print(folder_names)
label = str(folder_names).split("\")[-1][:-1]
print(label)

for img_path in folder_names.glob("*.jpg"):
    print(img_path)    

labels_dict = {“cat”:0,“dog”:1,“horse”:2,“humans”:3}

for folder_names in path.glob("*"): #glob() gives list of all folders inside the given folder
label = str(folder_names).split("\")[-1][:-1]

image_data=[]
labels=[]

for img_path in folder_names.glob("*.jpg"):
    img = image.load_img(img_path,target_size=(100,100))
    img_array = image.img_to_array(img)
    image_data.append(img_to_array)
    labels.append(labels_dict[label])

ImportError: Could not import PIL.Image. The use of load_img requires PIL.

hey @Jrockstar ,
kindly re-install keras and pillow once again.
and once you have done this , then restart your system once.

I hope it will work properly then.
Thank You.

now the error is as following:

NameError: name ‘img_to_array’ is not defined

sorry,it was my mistake. It is working now.Thank you for your support

No problem @Jrockstar ,
kindly mark this doubt as resolved and do provide your valuable feedback.

Thank You and Happy Learning :slightly_smiling_face: .