TypeError: can't convert np.ndarray of type numpy.bool_. The only supported types are: double, float, float16, int64, int32, and uint8

Hello,

I get an error (TypeError: can’t convert np.ndarray of type numpy.bool_. The only supported types are: double, float, float16, int64, int32, and uint8) when running my DataLoader in the line where the indices are created (indices = torch.LongTensor(sample[1]).detach().to(device))

I run the job on a cluster with only CPU’s.
Thanks for the help!

> import torch
> from torch.utils import data
> 
> class Dataset(data.Dataset):
>     
>     def __init__(self, list_IDs):
>         self.list_IDs = list_IDs
>     
>     def __len__(self):
>         return len(self.list_IDs)
>     
>     def __getitem__(self, index):
>         ID = self.list_IDs[index]
>         device = torch.device("cpu")
>         sample = torch.load('data/' + ID)
>         image = torch.DoubleTensor(sample[0]).detach().to(device)
>         indices = torch.LongTensor(sample[1]).detach().to(device)
>         return image, indices.unsqueeze(0)

The ID_List which it makes use of looks as follows:


ID000001.pt
ID000002.pt
ID000003.pt
ID000004.pt
ID000005.pt
ID000006.pt
ID000007.pt
ID000008.pt
ID000009.pt
ID000010.pt
ID000011.pt
ID000012.pt
ID000013.pt
ID000014.pt
ID000015.pt
ID000016.pt
ID000017.pt
ID000018.pt
ID000019.pt
ID000020.pt
ID000021.pt
ID000022.pt
ID000023.pt
ID000024.pt
ID000025.pt
ID000026.pt
ID000027.pt
ID000028.pt
ID000029.pt
ID000030.pt
ID000031.pt
ID000032.pt
ID000033.pt
ID000034.pt
ID000035.pt
ID000036.pt
ID000037.pt
ID000038.pt
ID000039.pt
ID000040.pt
ID000041.pt
ID000042.pt
ID000043.pt
ID000044.pt
ID000045.pt
ID000046.pt
ID000047.pt
ID000048.pt
ID000049.pt
ID000050.pt
ID000051.pt
ID000052.pt
ID000053.pt
ID000054.pt
ID000055.pt
ID000056.pt
ID000057.pt
ID000058.pt
ID000059.pt
ID000060.pt
ID000061.pt
ID000062.pt
ID000063.pt
ID000064.pt
ID000065.pt
ID000066.pt
ID000067.pt
ID000068.pt
ID000069.pt
ID000070.pt
ID000071.pt
ID000072.pt
ID000073.pt
ID000074.pt
ID000075.pt
ID000076.pt
ID000077.pt
ID000078.pt
ID000079.pt
ID000080.pt
ID000081.pt
ID000082.pt
ID000083.pt
ID000084.pt
ID000085.pt
ID000086.pt
ID000087.pt
ID000088.pt
ID000089.pt
ID000090.pt
ID000091.pt
ID000092.pt
ID000093.pt
ID000094.pt
ID000095.pt
ID000096.pt
ID000097.pt
ID000098.pt
ID000099.pt
ID000100.pt

Try using
indices = torch.LongTensor(sample[1].astype(np.float32)).detach().to(device)

Also check this out.