{"id":19412713,"url":"https://github.com/tensorlayer/tlx2onnx","last_synced_at":"2025-04-24T11:31:26.347Z","repository":{"id":37340984,"uuid":"481428550","full_name":"tensorlayer/TLX2ONNX","owner":"tensorlayer","description":"ONNX Model Exporter for TensorLayerX","archived":false,"fork":false,"pushed_at":"2022-09-19T07:08:59.000Z","size":182,"stargazers_count":21,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-14T06:45:12.745Z","etag":null,"topics":["deep-learning","mindspore","neural-network","onnx","onnxruntime","paddlepaddle","python","pytorch","tensorflow","tensorlayerx"],"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/tensorlayer.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":"2022-04-14T01:36:17.000Z","updated_at":"2024-01-04T17:07:47.000Z","dependencies_parsed_at":"2022-07-13T13:50:35.945Z","dependency_job_id":null,"html_url":"https://github.com/tensorlayer/TLX2ONNX","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorlayer%2FTLX2ONNX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorlayer%2FTLX2ONNX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorlayer%2FTLX2ONNX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorlayer%2FTLX2ONNX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tensorlayer","download_url":"https://codeload.github.com/tensorlayer/TLX2ONNX/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223951893,"owners_count":17230783,"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","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","mindspore","neural-network","onnx","onnxruntime","paddlepaddle","python","pytorch","tensorflow","tensorlayerx"],"created_at":"2024-11-10T12:27:56.344Z","updated_at":"2024-11-10T12:27:56.968Z","avatar_url":"https://github.com/tensorlayer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TLX2ONNX\nONNX Model Exporter for TensorLayerX. It's updated on Both [OpenI](https://git.openi.org.cn/OpenI/TLX2ONNX) and [Github](https://github.com/tensorlayer/TLX2ONNX/). You can get a [free GPU](https://git.openi.org.cn/OpenI/TLX2ONNX/debugjob?debugListType=all) on OpenI to use this project.\n\n## Introduction\n\nTLX2ONNX enables users to convert models from TensorLayerX to ONNX.\n\n- Supported operators. TLX2ONNX can stably export models to ONNX Opset 9~11, and partialy support lower version opset. More details please refer to [Operator list](OP_LIST.md).\n- Supported Layers. You can find officially verified Layers by TLX2ONNX/tests in [TLX2ONNX/test](https://github.com/tensorlayer/TLX2ONNX/tree/main/tests).\n\n## Installation\n\n#### Via Pip\n```bash\npip install tlx2onnx\n```\n \n#### From Source\n```bash\n git clone https://github.com/tensorlayer/TLX2ONNX.git\n cd TLX2ONNX\n python setup.py install\n```\n\n## Usage\nTLX2ONNX can convert models built using TensorLayerX Module Subclass and Layers, and the Layers support list can be found in [Operator list](OP_LIST.md).\n\nThe following is an example of converting a multi-layer perceptron. You can get the code from [here](https://github.com/tensorlayer/TLX2ONNX/tree/main/tests/test_merge.py).\n```python\nimport os\nos.environ[\"TL_BACKEND\"] = 'tensorflow'\nimport tensorlayerx as tlx\nfrom tensorlayerx.nn import Module\nfrom tensorlayerx.nn import Linear, Concat, Elementwise\nfrom tlx2onnx.main import export\nimport onnxruntime as rt\nimport numpy as np\n\nclass CustomModel(Module):\n    def __init__(self):\n        super(CustomModel, self).__init__(name=\"custom\")\n        self.linear1 = Linear(in_features=20, out_features=10, act=tlx.ReLU, name='relu1_1')\n        self.linear2 = Linear(in_features=20, out_features=10, act=tlx.ReLU, name='relu2_1')\n        self.concat = Concat(concat_dim=1, name='concat_layer')\n\n    def forward(self, inputs):\n        d1 = self.linear1(inputs)\n        d2 = self.linear2(inputs)\n        outputs = self.concat([d1, d2])\n        return outputs\n\nnet = CustomModel()\ninput = tlx.nn.Input(shape=(3, 20), init=tlx.initializers.RandomNormal())\nnet.set_eval()\noutput = net(input)\nprint(\"tlx out\", output)\nonnx_model = export(net, input_spec=input, path='concat.onnx')\n\n# Infer Model\nsess = rt.InferenceSession('concat.onnx')\ninput_name = sess.get_inputs()[0].name\noutput_name = sess.get_outputs()[0].name\ninput_data = np.array(input, dtype=np.float32)\nresult = sess.run([output_name], {input_name: input_data})\nprint('onnx out', result)\n```\nThe converted onnx file can be viewed via [Netron](https://github.com/lutzroeder/netron).\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://git.openi.org.cn/laich/pose_data/raw/commit/7ac74f03dbfdd8e023cdb205cd415a8571ebb91a/onnxfile.png\" width=\"580\"\\\u003e\u003c/p\u003e\n\n\nThe converted results have almost no loss of accuracy. \nAnd the graph show the input and output sizes of each layer, which is very helpful for checking the model.\n\n\n# Citation\n\nIf you find TensorLayerX or TLX2ONNX useful for your project, please cite the following papers：\n\n```\n@article{tensorlayer2017,\n    author  = {Dong, Hao and Supratak, Akara and Mai, Luo and Liu, Fangde and Oehmichen, Axel and Yu, Simiao and Guo, Yike},\n    journal = {ACM Multimedia},\n    title   = {{TensorLayer: A Versatile Library for Efficient Deep Learning Development}},\n    url     = {http://tensorlayer.org},\n    year    = {2017}\n}\n\n@inproceedings{tensorlayer2021,\n  title={TensorLayer 3.0: A Deep Learning Library Compatible With Multiple Backends},\n  author={Lai, Cheng and Han, Jiarong and Dong, Hao},\n  booktitle={2021 IEEE International Conference on Multimedia \\\u0026 Expo Workshops (ICMEW)},\n  pages={1--3},\n  year={2021},\n  organization={IEEE}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorlayer%2Ftlx2onnx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftensorlayer%2Ftlx2onnx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorlayer%2Ftlx2onnx/lists"}