I am working on the VGG16 classification. But when I tried to test the model. I meet this error.
I tried to change for i in range(batch_size): to for i in range(len(target.data)):. But I still get this error. Anybody help me?
I am working on the VGG16 classification. But when I tried to test the model. I meet this error.
I tried to change for i in range(batch_size): to for i in range(len(target.data)):. But I still get this error. Anybody help me?
Check which of the objects creates the indexing error, print its shape as well as the corresponding index, and make sure the index is inside the bounds. I don’t know how correct
and class_correct
are created and thus can only speculate.
The IndexError is raised when attempting to retrieve an index from a sequence (e.g. list, tuple), and the index isn’t found in the sequence. The Python documentation defines when this exception is raised:
Raised when a sequence subscript is out of range.
Here’s an Python Split() example that raises the IndexError:
data = "one%two%three%four%five"
numbers = data.split('%')
The list numbers has 5 elements, and the indexing starts with 0, so, the last element will have index 4. If you try to subscript with an index higher than 4, the Python Interpreter will raise an IndexError since there is no element at such index.