{"id":15290475,"url":"https://github.com/onnx/keras-onnx","last_synced_at":"2025-10-07T04:30:26.240Z","repository":{"id":47176589,"uuid":"162340677","full_name":"onnx/keras-onnx","owner":"onnx","description":"Convert tf.keras/Keras models to ONNX","archived":true,"fork":false,"pushed_at":"2021-09-09T19:50:42.000Z","size":18426,"stargazers_count":381,"open_issues_count":105,"forks_count":106,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-09-07T01:57:58.650Z","etag":null,"topics":["keras","onnx","subclassing","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onnx.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":"2018-12-18T20:15:57.000Z","updated_at":"2025-08-07T12:23:28.000Z","dependencies_parsed_at":"2022-08-12T13:20:11.527Z","dependency_job_id":null,"html_url":"https://github.com/onnx/keras-onnx","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/onnx/keras-onnx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onnx%2Fkeras-onnx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onnx%2Fkeras-onnx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onnx%2Fkeras-onnx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onnx%2Fkeras-onnx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onnx","download_url":"https://codeload.github.com/onnx/keras-onnx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onnx%2Fkeras-onnx/sbom","scorecard":{"id":707566,"data":{"date":"2025-08-11","repo":{"name":"github.com/onnx/keras-onnx","commit":"3b6da290c21bbbbf418577f3e2c528986a2965c5"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"21 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2018-34 / GHSA-2fc2-6r4j-p65h","Warn: Project is vulnerable to: PYSEC-2021-856 / GHSA-5545-2q6w-2gh6","Warn: Project is vulnerable to: PYSEC-2019-108 / GHSA-9fq2-x9r6-wfmf","Warn: Project is vulnerable to: PYSEC-2018-33 / GHSA-cw6w-4rcx-xphc","Warn: Project is vulnerable to: PYSEC-2021-857 / GHSA-f7c7-j99h-c22f","Warn: Project is vulnerable to: GHSA-fpfv-jqm9-f5jm","Warn: Project is vulnerable to: PYSEC-2017-1 / GHSA-frgw-fgh6-9g52","Warn: Project is vulnerable to: GHSA-6rq9-53c3-f7vj","Warn: Project is vulnerable to: PYSEC-2023-38 / GHSA-ffxj-547x-5j7c","Warn: Project is vulnerable to: PYSEC-2025-10 / GHSA-h36j-8vv3-cj52","Warn: Project is vulnerable to: PYSEC-2024-223 / GHSA-h8wv-9h96-m4hr","Warn: Project is vulnerable to: PYSEC-2024-222 / GHSA-whh8-fjgc-qp73","Warn: Project is vulnerable to: PYSEC-2022-48 / GHSA-77rm-9x9h-xj3g","Warn: Project is vulnerable to: GHSA-8gq9-2x98-w8hf","Warn: Project is vulnerable to: GHSA-8qvm-5x2c-j2w7","Warn: Project is vulnerable to: PYSEC-2017-65 / GHSA-jwvw-v7c5-m82h","Warn: Project is vulnerable to: PYSEC-2014-14 / GHSA-652x-xj99-gmcc","Warn: Project is vulnerable to: GHSA-9hjg-9r4m-mvj7","Warn: Project is vulnerable to: GHSA-9wx4-h78v-vm56","Warn: Project is vulnerable to: PYSEC-2014-13 / GHSA-cfj3-7x9c-4p3h","Warn: Project is vulnerable to: PYSEC-2018-28 / GHSA-x84v-xcm2-53pg"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T07:08:21.557Z","repository_id":47176589,"created_at":"2025-08-22T07:08:21.557Z","updated_at":"2025-08-22T07:08:21.557Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278585707,"owners_count":26011044,"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":["keras","onnx","subclassing","tensorflow"],"created_at":"2024-09-30T16:08:18.286Z","updated_at":"2025-10-07T04:30:25.156Z","avatar_url":"https://github.com/onnx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--- SPDX-License-Identifier: Apache-2.0 --\u003e\n\n# keras2onnx\n\n\u003cb\u003e\nWe stopped active development of keras2onnx and keras2onnx is now frozen to tf-2.3 and onnx-1.10.\n\nTo convert your Keras models you can head over to [tf2onnx](https://github.com/onnx/tensorflow-onnx) which can convert Tensorflow, Keras, Tflite and Tensorflow.js models. All keras2onnx unit tests have been added to the tf2onnx ci pipeline to make sure there are no avoidable regressions. The tf2onnx api [tf2onnx.convert.from_keras()](https://github.com/onnx/tensorflow-onnx#from_keras-tf-20-and-newer) is similar to the keras2onnx api and we hope transition is painless.\n\nYou can find a simple tutorial how to convert keras models using tf2onnx [here](https://github.com/onnx/tensorflow-onnx/blob/master/tutorials/keras-resnet50.ipynb).\n\nIf you run into issue or need help with the transition, please open issue against tf2onnx [here](https://github.com/onnx/tensorflow-onnx/issues).\n\u003c/b\u003e\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\n\n|          | Linux | Windows |\n|----------|-------|---------|\n| keras.io | [![Build Status](https://dev.azure.com/onnxmltools/ketone/_apis/build/status/linux-conda-ci?branchName=master)](https://dev.azure.com/onnxmltools/ketone/_build/latest?definitionId=9\u0026branchName=master) | [![Build Status](https://dev.azure.com/onnxmltools/ketone/_apis/build/status/win32-conda-ci?branchName=master)](https://dev.azure.com/onnxmltools/ketone/_build/latest?definitionId=10\u0026branchName=master) |\n| tf.keras | [![Build Status](https://dev.azure.com/onnxmltools/ketone/_apis/build/status/linux-tf-keras-ci?branchName=master)](https://dev.azure.com/onnxmltools/ketone/_build/latest?definitionId=19\u0026branchName=master) | [![Build Status](https://dev.azure.com/onnxmltools/ketone/_apis/build/status/win32-tf-keras-CI?branchName=master)](https://dev.azure.com/onnxmltools/ketone/_build/latest?definitionId=20\u0026branchName=master) |\n\n\n# Introduction\nThe keras2onnx model converter enables users to convert Keras models into the [ONNX](https://onnx.ai) model format.\nInitially, the Keras converter was developed in the project [onnxmltools](https://github.com/onnx/onnxmltools). keras2onnx converter development was moved into an [independent repository](https://github.com/onnx/keras-onnx) to support more kinds of Keras models and reduce the complexity of mixing multiple converters.\n\nMost of the common Keras layers have been supported for conversion. Please refer to the [Keras documentation](https://keras.io/layers/about-keras-layers/) or [tf.keras docs](https://www.tensorflow.org/api_docs/python/tf/keras/layers) for details on Keras layers.\n\nWindows Machine Learning (WinML) users can use [WinMLTools](https://docs.microsoft.com/en-us/windows/ai/windows-ml/convert-model-winmltools) which wrap its call on keras2onnx to convert the Keras models. If you want to use the keras2onnx converter, please refer to the [WinML Release Notes](https://docs.microsoft.com/en-us/windows/ai/windows-ml/release-notes) to identify the corresponding ONNX opset number for your WinML version.\n\nkeras2onnx has been tested on **Python 3.5 - 3.8**, with **tensorflow 1.x/2.0 - 2.2**  (CI build). It does not support **Python 2.x**.\n\n# Install\nYou can install latest release of Keras2ONNX from PyPi:\n\n```\npip install keras2onnx\n```\nor install from source:\n\n```\npip install -U git+https://github.com/microsoft/onnxconverter-common\npip install -U git+https://github.com/onnx/keras-onnx\n```\nBefore running the converter, please notice that tensorflow has to be installed in your python environment,\nyou can choose **tensorflow**/**tensorflow-cpu** package(CPU version) or **tensorflow-gpu**(GPU version)\n\n# Notes\nKeras2ONNX supports the new Keras subclassing model which was introduced in tensorflow 2.0 since the version **1.6.5**. Some typical subclassing models like [huggingface/transformers](https://github.com/huggingface/transformers) have been converted into ONNX and validated by ONNXRuntime.\u003cbr\u003e\n\nSince its version 2.3, the [multi-backend Keras (keras.io)](https://keras.io/#multi-backend-keras-and-tfkeras) stops the support of the tensorflow version above 2.0. The auther suggests to switch to tf.keras for the new features.\n## Multi-backend Keras and tf.keras:\nBoth Keras model types are now supported in the keras2onnx converter. If in the user python env, Keras package was installed from [Keras.io](https://keras.io/) and tensorflow package version is 1.x, the converter converts the model as it was created by the keras.io package. Otherwise, it will convert it through [tf.keras](https://www.tensorflow.org/guide/keras).\u003cbr\u003e\n\nIf you want to override this behaviour, please specify the environment variable TF_KERAS=1 before invoking the converter python API.\n# Development\nKeras2ONNX depends on [onnxconverter-common](https://github.com/microsoft/onnxconverter-common). In practice, the latest code of this converter requires the latest version of onnxconverter-common, so if you install this converter from its source code, please install the onnxconverter-common in source code mode before keras2onnx installation.\n\n# Validated pre-trained Keras models\nMost Keras models could be converted successfully by calling ```keras2onnx.convert_keras```, including CV, GAN, NLP, Speech and etc. See the tutorial [here](https://github.com/onnx/keras-onnx/tree/master/tutorial). However some models with a lot of custom operations need custom conversion, the following are some examples,\nlike [YOLOv3](https://github.com/qqwweee/keras-yolo3), and [Mask RCNN](https://github.com/matterport/Mask_RCNN).\n\n\n## Scripts\nIt will be useful to convert the models from Keras to ONNX from a python script.\nYou can use the following API:\n```\nimport keras2onnx\nkeras2onnx.convert_keras(model, name=None, doc_string='', target_opset=None, channel_first_inputs=None):\n    # type: (keras.Model, str, str, int, []) -\u003e onnx.ModelProto\n    \"\"\"\n    :param model: keras model\n    :param name: the converted onnx model internal name\n    :param doc_string:\n    :param target_opset:\n    :param channel_first_inputs: A list of channel first input.\n    :return:\n    \"\"\"\n```\n\nUse the following script to convert keras application models to onnx, and then perform inference:\n```\nimport numpy as np\nfrom keras.preprocessing import image\nfrom keras.applications.resnet50 import preprocess_input\nimport keras2onnx\nimport onnxruntime\n\n# image preprocessing\nimg_path = 'street.jpg'   # make sure the image is in img_path\nimg_size = 224\nimg = image.load_img(img_path, target_size=(img_size, img_size))\nx = image.img_to_array(img)\nx = np.expand_dims(x, axis=0)\nx = preprocess_input(x)\n\n# load keras model\nfrom keras.applications.resnet50 import ResNet50\nmodel = ResNet50(include_top=True, weights='imagenet')\n\n# convert to onnx model\nonnx_model = keras2onnx.convert_keras(model, model.name)\n\n# runtime prediction\ncontent = onnx_model.SerializeToString()\nsess = onnxruntime.InferenceSession(content)\nx = x if isinstance(x, list) else [x]\nfeed = dict([(input.name, x[n]) for n, input in enumerate(sess.get_inputs())])\npred_onnx = sess.run(None, feed)\n```\n\nThe inference result is a list which aligns with keras model prediction result `model.predict()`.\nAn alternative way to load onnx model to runtime session is to save the model first:\n```\ntemp_model_file = 'model.onnx'\nkeras2onnx.save_model(onnx_model, temp_model_file)\nsess = onnxruntime.InferenceSession(temp_model_file)\n```\n\n## Contribute\nWe welcome contributions in the form of feedback, ideas, or code.\n\n## License\n[Apache License v2.0](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonnx%2Fkeras-onnx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonnx%2Fkeras-onnx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonnx%2Fkeras-onnx/lists"}