The variables prec1[0] and prec5[0] still hold reference to tensors. These should be replaced with prec1[0].item() and prec5[0].item() respectively. This is due to the fact that the accuracy method part of the pytorch imagenet training example code returns a tensor and can cause memory leak.



 lyakaap:

top1.update(prec1[0], X.size(0))
top5.update(prec5[0], X.size(0))


@albanD Could you please clarify the difference between detach() and item() when called on a tensor. Are these effectively the same?