{"library":"onnx2tf","title":"ONNX to TensorFlow/TFLite Converter","description":"onnx2tf is a versatile Python tool designed for converting ONNX model files into various target formats, including LiteRT, TFLite, TensorFlow SavedModel, PyTorch native code (nn.Module), TorchScript (.pt), state_dict (.pt), Exported Program (.pt2), and Dynamo ONNX. It also supports direct conversion from LiteRT to PyTorch. The library maintains a rapid release cadence, with version 2.4.0 being the latest stable release.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install onnx2tf"],"cli":{"name":"onnx2tf","version":""}},"imports":["import onnx2tf\n\n# ... then onnx2tf.convert(...)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import onnx2tf\nimport torch\nimport torch.nn as nn\nimport os\n\n# 1. Define a simple PyTorch model\nclass SimpleModel(nn.Module):\n    def __init__(self):\n        super(SimpleModel, self).__init__()\n        self.conv = nn.Conv2d(3, 16, 3, 1, 1)\n\n    def forward(self, x):\n        return self.conv(x)\n\n# 2. Instantiate and export to ONNX\nmodel = SimpleModel()\ndummy_input = torch.randn(1, 3, 224, 224)\nonnx_file_path = \"simple_model.onnx\"\ntorch.onnx.export(\n    model,\n    dummy_input,\n    onnx_file_path,\n    opset_version=17,\n    input_names=[\"input\"],\n    output_names=[\"output\"],\n    dynamic_axes={\"input\": {0: \"batch_size\"}, \"output\": {0: \"batch_size\"}}\n)\nprint(f\"PyTorch model exported to {onnx_file_path}\")\n\n# 3. Convert ONNX to TensorFlow SavedModel\noutput_folder = \"./converted_tf_model\"\nos.makedirs(output_folder, exist_ok=True)\n\nonnx2tf.convert(\n    input_onnx_file_path=onnx_file_path,\n    output_folder_path=output_folder,\n    # For TFLite conversion, you might add:\n    # tflite_output_file_path=\"./converted_tf_model/model.tflite\"\n)\nprint(f\"ONNX model converted to TensorFlow SavedModel at {output_folder}\")\n\n# Clean up generated ONNX file\nos.remove(onnx_file_path)\n\n# To use a specific backend for TFLite (e.g., the deprecated tf_converter):\n# onnx2tf.convert(\n#     input_onnx_file_path=onnx_file_path,\n#     output_folder_path=\"./converted_tf_model_tfconv\",\n#     tflite_output_file_path=\"./converted_tf_model_tfconv/model.tflite\",\n#     tflite_backend='tf_converter'\n# )","lang":"python","description":"This quickstart demonstrates the end-to-end process of defining a simple PyTorch model, exporting it to ONNX format, and then using `onnx2tf` to convert the ONNX model into a TensorFlow SavedModel. It highlights the primary `onnx2tf.convert()` function and the necessary input/output paths.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"1.20.0","pypi_latest":"2.4.0","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":70,"avg_install_s":30.6,"avg_import_s":7.33,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"onnx2tf","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"onnx2tf","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":50.3,"import_time_s":8.85,"mem_mb":118.7,"disk_size":"2.5G"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"onnx2tf","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"24.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"onnx2tf","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":49.8,"import_time_s":13.12,"mem_mb":132.2,"disk_size":"2.5G"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"onnx2tf","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"15.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"onnx2tf","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":19.9,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"618M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"onnx2tf","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"onnx2tf","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":6.9,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"onnx2tf","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"20.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"onnx2tf","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.3,"import_time_s":null,"mem_mb":null,"disk_size":"21M"}]}}