Data loader type error

matan_cohen: <p>hi,<br>
I’m using data loader with dataset that I coded. here the dataset:</p>
<h1>Dataset preparation</h1>
<p>class dfDataset(Dataset):</p>
<pre><code>def __init__(self, df, label_list, first_words=10000):
    self.cur_df = df
    self.label_list = label_list
    self.first_words= first_words
    


def __len__(self):
    return len(self.label_list)

def __getitem__(self, idx):
    
    tmp = [i+1 for i in self.cur_df.iloc[idx, 1][:self.first_words]]
    tmp =np.append( tmp,[0]*(self.first_n_byte-len(tmp)))

    ret = dict()
    ret["words"] = np.array(words)
    ret["sig"] = np.array(np.append([i+1 for i in self.cur_df.iloc[idx, 0]], [0]*(sig_limit-len(self.cur_df.iloc[idx, 0]))))
    ret["feature"] =  np.array(self.cur_df.iloc[idx, 2])
    ret["sig_len"] = np.array(len(self.cur_df.iloc[idx, 0]))
    return ret, np.array([self.label_list[idx]])
</code></pre>
<h2>I’ve got this error at some batch :</h2>
<p>RuntimeError                              Traceback (most recent call last)<br>
 in ()<br>
5     train_Loss.append(0)<br>
----&gt; 6     for step,batch_data in enumerate(dataloader):<br>
7         i+=1<br>
8         start = time.time()</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in <strong>next</strong>(self)<br>
558         if self.num_workers == 0:  # same-process loading<br>
559             indices = next(self.sample_iter)  # may raise StopIteration<br>
–&gt; 560             batch = self.collate_fn([self.dataset[i] for i in indices])<br>
561             if self.pin_memory:<br>
562                 batch = _utils.pin_memory.pin_memory_batch(batch)</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py in default_collate(batch)<br>
66     elif isinstance(batch[0], container_abcs.Sequence):<br>
67         transposed = zip(*batch)<br>
—&gt; 68         return [default_collate(samples) for samples in transposed]<br>
69<br>
70     raise TypeError((error_msg_fmt.format(type(batch[0]))))</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py in (.0)<br>
66     elif isinstance(batch[0], container_abcs.Sequence):<br>
67         transposed = zip(*batch)<br>
—&gt; 68         return [default_collate(samples) for samples in transposed]<br>
69<br>
70     raise TypeError((error_msg_fmt.format(type(batch[0]))))</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py in default_collate(batch)<br>
61         return batch<br>
62     elif isinstance(batch[0], container_abcs.Mapping):<br>
—&gt; 63         return {key: default_collate([d[key] for d in batch]) for key in batch[0]}<br>
64     elif isinstance(batch[0], tuple) and hasattr(batch[0], ‘_fields’):  # namedtuple<br>
65         return type(batch[0])(*(default_collate(samples) for samples in zip(*batch)))</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py in (.0)<br>
61         return batch<br>
62     elif isinstance(batch[0], container_abcs.Mapping):<br>
—&gt; 63         return {key: default_collate([d[key] for d in batch]) for key in batch[0]}<br>
64     elif isinstance(batch[0], tuple) and hasattr(batch[0], ‘_fields’):  # namedtuple<br>
65         return type(batch[0])(*(default_collate(samples) for samples in zip(*batch)))</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py in default_collate(batch)<br>
50                 raise TypeError(error_msg_fmt.format(elem.dtype))<br>
51<br>
—&gt; 52             return default_collate([torch.from_numpy(b) for b in batch])<br>
53         if elem.shape == ():  # scalars<br>
54             py_type = float if elem.dtype.name.startswith(‘float’) else int</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/utils/data/<em>utils/collate.py in default_collate(batch)<br>
41             storage = batch[0].storage().<em>new_shared(numel)<br>
42             out = batch[0].new(storage)<br>
—&gt; 43         return torch.stack(batch, 0, out=out)<br>
44     elif elem_type.<strong>module</strong> == ‘numpy’ and elem_type.<strong>name</strong> != 'str</em>’ <br>
45             and elem_type.<strong>name</strong> != 'string</em>’:</p>
<p>RuntimeError: Expected object of scalar type Double but got scalar type Long for sequence element 1 in sequence argument at position <span class="hashtag">#1</span> ‘tensors’</p>
<p>I tracked down the specific batch that cause this error, but it looks o.k… any help?</p>