How to use tensorflow model optimization for prune without any tf.keras support?

I’d like to use tensorflow model optimization for tensorflow models trained by only native tensorflow APIs without any tf.keras support. But the docs from Pruning comprehensive guide  |  TensorFlow Model Optimization is all about how to prune a keras model.
How to achieve this goal? If it can’t, can I transform my pre-trained model from native tensorflow models(saved with 'tf.saved_model.save ') to keras models(saved with tf.keras.models.save_model) for prune?

1 Like

I’d like to prune the model trained without any tf.keras support. But reference to Pruning comprehensive guide  |  TensorFlow Model Optimization, all the operations are based on tf.keras.
If I train the model in tensorflow native API, Can I use tfmot to prune my model?
If It can’t, can I transform my model type from native tensorflow model(saved with ‘tf.saved_model.save’) to keras model(saved with ‘tf.keras.models.save_model’) to use tfmot to prune the model? How to achieve this goal?
Thanks a lot.

Pruning on TFMOT toolkit only supports tf.keras model. There was contrib/model_pruning for TF1, but I don’t think it’s actively maintained.

To use Pruning on TFMOT toolkit, your model should build by Keras layers using tf.keras.layers API. (Just saved by keras API is not enough.) And also, you have to do additional training to achieve reasonable accuracy.

Added @Rino_Lee for visibility (user request)

1 Like