I am trying to import some images into python to train a ML Algorithm. Unfortunately when i try to show them, an erro occurs:
TypeError: Image data of dtype object cannot be converted to float
The code is the following:
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
from tqdm import tqdm
from PIL import Image
from scipy import ndimage, misc
DATADIR = r"C:\Users\robda\Desktop\Università\Corsi Luiss\ML & AI\dog vs cat\Petimages"
CATEGORIES = ["Dog", "Cat"]
for category in CATEGORIES: # do dogs and cats
path = os.path.join(DATADIR,category) # create path to dogs and cats
for img in os.listdir(path): # iterate over each image per dogs and cats
img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE) # convert to array
plt.imshow(img_array, cmap='gray') # graph it
plt.show() # display!
break
break