# Keyerror when for loop dataloader

**URL:** <https://discuss.pytorch.org/t/keyerror-when-for-loop-dataloader/84601>\
**Category:** Uncategorized\
**Created:** [June 8, 2020, 6:47am UTC](https://discuss.pytorch.org/t/keyerror-when-for-loop-dataloader/84601 "2020-06-08T06:47:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jinyoung](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jinyoung/32/21064_2.png) [@Jinyoung](https://discuss.pytorch.org/u/Jinyoung)\
**Post date:** [June 8, 2020, 6:47am UTC](https://discuss.pytorch.org/t/keyerror-when-for-loop-dataloader/84601/1 "2020-06-08T06:47:28Z")

</div>

When I use Dataloader, It occurs error below:

 ![Screenshot from 2020-06-08 13-06-13](https://discuss.pytorch.org/uploads/default/original/3X/6/d/6dd5d6ed30a46579e8072bad27dc065ef74139b8.png)

I don’t know why the error occurs. Is there any problem raising this error?

Thank you

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [June 8, 2020, 9:00am UTC](https://discuss.pytorch.org/t/keyerror-when-for-loop-dataloader/84601/2 "2020-06-08T09:00:38Z")

</div>

Could you use `num_workers=0` and rerun the script?  
If that’s working, could you iterate the `Dataset` directly without wrapping it into a `DataLoader`?

PS: It’s better to post code directly by wrapping it into three backticks ```, as it makes debugging easier. 😉

---

<div class="post-metadata">

**Author:** ![Jinyoung](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jinyoung/32/21064_2.png) [@Jinyoung](https://discuss.pytorch.org/u/Jinyoung)\
**Post date:** [June 12, 2020, 8:34am UTC](https://discuss.pytorch.org/t/keyerror-when-for-loop-dataloader/84601/3 "2020-06-12T08:34:17Z")

</div>

Thank ptrblc!  
When num\_workers=0 is set, the problem is solved.  
And as you mentione, I iterated the Dataset directly with no errors

Thank you for your reply!!

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [June 12, 2020, 8:36am UTC](https://discuss.pytorch.org/t/keyerror-when-for-loop-dataloader/84601/4 "2020-06-12T08:36:14Z")

</div>

That’s weird, as the `DataLoader` seems to raise this error even though you can successfully iterate the `Dataset`.  
Are you somehow manipulating the dataset inside your training loop?
