IndexError: list index out of range for CNN model testing

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.


Thank you for your reply. Please check the shape.
class_correct means the correct prediction number, for example, if the test image is negative, the prediction is negative, I made it add 1.
I also read this: IndexError: index out of bounds error - #5 by Gutabaga