TypeError: zip argument #3 must support iteration

nikitha_kona: <p>Hello I am getting the below error and its running for 2 batches and throwing this error.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/6/6d40b4d656ae9f9bb2e3a9a05331cc7676cab84b.png" data-download-href="https://discuss.pytorch.org/uploads/default/6d40b4d656ae9f9bb2e3a9a05331cc7676cab84b" title="53%20PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/6/6d40b4d656ae9f9bb2e3a9a05331cc7676cab84b_2_690x459.png" alt="53%20PM" data-base62-sha1="fAuFYJZtNNzins147v8OnvN8NIL" width="690" height="459" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/6/6d40b4d656ae9f9bb2e3a9a05331cc7676cab84b_2_690x459.png, https://discuss.pytorch.org/uploads/default/optimized/2X/6/6d40b4d656ae9f9bb2e3a9a05331cc7676cab84b_2_1035x688.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/2X/6/6d40b4d656ae9f9bb2e3a9a05331cc7676cab84b_2_1380x918.png 2x" data-dominant-color="F0F1F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">53%20PM</span><span class="informations">1892×1260 289 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div> <div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/3/3ba9e67f5c0ed587e125ad8092f1bedbdd25df79.png" data-download-href="https://discuss.pytorch.org/uploads/default/3ba9e67f5c0ed587e125ad8092f1bedbdd25df79" title="17%20PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/3/3ba9e67f5c0ed587e125ad8092f1bedbdd25df79_2_658x500.png" alt="17%20PM" data-base62-sha1="8vObcorF86v4JS1GZbIYcQNioWd" width="658" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/3/3ba9e67f5c0ed587e125ad8092f1bedbdd25df79_2_658x500.png, https://discuss.pytorch.org/uploads/default/optimized/2X/3/3ba9e67f5c0ed587e125ad8092f1bedbdd25df79_2_987x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/2X/3/3ba9e67f5c0ed587e125ad8092f1bedbdd25df79_2_1316x1000.png 2x" data-dominant-color="F0EEEE"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">17%20PM</span><span class="informations">1610×1222 194 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Thanks</p>

ptrblck: <p>Could you add an <code>assert</code> statement in the <code>else</code> condition in your <code>__getitem__</code>?<br>
Maybe the condition is not met and you return nothing, which might yield this error.</p>

nikitha_kona: <p>Thanks but assert what?.</p>

ptrblck: <p>I would just add a dummy assert statement or raise an exception, so that the code crashes:</p>
<pre><code class="lang-python">assert False, "empty batch"
raise RuntimeError("empty batch")
</code></pre>

nikitha_kona: <aside class="quote no-group quote-modified" data-username="ptrblck" data-post="4" data-topic="50394">
<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/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>assert False, “empty batch” raise RuntimeError(“empty batch”)</p>
</blockquote>
</aside>
<p>Got the below error.Does that mean the next batch of 64 images aren’t present in folder.<br>
AssertionError                            Traceback (most recent call last)<br>
 in <br>
2     res.train()<br>
3     running_loss=0<br>
----&gt; 4     for i,(data,target) in enumerate(train_load):<br>
5<br>
6         print(i,data.shape,target.shape)</p>
<p>/anaconda3/lib/python3.6/site-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>
 → 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>/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py in (.0)<br>
558         if self.num_workers == 0:  # same-process loading<br>
559             indices = next(self.sample_iter)  # may raise StopIteration<br>
 → 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> in <strong>getitem</strong>(self, idx)<br>
19             self.cj.append(img)<br>
20             <span class="hashtag-raw">#assert</span>(path.exists(img)),“wronggg”<br>
—&gt; 21             assert False, “empty batch”<br>
22             raise RuntimeError(“empty batch”)<br>
23</p>
<p>AssertionError: empty batc</p>

ptrblck: <p>Yes, apparently neither the file is “open/closed” (not sure what this entry means) nor the path can be found.<br>
Add the <code>img</code> to the exception/assert so that you’ll see which path is wrong and can fix it.</p>

nikitha_kona: <p>Thanks.But I tried to add to list and see if 64 images aren’t in proper format.But I get the following now.Can you please explain what does that mean.Thanks</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/d/d66bd737a58b18225dd003f3dad157e548acdaea.png" data-download-href="https://discuss.pytorch.org/uploads/default/d66bd737a58b18225dd003f3dad157e548acdaea" title="15%20PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/d/d66bd737a58b18225dd003f3dad157e548acdaea_2_690x354.png" alt="15%20PM" data-base62-sha1="uARe1SqcThBdhPF4U3XBIWRJm5Q" width="690" height="354" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/d/d66bd737a58b18225dd003f3dad157e548acdaea_2_690x354.png, https://discuss.pytorch.org/uploads/default/optimized/2X/d/d66bd737a58b18225dd003f3dad157e548acdaea_2_1035x531.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/d/d66bd737a58b18225dd003f3dad157e548acdaea.png 2x" data-dominant-color="EEEFEF"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">15%20PM</span><span class="informations">1288×662 82.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div> <div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/3/3d106cdb1d80269601ecec1625d1e882176caeb9.png" data-download-href="https://discuss.pytorch.org/uploads/default/3d106cdb1d80269601ecec1625d1e882176caeb9" title="23%20PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/3/3d106cdb1d80269601ecec1625d1e882176caeb9_2_562x500.png" alt="23%20PM" data-base62-sha1="8IcjCSrtvWNxsw4ctgKgTAtqAwF" width="562" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/3/3d106cdb1d80269601ecec1625d1e882176caeb9_2_562x500.png, https://discuss.pytorch.org/uploads/default/optimized/2X/3/3d106cdb1d80269601ecec1625d1e882176caeb9_2_843x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/2X/3/3d106cdb1d80269601ecec1625d1e882176caeb9_2_1124x1000.png 2x" data-dominant-color="F2F0F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">23%20PM</span><span class="informations">1476×1312 184 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>It looks like more than a single path cannot be found, so that the length of the list grows.<br>
Can you print this list after the code crashed using <code>print(dataset.cj)</code>, where <code>dataset</code> refers to the instance of your current <code>Dataset</code>.</p>
<p>PS: It’s better to post the code directly by wrapping it in three backticks ```, as this will e.g. allow to search for the code <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

pchhapolika: <aside class="quote no-group" data-username="ptrblck" data-post="4" data-topic="50394">
<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/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<pre><code class="lang-auto">assert False, "empty batch"
raise RuntimeError("empty batch")
</code></pre>
</blockquote>
</aside>
<p>What was the solution for this?</p>

ptrblck: <p>Could you give more details which solution you mean?<br>
My suggestion to add <code>assert</code> statements was to debug the issue in the original post.</p>