Данные изображения dtype не могут быть преобразованы в float
Вот мой код
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
directory = "./img/"
classes = ["guns"]
for i in classes:
path = os.path.join(directory,i) # create path to dogs and cats
for img in os.listdir("C:/Users/Asus/.conda/envs/tensorflowp36/DL-CV-TF-Keras_Resources/5-Creating_datasets/img/guns"):
if img.endswith((".png", ".jpg", ".jpeg")):
img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array)
#plt.show()
break
break
Я получаю результат
**TypeError Traceback (most recent call last)**
**<ipython-input-62-0bf420b2bd1a> in <module>**
4 if img.endswith((".png", ".jpg", ".jpeg")):
5 img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)
----> 6 plt.imshow(img_array)
7 #plt.show()
8
**~\AppData\Roaming\Python\Python36\site-packages\matplotlib\pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url, data,** ****kwargs)**
2728 filternorm=filternorm, filterrad=filterrad, resample=resample,
2729 url=url, **({"data": data} if data is not None else {}),
-> 2730 **kwargs)
2731 sci(__ret)
2732 return __ret
**~\AppData\Roaming\Python\Python36\site-packages\matplotlib\__init__.py in inner(ax, data,** ***args,** ****kwargs)**
1436 def inner(ax, *args, data=None, **kwargs):
1437 if data is None:
-> 1438 return func(ax, *map(sanitize_sequence, args), **kwargs)
1439
1440 bound = new_sig.bind(ax, *args, **kwargs)
**~\AppData\Roaming\Python\Python36\site-packages\matplotlib\axes\_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url,** ****kwargs)**
5521 resample=resample, **kwargs)
5522
-> 5523 im.set_data(X)
5524 im.set_alpha(alpha)
5525 if im.get_clip_path() is None:
**~\AppData\Roaming\Python\Python36\site-packages\matplotlib\image.py in set_data(self, A)**
699 not np.can_cast(self._A.dtype, float, "same_kind")):
700 raise TypeError("Image data of dtype {} cannot be converted to "
--> 701 "float".format(self._A.dtype))
702
703 if self._A.ndim == 3 and self._A.shape[-1] == 1:
**TypeError: Image data of dtype object cannot be converted to float**
Что я делаю неправильно?