How can I accumulate and save tensors?

Hello everyone!

I want to check the weight of a specific layer while training ResNet.
So I got the following output through the script below.

    get_weight = net.get_parameter('module.layer1.0.conv1.weight')
    L2norm_weight = torch.norm(get_weight, p='fro')
    print(L2norm_weight)

output:
image

So I want to save the number (such as 7.2596, 7.3254, etc.) in the tensor for every epoch, what should I do?

I understand that you will use this value only only for recording (i.e. not for anything like gradient computation), I would suggest you use L2norm_weight.data to extract its tensor content. This way L2norm_weight.data is not tracked autograd and will not affect computation graph. You can simply take these value and put into a list

1 Like