Finding model size

Hi, I am curious about calculating model size (MB) for NN in pytorch.
Is it equivalent to the size of the file from,‘example.pth’)?
Please refer to the image below from PointNet++

I wouldn’t depend on the stored size, as the file might be compressed.
Instead you could calculate the number of parameters and buffers, multiply them with the element size and accumulate these numbers as seen here:

model = models.resnet18()
param_size = 0
for param in model.parameters():
    param_size += param.nelement() * param.element_size()
buffer_size = 0
for buffer in model.buffers():
    buffer_size += buffer.nelement() * buffer.element_size()

size_all_mb = (param_size + buffer_size) / 1024**2
print('model size: {:.3f}MB'.format(size_all_mb))
> model size: 44.629MB
1 Like

Thank you so much!!! @ptrblck