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

hfdp: <p>Hello,</p>
<p>I get an error (<em><strong>TypeError: can’t convert np.ndarray of type numpy.bool_. The only supported types are: double, float, float16, int64, int32, and uint8</strong></em>) when running my DataLoader in the line where the indices are created (indices = torch.LongTensor(sample[1]).detach().to(device))</p>
<p>I run the job on a cluster with only CPU’s.<br>
Thanks for the help!</p>
<pre><code class="lang-auto">&gt; import torch
&gt; from torch.utils import data
&gt; 
&gt; class Dataset(data.Dataset):
&gt;     
&gt;     def __init__(self, list_IDs):
&gt;         self.list_IDs = list_IDs
&gt;     
&gt;     def __len__(self):
&gt;         return len(self.list_IDs)
&gt;     
&gt;     def __getitem__(self, index):
&gt;         ID = self.list_IDs[index]
&gt;         device = torch.device("cpu")
&gt;         sample = torch.load('data/' + ID)
&gt;         image = torch.DoubleTensor(sample[0]).detach().to(device)
&gt;         indices = torch.LongTensor(sample[1]).detach().to(device)
&gt;         return image, indices.unsqueeze(0)
</code></pre>
<p>The ID_List which it makes use of looks as follows:</p>
<pre><code class="lang-auto">
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
</code></pre>

Chirath_Pansilu: <aside class="quote no-group" data-username="hfdp" data-post="1" data-topic="88440">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hfdp/48/25422_2.png" class="avatar"> hfdp:</div>
<blockquote>
<p><code>indices = torch.LongTensor(sample[1]).detach().to(device)</code></p>
</blockquote>
</aside>
<p>Try using<br>
<code> indices = torch.LongTensor(sample[1].astype(np.float32)).detach().to(device)</code></p>
<p>Also <a href="https://stackoverflow.com/questions/56203536/can-t-convert-np-ndarray-of-type-numpy-bool" rel="noopener nofollow ugc">check this out.</a></p>