(Tensorflow) ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

Viewed 2258

I'm trying to combine a set of images into one np.array and convert it to a tf.data.Dataset object like so:

test = np.array([np.array(PIL.Image.open(image), dtype=np.float32) for image in image_list],
                dtype=object)

test_set = tf.data.Dataset.from_tensor_slices(test)

But doing so raises the following error:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).

Any idea what I could be doing wrong? Cheers

1 Answers

Figured out the issue was caused by creating one np.array too many. Doing the following fixed it for me:

test = [np.array(PIL.Image.open(image), dtype=np.float32) for image in image_list]
Related