TypeError: 'NoneType' object is not subscriptable

xuxianshan: <p>when I used dataloader in torch to output, I got this error: TypeError: ‘NoneType’ object is not subscriptable. I checked my dataset and it was complete. I dont know how to fix this error.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/e/cebafda63551f37beae3d91fb3119443efdaa216.png" data-download-href="https://discuss.pytorch.org/uploads/default/cebafda63551f37beae3d91fb3119443efdaa216" title="截屏2020-11-11 下午10.22.06"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/e/cebafda63551f37beae3d91fb3119443efdaa216_2_690x390.png" alt="截屏2020-11-11 下午10.22.06" data-base62-sha1="tuOZ3V7F7knqPBjSfvdS3gIsqt8" width="690" height="390" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/e/cebafda63551f37beae3d91fb3119443efdaa216_2_690x390.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/e/cebafda63551f37beae3d91fb3119443efdaa216_2_1035x585.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/e/cebafda63551f37beae3d91fb3119443efdaa216_2_1380x780.png 2x" data-dominant-color="F6F7F7"><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">截屏2020-11-11 下午10.22.06</span><span class="informations">2360×1334 413 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>

albanD: <p>Hi,</p>
<p>It looks like our code in cvtest is getting an image that is <code>None</code> instead of a Tensor. You should figure out why this is None to remove the error.</p>

xuxianshan: <p>Oh, Thank you so much. You mean I must miss something when input the images?</p>

xuxianshan: <p>Thank you again. I have fixed my prioblem. The reason why it is a error is that when I use pandas to read the csv.file, the head also was read which are not the the image and label’s address. so I add a code to delet the head. Like this:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/c/5ca919f3e3475b4f29ed5a2a82403cbf2e8ef38f.png" data-download-href="https://discuss.pytorch.org/uploads/default/5ca919f3e3475b4f29ed5a2a82403cbf2e8ef38f" title="截屏2020-11-12 下午1.25.23"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/c/5ca919f3e3475b4f29ed5a2a82403cbf2e8ef38f_2_690x131.png" alt="截屏2020-11-12 下午1.25.23" data-base62-sha1="ddIdY6bfKRuwWSmNOPONtIKJoTB" width="690" height="131" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/c/5ca919f3e3475b4f29ed5a2a82403cbf2e8ef38f_2_690x131.png, https://discuss.pytorch.org/uploads/default/original/3X/5/c/5ca919f3e3475b4f29ed5a2a82403cbf2e8ef38f.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/c/5ca919f3e3475b4f29ed5a2a82403cbf2e8ef38f.png 2x" data-dominant-color="E8E8E8"><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">截屏2020-11-12 下午1.25.23</span><span class="informations">936×178 31.7 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>

drakebohan: <aside class="quote no-group" data-username="xuxianshan" data-post="1" data-topic="102425">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/x/b9bd4f/48.png" class="avatar"> xuxianshan:</div>
<blockquote>
<p>when I used dataloader in torch to output, I got this error: TypeError: ‘NoneType’ object is not subscriptable. I checked my dataset and it was complete. I dont know how to fix this error.</p>
</blockquote>
</aside>
<p>The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None  (i.e: the object has no value). This means that you tried to do:</p>
<p><code>None[something]</code></p>
<p>Here you attempted to index an object that doesn’t have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. This is a design principle for all mutable data structures in Python.</p>
<p>This ‘NoneType’ <a href="http://net-informations.com/python/err/nonetype.htm" rel="noopener nofollow ugc">object is not subscriptable</a>  is the one thrown by python when you use the square bracket notation object[key] where an object doesn’t define the <strong>getitem</strong> method.</p>