amir-abdi/keras_to_tensorflow
소개
학습된 Keras 모델을 추론용 TensorFlow 모델로 변환하는 범용 코드
AI 및 머신러닝측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- +1
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalKeras to TensorFlow
The keras_to_tensorflow is a tool that converts a trained keras model into a ready-for-inference TensorFlow model. The tool is NOT tailored for TensorFlow 2.0 it SEEMS to be working fine.
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.
This tool supports multiple output networks and enables the user to rename the output tensors via the
--output_nodes_prefixflag.If the
--output_meta_ckptflag is set, the checkpoint and metagraph files for TensorFlow will also be exported which can later be used in thetf.train.Saverclass to continue training.
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"
Keras models can also be saved in two separate files where a [.hdf5 or h5] file stores the weights, using the model.save_weights() function, and another .json file stores the network architecture using the model.to_json() function.
In this case, the model can be converted as follows:
python keras_to_tensorflow.py
--input_model="path/to/keras/model.h5"
--input_model_json="path/to/keras/model.json"
--output_model="path/to/save/model.pb"
Try
python keras_to_tensorflow.py --help
to learn about other supported flags (quantize, output_nodes_prefix, save_graph_def).
Dependencies
- keras
- tensorflow
- absl
- pathlib
Legacy code
The code on how to freeze and save keras models in previous versions of tensorflow is also available. Back then, the freeze_graph tool (/tensorflow/python/tools/freeze_graph.py) was used to convert the variables into constants. This functionality is now handled by graph_util.convert_variables_to_constants
관련 프로젝트 살펴보기
불러오는 중…