Wrong/different image shapes after DataLoader; bug in DL?

username: MikeTensor
cooked: <pre><code class="lang-auto">Image shape WITH DataLoader: torch.Size([376, 1241, 3])
Image ARRAY shape -manual- BEFORE/AFTER DataLoader execution: (375, 1242, 3)
</code></pre>
<p>The image size is<br>
height: 375<br>
width: 1242</p>
<p>But the ouput of DL is:<br>
height: 37<strong>6</strong><br>
width: 124<strong>1</strong></p>
<p>If I catch the output of my <code>__getitem__</code> manually an image array is returned with the right shape.<br>
If I <code>next(iter(train_dataloader))</code> I get the wrong shape … which really confuses me.<br>
I haven’t enabled any transforms or similar.</p>
<p>The confusing thing is … at the beginning everything worked fine – even with the DataLoader.<br>
I restarted my docker-container (with torch, …) several time; tried an other container, opened a new Notebook, ran it straight as a python-script, backuped my CustomData-Set with some “older” version, I backuped …: Nothing.</p>
<p>I don’t get it, where and why my image is changed in shapes.</p>
<p><code>collate_fn</code> should be deactivated.</p>
<pre><code class="lang-auto">train_data = KittiDist(root = "datasets", develop = True)

train_dataloader = DataLoader(dataset=train_data,
                               collate_fn=None,
                               batch_size=None, # how many samples per batch?
                               num_workers=1, # how many subprocesses to use for data loading? (higher = more)
                               pin_memory=False,
                               shuffle=False) # shuffle the data?

image_dl, target = next(iter(train_dataloader))
</code></pre>
<p>Any idea?</p>

username: MikeTensor
cooked: <p>using the <code>collate_fn</code> the same just with the batch_dim: ([1, 37<strong>6</strong>, 124<strong>1</strong>, 3])</p>
<p>Issue happens with different docker containers using:<br>
torchversion: ‘1.13.1+cu117’ and ‘1.12.x…’</p>
<p><a class="mention" href="/u/ptrblck">@ptrblck</a><br>
any idea? <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p><code>shuffle=False</code>: →Wrong shape.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/3/2/323823c2619ac66df81519f6b7ebabb136f918ff.png" alt="Bildschirmfoto vom 2023-03-02 05-59-35" data-base62-sha1="7ag9rdCfj56woDAyvqLWlOo2Qft" width="604" height="358"></p>
<p><code>shuffle=True</code>: → Right shape.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/0/d/0d79fef9408fc9f855c85b2af17df61c3f7705c5.png" alt="Bildschirmfoto vom 2023-03-02 05-58-51" data-base62-sha1="1VdA6rjyUS2FyMdfY5DhgPsWg61" width="604" height="358"></p>
<p>When I played around with <code>pin_memory=True/False</code> AND  <code>shuffle=True/False</code> the shape gots even more crazy (1238 instead of 1242, …). But I couldn’t reproduce it again.</p>
<p>Edit:<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/4/a/4a22e32f90d4e1926ec6877ae89ff749e62d2546.png" alt="grafik" data-base62-sha1="azQ4SYDOxdbMbSy57AXzI3G18Lc" width="569" height="33"><br>
(With <code>shuffle=True</code>)</p>
<p>and again (randomly wrong shape) also with <code>shuffle=True</code><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/0/a/0a977d6afb8bcc24da2c48ae4f6c908644b6ac32.png" alt="grafik" data-base62-sha1="1vHl6inmbMWGCDu58WTGFinqYHU" width="609" height="424"></p>
<p>What’s going on here? <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=12" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p>

username: nkdatascientist
cooked: <p>Hi <a class="mention" href="/u/miketensor">@MikeTensor</a><br>
Can you change the batch_size to 1 and try it out? In general batch_size should not be None <a href="https://pytorch.org/docs/stable/data.html" rel="noopener nofollow ugc">DataLoader</a></p>

username: ptrblck
cooked: <p>Could you point me to the implementation of <code>KittiDist</code> and where I could find this dataset?</p>

username: MikeTensor
cooked: <p>Same issue.<br>
As I wrote:</p>
<blockquote>
<p>using the <code>collate_fn</code> the same just with the batch_dim: ([1, 37<strong>6</strong>, 124<strong>1</strong>, 3])<br>
Only that the <code>batch_dim</code> is added.</p>
</blockquote>

username: MikeTensor
cooked: <p>Oh my godness – I am so sorry for the false alarm.<br>
The solution: The Kitti-Dataset does NOT have the same image-size.<br>
Since I always opened the images manually with the <code>__getitem__</code> I never got <em>lucky</em> enough to catch one of a few with different shape …</p>
<p>I am just happy that I can move on <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=12" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"><br>
– Ohh dear …</p>