Firstly, I put the slicing operation out of “with torch.no_grad()” scope. The loss of the classifier does not decrease and the prediction is wrong.

image1019×94 17 KB

Then, I move the slicing operation into “with torch.no_grad()”. And the classifier behaves normally.
Why does the classifier run abnormally in the first case?