简体   繁体   中英

'Image data of dtype object cannot be converted to float' on imshow()

I'm trying to show images from my dataset. But on imshow() function I have this error. 'Image data of dtype object cannot be converted to float'

This is my code:

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()

Can I solve it? Thank you, Best regards

image_dataset_from_directory function uses cv2.imread() as function to read images from your directory. Though, cv2.imread() returns None if file weren't found. None is type object . So, check your path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM