Converting Image to Tensor Error

I am getting this 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.”

even though the ndarray is an array of 249 ndarrays of shape (512x384x3) with dtype=uint8.

One interesting thing is np.array(images).shape returns (249,) not the entire shape I am expecting.

The images are of varying size so I read in each one and create a thumbnail of standard sizing using PIL thumbnail method. Then i create an ndarray and add it to the images list. From there is try and create a Tensor.

def read_image_files(path):
size = 512, 512

# Read in image using imread
images = []
for typePath in tqdm_notebook(glob(path + "/*"), desc='Type'):
    count = 0
    for imgPath in tqdm_notebook(glob(typePath + "/*"), desc='Image'):
        img =

return torch.from_numpy(np.array(images))

We dont support ndarray of ndarrays, which is why you are seeing this error.

torch itself does not support a Tensor containing many variable length Tensors, and we do not plan to support it.