TypeError: 'NoneType' object is not subscriptable

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.

Hi,

It looks like our code in cvtest is getting an image that is None instead of a Tensor. You should figure out why this is None to remove the error.

Oh, Thank you so much. You mean I must miss something when input the images?

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:

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:

None[something]

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.

This ‘NoneType’ object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn’t define the getitem method.