I found a line of code:
out_a, out_p, out_n = model(data_a), model(data_p), model(data_n)    

in:https://github.com/liorshk/facenet_pytorch/blob/master/train_triplet.py 1
as you can see that the “forward()” is invoked multiple times before “backward()”,In my test,the gpu consumption will increase accordingly,so GPU memory leaking happens,Questions are:
1,How to solve this problem?
2,Is it possible use model as a pure feature extrator these three consecutive invoking(with some modifiction,of course),then in fourth invoking,use it as “forward()”,if “Yes”,how to implement it?