0

I stored multiple images as below.

for name in image_names:
    images.append(cv2.imread("./train_mini/"+name))

And I’d like to use those images in CNN training later. However, when I stored those data in “torch.utils.data.TensorDataset” like below, it shows error:

“RuntimeError: can’t convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8.” 

So I checked the data type of images, and it was “object”.

train = torch.utils.data.TensorDataset(torch.from_numpy(X_train), torch.from_numpy(Y_train))

How can I solve this problem? I am completely stuck…

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
soshi shimada
  • 425
  • 1
  • 7
  • 21
  • [Read here](https://stackoverflow.com/questions/3386259/how-to-make-a-multidimension-numpy-array-with-a-varying-row-size) about what happens when you have a list of differently shaped arrays. Also, you can pass a list of arrays into `TensorDataset`, no need to run `torch.from_numpy()`. – Nils Werner Nov 14 '17 at 09:54
  • 1
    Thank you! That was because the install image sizes were various. – soshi shimada Nov 14 '17 at 10:48

1 Answers1

0

I think Pytorsh doesn't support ndarray of ndarrays, which is why you are seeing this error.

Saghe Achraf
  • 330
  • 1
  • 7