Search code examples
pythontensorflowkerasmxnet

What are all the formats to save machine learning model in scikit-learn, keras, tensorflow and mxnet?


There are many ways to save a model and its weights. It is confusing when there are so many ways and not any source where we can read and compare their properties.

Some of the formats I know are:
1. YAML File - Structure only
2. JSON File - Structure only
3. H5 Complete Model - Keras
4. H5 Weights only - Keras
5. ProtoBuf - Deployment using TensorFlow serving
6. Pickle - Scikit-learn
7. Joblib - Scikit-learn - replacement for Pickle, for objects containing large data.

Discussion:
Unlike scikit-learn, Keras does not recommend you save models using pickle. Instead, models are saved as an HDF5 file. The HDF5 file contains everything you need to not only load the model to make predictions (i.e., architecture and trained parameters) but also to restart training (i.e., loss and optimizer settings and the current state).

What are other formats to save the model for Scikit-learn, Keras, Tensorflow, and Mxnet? Also what info I am missing about each of the above-discussed formats?


Solution

  • There are also formats like onnx which basically supports most of the frameworks and helps in removing the confusion of using different formats for different frameworks.