Skip to content

A tool for converting .hdf5 keras model to .pb tensorflow model. Tested on tf.keras and tensorflow 2.0

License

Notifications You must be signed in to change notification settings

chenusc11/keras_to_tensorflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keras to TensorFlow

The keras_to_tensorflow is a tool that converts a trained keras model into a ready-for-inference TensorFlow model. The original tool does not support TF2.0 very well, so I tailored it to support TF2.0

If you are looking for a convertion tool that supports TF1.x, you can checkout this repo: https://github.com/amir-abdi/keras_to_tensorflow

Summary

  • In the default behaviour, this tool freezes the nodes (converts all TF variables to TF constants), and saves the inference graph and weights into a binary protobuf (.pb) file. During freezing, TensorFlow also applies node pruning which removes nodes with no contribution to the output tensor.

How to use

Keras models can be saved as a single [.hdf5 or h5] file, which stores both the architecture and weights, using the model.save() function. This model can be then converted to a TensorFlow model by calling this tool as follows:

python keras_to_tensorflow.py 
    --input_model="path/to/keras/model.h5" 
    --output_model="path/to/save/model.pb"

Dependencies

  • keras
  • tensorflow
  • pprint
  • pathlib
  • argparse

About

A tool for converting .hdf5 keras model to .pb tensorflow model. Tested on tf.keras and tensorflow 2.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published