onnx2pytorch


Nameonnx2pytorch JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://github.com/ToriML/onnx2pytorch
SummaryLibrary to transform onnx model to pytorch.
upload_time2024-11-13 09:12:23
maintainerNone
docs_urlNone
authorTalmaj Marinc
requires_python>=3.6
licenseapache-2.0
keywords
VCS
bugtrack_url
requirements pytest pre-commit torch torchvision onnx onnxruntime numpy
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ONNX to PyTorch
![PyPI - License](https://img.shields.io/pypi/l/onnx2pytorch?color)
[![Lint and Test](https://github.com/Talmaj/onnx2pytorch/actions/workflows/lint_and_test.yml/badge.svg)](https://github.com/Talmaj/onnx2pytorch/actions/workflows/lint_and_test.yml)
[![Downloads](https://pepy.tech/badge/onnx2pytorch)](https://pepy.tech/project/onnx2pytorch)
![PyPI](https://img.shields.io/pypi/v/onnx2pytorch)

A library to transform ONNX model to PyTorch. This library enables use of PyTorch 
backend and all of its great features for manipulation of neural networks.

## Installation
```pip install onnx2pytorch```

## Usage
```
import onnx
from onnx2pytorch import ConvertModel

onnx_model = onnx.load(path_to_onnx_model)
pytorch_model = ConvertModel(onnx_model)
```

Currently supported and tested models from [onnx_zoo](https://github.com/onnx/models):
- [MobileNet](https://github.com/onnx/models/tree/master/vision/classification/mobilenet)
- [ResNet](https://github.com/onnx/models/tree/master/vision/classification/resnet)
- [ShuffleNet_V2](https://github.com/onnx/models/tree/master/vision/classification/shufflenet)
- [BERT-Squad](https://github.com/onnx/models/tree/master/text/machine_comprehension/bert-squad)
- [EfficientNet-Lite4](https://github.com/onnx/models/tree/master/vision/classification/efficientnet-lite4)
- [Fast Neural Style Transfer](https://github.com/onnx/models/tree/master/vision/style_transfer/fast_neural_style)
- [Super Resolution](https://github.com/onnx/models/tree/master/vision/super_resolution/sub_pixel_cnn_2016)
- [YOLOv4](https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/yolov4)
  (Not exactly the same, nearest neighbour interpolation in pytorch differs)
- [U-net](https://pytorch.org/hub/mateuszbuda_brain-segmentation-pytorch_unet/)
  (Converted from pytorch to onnx and then back)

## Limitations
Known current version limitations are:
- `batch_size > 1` could deliver unexpected results due to ambiguity of onnx's BatchNorm layer.   
That is why in this case for now we raise an assertion error.  
Set `experimental=True` in `ConvertModel` to be able to use `batch_size > 1`.
- Fine tuning and training of converted models was not tested yet, only inference.

## Development
### Dependency installation
```pip install -r requirements.txt```

From onnxruntime>=1.5.0 you need to add the 
following to your .bashrc or .zshrc if you are running OSx:
```export KMP_DUPLICATE_LIB_OK=True```

### Code formatting
The Uncompromising Code Formatter: [Black](https://github.com/psf/black)  
```black {source_file_or_directory}```  

Install it into pre-commit hook to always commit nicely formatted code:  
```pre-commit install```

### Testing
[Pytest](https://docs.pytest.org/en/latest/) and [tox](https://tox.readthedocs.io/en/latest/).  
```tox```
#### Test fixtures
To test the complete conversion of an onnx model download pre-trained models: 
```./download_fixtures.sh```  
Use flag `--all` to download more models.
Add any custom models to `./fixtures` folder to test their conversion.

### Debugging
Set `ConvertModel(..., debug=True)` to compare each converted
activation from pytorch with the activation from onnxruntime.  
This helps identify where in the graph the activations start to differ.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ToriML/onnx2pytorch",
    "name": "onnx2pytorch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Talmaj Marinc",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/66/85/ff182f63c81419607182184d4dc7da3bbfc244dcdef3ac4aea2f1ab6b1a0/onnx2pytorch-0.5.1.tar.gz",
    "platform": null,
    "description": "# ONNX to PyTorch\n![PyPI - License](https://img.shields.io/pypi/l/onnx2pytorch?color)\n[![Lint and Test](https://github.com/Talmaj/onnx2pytorch/actions/workflows/lint_and_test.yml/badge.svg)](https://github.com/Talmaj/onnx2pytorch/actions/workflows/lint_and_test.yml)\n[![Downloads](https://pepy.tech/badge/onnx2pytorch)](https://pepy.tech/project/onnx2pytorch)\n![PyPI](https://img.shields.io/pypi/v/onnx2pytorch)\n\nA library to transform ONNX model to PyTorch. This library enables use of PyTorch \nbackend and all of its great features for manipulation of neural networks.\n\n## Installation\n```pip install onnx2pytorch```\n\n## Usage\n```\nimport onnx\nfrom onnx2pytorch import ConvertModel\n\nonnx_model = onnx.load(path_to_onnx_model)\npytorch_model = ConvertModel(onnx_model)\n```\n\nCurrently supported and tested models from [onnx_zoo](https://github.com/onnx/models):\n- [MobileNet](https://github.com/onnx/models/tree/master/vision/classification/mobilenet)\n- [ResNet](https://github.com/onnx/models/tree/master/vision/classification/resnet)\n- [ShuffleNet_V2](https://github.com/onnx/models/tree/master/vision/classification/shufflenet)\n- [BERT-Squad](https://github.com/onnx/models/tree/master/text/machine_comprehension/bert-squad)\n- [EfficientNet-Lite4](https://github.com/onnx/models/tree/master/vision/classification/efficientnet-lite4)\n- [Fast Neural Style Transfer](https://github.com/onnx/models/tree/master/vision/style_transfer/fast_neural_style)\n- [Super Resolution](https://github.com/onnx/models/tree/master/vision/super_resolution/sub_pixel_cnn_2016)\n- [YOLOv4](https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/yolov4)\n  (Not exactly the same, nearest neighbour interpolation in pytorch differs)\n- [U-net](https://pytorch.org/hub/mateuszbuda_brain-segmentation-pytorch_unet/)\n  (Converted from pytorch to onnx and then back)\n\n## Limitations\nKnown current version limitations are:\n- `batch_size > 1` could deliver unexpected results due to ambiguity of onnx's BatchNorm layer.   \nThat is why in this case for now we raise an assertion error.  \nSet `experimental=True` in `ConvertModel` to be able to use `batch_size > 1`.\n- Fine tuning and training of converted models was not tested yet, only inference.\n\n## Development\n### Dependency installation\n```pip install -r requirements.txt```\n\nFrom onnxruntime>=1.5.0 you need to add the \nfollowing to your .bashrc or .zshrc if you are running OSx:\n```export KMP_DUPLICATE_LIB_OK=True```\n\n### Code formatting\nThe Uncompromising Code Formatter: [Black](https://github.com/psf/black)  \n```black {source_file_or_directory}```  \n\nInstall it into pre-commit hook to always commit nicely formatted code:  \n```pre-commit install```\n\n### Testing\n[Pytest](https://docs.pytest.org/en/latest/) and [tox](https://tox.readthedocs.io/en/latest/).  \n```tox```\n#### Test fixtures\nTo test the complete conversion of an onnx model download pre-trained models: \n```./download_fixtures.sh```  \nUse flag `--all` to download more models.\nAdd any custom models to `./fixtures` folder to test their conversion.\n\n### Debugging\nSet `ConvertModel(..., debug=True)` to compare each converted\nactivation from pytorch with the activation from onnxruntime.  \nThis helps identify where in the graph the activations start to differ.\n",
    "bugtrack_url": null,
    "license": "apache-2.0",
    "summary": "Library to transform onnx model to pytorch.",
    "version": "0.5.1",
    "project_urls": {
        "Homepage": "https://github.com/ToriML/onnx2pytorch"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9784ef57a569ba57f4291d2dc918f863efa6ea56a944ab55677226eade2ea8d9",
                "md5": "317b5afe577ed973ee9fa08b6e8ca273",
                "sha256": "9fffda1c0c0d2eca5a54bffd2dea859ebe5be1ce22ed01981ae9d97b50385bcb"
            },
            "downloads": -1,
            "filename": "onnx2pytorch-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "317b5afe577ed973ee9fa08b6e8ca273",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 46505,
            "upload_time": "2024-11-13T09:12:21",
            "upload_time_iso_8601": "2024-11-13T09:12:21.383792Z",
            "url": "https://files.pythonhosted.org/packages/97/84/ef57a569ba57f4291d2dc918f863efa6ea56a944ab55677226eade2ea8d9/onnx2pytorch-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6685ff182f63c81419607182184d4dc7da3bbfc244dcdef3ac4aea2f1ab6b1a0",
                "md5": "3942c3b214bbd75c8ff453645013a2de",
                "sha256": "5c3ddf004838e67793817751affb426d77955290e473b492a058fc6edcee8d14"
            },
            "downloads": -1,
            "filename": "onnx2pytorch-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3942c3b214bbd75c8ff453645013a2de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 33361,
            "upload_time": "2024-11-13T09:12:23",
            "upload_time_iso_8601": "2024-11-13T09:12:23.317504Z",
            "url": "https://files.pythonhosted.org/packages/66/85/ff182f63c81419607182184d4dc7da3bbfc244dcdef3ac4aea2f1ab6b1a0/onnx2pytorch-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-13 09:12:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ToriML",
    "github_project": "onnx2pytorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "5.4.1"
                ]
            ]
        },
        {
            "name": "pre-commit",
            "specs": [
                [
                    ">=",
                    "2.2.0"
                ]
            ]
        },
        {
            "name": "torch",
            "specs": [
                [
                    ">=",
                    "1.4.0"
                ]
            ]
        },
        {
            "name": "torchvision",
            "specs": [
                [
                    ">=",
                    "0.9.0"
                ]
            ]
        },
        {
            "name": "onnx",
            "specs": [
                [
                    ">=",
                    "1.6.0"
                ]
            ]
        },
        {
            "name": "onnxruntime",
            "specs": [
                [
                    ">=",
                    "1.5.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.18.1"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "onnx2pytorch"
}
        
Elapsed time: 0.40649s