1

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

marco
  • 121
  • 1
  • 10
  • 2
    `val_ds` is a `tf.data.Dataset` object, so you need to extract the images from that object: [How to extract data/labels back from TensorFlow dataset](https://stackoverflow.com/q/56226621/13138364) – tdy Mar 16 '22 at 17:41
  • Yes, I think that this is the problem. But the function np.concatenate returns me `iteration over a 0-d array`. I'm confused. – marco Mar 16 '22 at 17:55

1 Answers1

2

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

K0mp0t
  • 89
  • 1
  • 6