The return format of torch.utils.data.DataLoader?

username: chuli
cooked: <pre><code class="lang-auto">        train_transform = transforms.Compose([transforms.RandomHorizontalFlip(), transforms.ToTensor()])
        train_set = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=train_transform)
        self.train_loader = torch.utils.data.DataLoader(dataset=train_set,
</code></pre>
<p>how to see <code>train_loader</code> ? why can we do <code>for batch_num, (data, target) in enumerate(self.train_loader):</code> ? I can not understand the format of <code>train_loader</code> .</p>

username: albanD
cooked: <p><code>train_loader</code> is a <a href="https://www.w3schools.com/python/python_iterators.asp">python iterator</a> that will return elements from your dataset batch by batch.<br>
This allows you to use it as <code>for data in train_loader:</code>.</p>

username: adarsh_pandey
cooked: <p><a class="mention" href="/u/alband">@albanD</a> please tell me how to get the label of the batch returned by  Dataloader …<br>
Sir please give an urgent reply…<br>
Regards,<br>
Adarsh</p>

username: albanD
cooked: <p>It will depend on your dataset, you dataloader will return batches of elements from your dataset.</p>

username: adarsh_pandey
cooked: <p><a class="mention" href="/u/alband">@albanD</a> I have actually seperated my features and labels …write now i am only feeding the features to the neural network and trying to predict the labels …so should i also forward the labels to NN in order to get it by my dataloader<br>
please give an urgent reply sir …<br>
Regards,<br>
Adarsh</p>

username: albanD
cooked: <blockquote>
<p>so should i also forward the labels to NN in order to get it by my dataloader</p>
</blockquote>
<p>I think you should check out the tutorials to see better how to use dataloader and create a training loop.</p>

username: adarsh_pandey
cooked: <p><a class="mention" href="/u/alband">@albanD</a> Thanks for your help!!!<br>
Best Regards,</p>

username: adarsh_pandey
cooked: <p><a class="mention" href="/u/alband">@albanD</a> sir please help again…<br>
for i,data  in enumerate(dataloader):<br>
<span class="hashtag">#training</span> starts<br>
value,_=data<br>
Traceback (most recent call last):</p>
<p>File “”, line 1, in <br>
for i,data  in enumerate(dataloader):</p>
<p>File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py”, line 819, in <strong>next</strong><br>
return self._process_data(data)</p>
<p>File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py”, line 846, in _process_data<br>
data.reraise()</p>
<p>File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\torch_utils.py”, line 385, in reraise<br>
raise self.exc_type(msg)</p>
<p>KeyError: Caught KeyError in DataLoader worker process 0.<br>
Original Traceback (most recent call last):<br>
File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\pandas\core\indexes\base.py”, line 2657, in get_loc<br>
return self._engine.get_loc(key)<br>
File “pandas/_libs/index.pyx”, line 108, in pandas._libs.index.IndexEngine.get_loc<br>
File “pandas/_libs/index.pyx”, line 132, in pandas._libs.index.IndexEngine.get_loc<br>
File “pandas/_libs/hashtable_class_helper.pxi”, line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item<br>
File “pandas/_libs/hashtable_class_helper.pxi”, line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item<br>
KeyError: 3</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>Traceback (most recent call last):<br>
File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\torch\utils\data_utils\worker.py”, line 178, in _worker_loop<br>
data = fetcher.fetch(index)<br>
File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py”, line 44, in fetch<br>
data = [self.dataset[idx] for idx in possibly_batched_index]<br>
File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py”, line 44, in <br>
data = [self.dataset[idx] for idx in possibly_batched_index]<br>
File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\pandas\core\frame.py”, line 2927, in <strong>getitem</strong><br>
indexer = self.columns.get_loc(key)<br>
File “C:\Users\SHRIKANT\Anaconda3\lib\site-packages\pandas\core\indexes\base.py”, line 2659, in get_loc<br>
return self._engine.get_loc(self._maybe_cast_indexer(key))<br>
File “pandas/_libs/index.pyx”, line 108, in pandas._libs.index.IndexEngine.get_loc<br>
File “pandas/_libs/index.pyx”, line 132, in pandas._libs.index.IndexEngine.get_loc<br>
File “pandas/_libs/hashtable_class_helper.pxi”, line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item<br>
File “pandas/_libs/hashtable_class_helper.pxi”, line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item<br>
KeyError: 3</p>
<p>why am i getting this error??</p>

username: albanD
cooked: <aside class="quote no-group" data-username="adarsh_pandey" data-post="8" data-topic="27567">
<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/adarsh_pandey/48/14907_2.png" class="avatar"> adarsh_pandey:</div>
<blockquote>
<p>pandas._libs.hashtable.PyObjectHashTable.get_item</p>
</blockquote>
</aside>
<p>Given the error, I would say some pandas related objects? I am not familiar with it so I don’t know.</p>