Hi,
What happens is that you seem to run this code with the autograd enabled.
Since the parameters in the resnet require gradients, your out does as well (and so contains all the history to compute these gradients if needed). When you save out.cpu() in your dictionary, you still hold onto this history. So the memory usage increases.
The best thing to do here I think is to decorate your function with @torch.no_grad() or run the model within the with torch.no_grad(): context manager. to disable autograd.
PS: you should not call the .forward() method of modules directly, but call them with the input: out = resnet101(image) in your case. Otherwise features like hooks won’t work.