{"id":14958664,"url":"https://github.com/amir-abdi/keras_to_tensorflow","last_synced_at":"2025-10-06T16:59:22.369Z","repository":{"id":41612349,"uuid":"90821710","full_name":"amir-abdi/keras_to_tensorflow","owner":"amir-abdi","description":"General code to convert a trained keras model into an inference tensorflow model","archived":false,"fork":false,"pushed_at":"2020-11-23T20:22:56.000Z","size":149,"stargazers_count":1654,"open_issues_count":63,"forks_count":534,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-10-06T16:59:21.806Z","etag":null,"topics":["deep-learning","keras","machine-learning","python","tensorflow"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amir-abdi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-10T04:43:29.000Z","updated_at":"2025-09-23T15:08:52.000Z","dependencies_parsed_at":"2022-07-07T11:25:02.811Z","dependency_job_id":null,"html_url":"https://github.com/amir-abdi/keras_to_tensorflow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amir-abdi/keras_to_tensorflow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amir-abdi%2Fkeras_to_tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amir-abdi%2Fkeras_to_tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amir-abdi%2Fkeras_to_tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amir-abdi%2Fkeras_to_tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amir-abdi","download_url":"https://codeload.github.com/amir-abdi/keras_to_tensorflow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amir-abdi%2Fkeras_to_tensorflow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278646773,"owners_count":26021511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","keras","machine-learning","python","tensorflow"],"created_at":"2024-09-24T13:17:46.763Z","updated_at":"2025-10-06T16:59:22.337Z","avatar_url":"https://github.com/amir-abdi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Keras to TensorFlow\nThe **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.*\n\n#### Summary\n- 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.\n\n- This tool supports multiple output networks and enables the user to rename the output tensors via the `--output_nodes_prefix` flag.\n \n- If the `--output_meta_ckpt` flag is set, the checkpoint and metagraph files for TensorFlow will also be exported\nwhich can later be used in the `tf.train.Saver` class to continue training.   \n\n\n## How to use\nKeras models can be saved as a single [`.hdf5` or `h5`] file, which stores both the architecture and weights, using the `model.save()` function.\n This model can be then converted to a TensorFlow model by calling this tool as follows:\n    \n    python keras_to_tensorflow.py \n        --input_model=\"path/to/keras/model.h5\" \n        --output_model=\"path/to/save/model.pb\"\n     \nKeras 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.\nIn this case, the model can be converted as follows:\n\n    python keras_to_tensorflow.py \n        --input_model=\"path/to/keras/model.h5\" \n        --input_model_json=\"path/to/keras/model.json\" \n        --output_model=\"path/to/save/model.pb\"\n\nTry \n\n    python keras_to_tensorflow.py --help\nto learn about other supported flags (quantize, output_nodes_prefix, save_graph_def).\n\n\n## Dependencies\n- keras\n- tensorflow\n- absl\n- pathlib\n\n## Legacy code\nThe 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```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famir-abdi%2Fkeras_to_tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famir-abdi%2Fkeras_to_tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famir-abdi%2Fkeras_to_tensorflow/lists"}