Keras/TF model file size vs. PyTorch

I implemented a standard Inception-V3 for custom image classification in both Keras/TF2 and PyTorch. Both give similar accuracy and loss value. I notice that the model file sizes are very different. In TF2 saved checkpoint files, the file size is 25M. After saving to a h5 file, it becomes 9M. However, in PyTorch, the model file is 85M. I calculate the number of parameters,

The TF/Keras model has number of parameters 21,780,646.
The PyTorch model has number of parameters 21,797,286.
If every parameter is 4 byte, then PyTorch file size is 21,797,286*4/1024**2 = 83.8 MB.

I am wondering how the Keras/TF makes the saved model file size as small as 9M? I look up everywhere online but cannot find an answer. Is the Keras/TF using variable length for the parameters?

Thanks a lot.

Hi @Weijun_Tan, The size difference may be due to the compression techniques handled by Keras and pytorch.

And also .h5 contains the model configuration (architecture), weights, optimizer’s state are saved in the .h5 file. when you save the model in .pt, the .pt contains the model architecture and state dictionary. In addition to the learnable parameters, the .pt file also saves the non-learnable components of the model.

These may be the reason why there is a size difference.

Thank You!

@Kiran_Sai_Ramineni Thanks for your answer. From my calculation, PyTorch does not use any compression. PyTorch saves the weight in the state dictionary.
I wonder Keras/TF may use compression but I cannot find it online. Please note that the difference is huge, Keras/TF saved model files are 9M, 25M, while the PyTorch’s files are 85M.