imshow() 上的“dtype 对象的图像数据无法转换为浮点数”

原文标题‘Image data of dtype object cannot be converted to float’ on imshow()

我正在尝试显示我的数据集中的图像。但是在 imshow() 函数上我有这个错误。’dtype 对象的图像数据不能转换为浮点数’

这是我的代码:

val_ds = tf.keras.utils.image_dataset_from_directory(
  '/media/Tesi/',
  validation_split=0.2,
  subset="validation",
  seed=123,
  image_size=(360, 360),
  batch_size=18)


probability_model = tf.keras.Sequential([model, 
                                         tf.keras.layers.Softmax()])

predictions = probability_model.predict(val_ds)
predictions[0]

plt.figure(figsize=(10,10))

for i in range(25):
  plt.subplot(5,5,i+1)
  plt.xticks([])
  plt.yticks([])
  plt.grid(False)
  plt.imshow(val_ds, cmap=plt.cm.binary)
  plt.xlabel(class_names[predictions[i]])
plt.show()

我可以解决吗?谢谢,最好的问候

原文链接:https://stackoverflow.com//questions/71501334/image-data-of-dtype-object-cannot-be-converted-to-float-on-imshow

回复

我来回复
  • K0mp0t的头像
    K0mp0t 评论

    image_dataset_from_directoryfunction 使用cv2.imread()as 函数从您的目录中读取图像。虽然,cv2.imread()returnsNone如果找不到文件。无是类型object。所以,检查你的路径

    2年前 0条评论