{ "info": { "author": "Grigory Malivenko", "author_email": "nerox8664@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# gluon2pytorch\n\n[![Build Status](https://travis-ci.com/nerox8664/gluon2pytorch.svg?branch=master)](https://travis-ci.com/nerox8664/gluon2pytorch)\n[![GitHub License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Python Version](https://img.shields.io/badge/python-2.7%2C3.6-lightgrey.svg)](https://github.com/nerox8664/gluon2pytorch)\n[![Readthedocs](https://img.shields.io/readthedocs/gluon2pytorch.svg)](https://gluon2pytorch.readthedocs.io/en/latest/)\n\nGluon to PyTorch model convertor with script generation.\n\n## Installation\n\n```\ngit clone https://github.com/nerox8664/gluon2pytorch\ncd gluon2pytorch\npip install -e . \n```\n\nor you can use `pip`:\n\n```\npip install gluon2pytorch\n```\n\n## How to use\n\nIt's the convertor of Gluon graph to a Pytorch model file + weights.\n\nFirstly, we need to load (or create) Gluon Hybrid model:\n\n```\n\nclass ReLUTest(mx.gluon.nn.HybridSequential):\n def __init__(self):\n super(ReLUTest, self).__init__()\n from mxnet.gluon import nn\n with self.name_scope():\n self.conv1 = nn.Conv2D(3, 32)\n self.relu = nn.Activation('relu')\n\n def hybrid_forward(self, F, x):\n x = F.relu(self.relu(self.conv1(x)))\n return x\n\n\nif __name__ == '__main__':\n net = ReLUTest()\n \n # Make sure it's hybrid and initialized\n net.hybridize()\n net.collect_params().initialize()\n\n```\n\nThe next step - call the converter:\n\n```\n pytorch_model = gluon2pytorch(net, [(1, 3, 224, 224)], dst_dir=None, pytorch_module_name='ReLUTest')\n```\n\nFinally, we can check the difference\n\n```\n input_np = np.random.uniform(-1, 1, (1, 3, 224, 224))\n\n gluon_output = net(mx.nd.array(input_np))\n pytorch_output = pytorch_model(torch.FloatTensor(input_np))\n check_error(gluon_output, pytorch_output)\n```\n\n## Supported layers\n\nLayers:\n\n* Linear\n* Conv2d\n* ConvTranspose2d (Deconvolution)\n* MaxPool2d\n* AvgPool2d\n* Global average pooling (as special case of AdaptiveAvgPool2d)\n* BatchNorm2d* \n* Padding2d (constant, reflection, replication)\n\nReshape:\n\n* Flatten\n\nActivations:\n\n* ReLU\n* LeakyReLU\n* Sigmoid\n* Softmax\n* SELU\n\nElement-wise:\n\n* Addition\n* Concatenation\n* Subtraction\n* Multiplication\n\nMisc:\n\n* clamp\n* BilinearResize2D\n* LRN\n\n\n## Classification models converted with gluon2pytorch\n\n\n| Model | Top1 | Top5 | Params | FLOPs | Source weights | Remarks |\n| --- | ---: | ---: | ---: | ---: | ---: | ---: |\n| ResNet-10 | 37.09 | 15.55 | 5,418,792 | 892.62M | osmr's repo | Success |\n| ResNet-12 | 35.86 | 14.46 | 5,492,776 | 1,124.23M | osmr's repo | Success |\n| ResNet-14 | 32.85 | 12.41 | 5,788,200 | 1,355.64M | osmr's repo | Success |\n| ResNet-16 | 30.68 | 11.10 | 6,968,872 | 1,586.95M | osmr's repo | Success |\n| ResNet-18 x0.25 | 49.16 | 24.45 | 831,096 | 136.64M | osmr's repo | Success |\n| ResNet-18 x0.5 | 36.54 | 14.96 | 3,055,880 | 485.22M | osmr's repo | Success |\n| ResNet-18 x0.75 | 33.25 | 12.54 | 6,675,352 | 1,045.75M | osmr's repo | Success |\n| ResNet-18 | 29.13 | 9.94 | 11,689,512 | 1,818.21M | osmr's repo | Success |\n| ResNet-34 | 25.34 | 7.92 | 21,797,672 | 3,669.16M | osmr's repo | Success |\n| ResNet-50 | 23.50 | 6.87 | 25,557,032 | 3,868.96M | osmr's repo | Success |\n| ResNet-50b | 22.92 | 6.44 | 25,557,032 | 4,100.70M | osmr's repo | Success |\n| ResNet-101 | 21.66 | 5.99 | 44,549,160 | 7,586.30M | osmr's repo | Success |\n| ResNet-101b | 21.18 | 5.60 | 44,549,160 | 7,818.04M | osmr's repo | Success |\n| ResNet-152 | 21.01 | 5.61 | 60,192,808 | 11,304.85M | osmr's repo | Success |\n| ResNet-152b | 20.54 | 5.37 | 60,192,808 | 11,536.58M | osmr's repo | Success |\n| PreResNet-18 | 28.72 | 9.88 | 11,687,848 | 1,818.41M | osmr's repo | Success |\n| PreResNet-34 | 25.88 | 8.11 | 21,796,008 | 3,669.36M | osmr's repo | Success |\n| PreResNet-50 | 23.39 | 6.68 | 25,549,480 | 3,869.16M | osmr's repo | Success |\n| PreResNet-50b | 23.16 | 6.64 | 25,549,480 | 4,100.90M | osmr's repo | Success |\n| PreResNet-101 | 21.45 | 5.75 | 44,541,608 | 7,586.50M | osmr's repo | Success |\n| PreResNet-101b | 21.73 | 5.88 | 44,541,608 | 7,818.24M | osmr's repo | Success |\n| PreResNet-152 | 20.70 | 5.32 | 60,185,256 | 11,305.05M | osmr's repo | Success |\n| PreResNet-152b | 21.00 | 5.75 | 60,185,256 | 11,536.78M | Gluon Model Zoo| Success |\n| PreResNet-200b | 21.10 | 5.64 | 64,666,280 | 15,040.27M | tornadomeet/ResNet | Success |\n| ResNeXt-101 (32x4d) | 21.32 | 5.79 | 44,177,704 | 7,991.62M | Cadene's repo | Success |\n| ResNeXt-101 (64x4d) | 20.60 | 5.41 | 83,455,272 | 15,491.88M | Cadene's repo | Success |\n| SE-ResNet-50 | 22.51 | 6.44 | 28,088,024 | 3,877.01M | Cadene's repo | Success |\n| SE-ResNet-101 | 21.92 | 5.89 | 49,326,872 | 7,600.01M | Cadene's repo | Success |\n| SE-ResNet-152 | 21.48 | 5.77 | 66,821,848 | 11,324.62M | Cadene's repo | Success |\n| SE-ResNeXt-50 (32x4d) | 21.06 | 5.58 | 27,559,896 | 4,253.33M | Cadene's repo | Success |\n| SE-ResNeXt-101 (32x4d) | 19.99 | 5.00 | 48,955,416 | 8,005.33M | Cadene's repo | Success |\n| SENet-154 | 18.84 | 4.65 | 115,088,984 | 20,742.40M | Cadene's repo | Success |\n| DenseNet-121 | 25.11 | 7.80 | 7,978,856 | 2,852.39M | Gluon Model Zoo| Success |\n| DenseNet-161 | 22.40 | 6.18 | 28,681,000 | 7,761.25M | Gluon Model Zoo| Success |\n| DenseNet-169 | 23.89 | 6.89 | 14,149,480 | 3,381.48M | Gluon Model Zoo| Success |\n| DenseNet-201 | 22.71 | 6.36 | 20,013,928 | 4,318.75M | Gluon Model Zoo| Success |\n| DPN-68 | 23.57 | 7.00 | 12,611,602 | 2,338.71M | Cadene's repo | Success |\n| DPN-98 | 20.23 | 5.28 | 61,570,728 | 11,702.80M | Cadene's repo | Success |\n| DPN-131 | 20.03 | 5.22 | 79,254,504 | 16,056.22M | Cadene's repo | Success |\n| DarkNet Tiny | 40.31 | 17.46 | 1,042,104 | 496.34M | osmr's repo | Success |\n| DarkNet Ref | 38.00 | 16.68 | 7,319,416 | 365.55M | osmr's repo | Success |\n| SqueezeNet v1.0 | 40.97 | 18.96 | 1,248,424 | 828.30M | osmr's repo | Success |\n| SqueezeNet v1.1 | 39.09 | 17.39 | 1,235,496 | 354.88M | osmr's repo | Success |\n| SqueezeResNet v1.1 | 39.83 | 17.84 | 1,235,496 | 354.88M | osmr's repo | Success |\n| ShuffleNetV2 x0.5 | 40.61 | 18.30 | 1,366,792 | 42.34M | osmr's repo | Success |\n| ShuffleNetV2c x0.5 | 39.87 | 18.11 | 1,366,792 | 42.37M | tensorpack/tensorpack | Success |\n| ShuffleNetV2 x1.0 | 33.76 | 13.22 | 2,278,604 | 147.92M | osmr's repo | Success |\n| ShuffleNetV2c x1.0 | 30.74 | 11.38 | 2,279,760 | 148.85M | tensorpack/tensorpack | Success |\n| ShuffleNetV2 x1.5 | 32.38 | 12.37 | 4,406,098 | 318.61M | osmr's repo | Success |\n| ShuffleNetV2 x2.0 | 32.04 | 12.10 | 7,601,686 | 593.66M | osmr's repo | Success |\n| 108-MENet-8x1 (g=3) | 43.62 | 20.30 | 654,516 | 40.64M | osmr's repo | Success |\n| 128-MENet-8x1 (g=4) | 45.80 | 21.93 | 750,796 | 43.58M | clavichord93/MENet | Success |\n| 228-MENet-12x1 (g=3) | 35.03 | 13.99 | 1,806,568 | 148.93M | clavichord93/MENet | Success |\n| 256-MENet-12x1 (g=4) | 34.49 | 13.90 | 1,888,240 | 146.11M | clavichord93/MENet | Success |\n| 348-MENet-12x1 (g=3) | 31.17 | 11.41 | 3,368,128 | 306.31M | clavichord93/MENet | Success |\n| 352-MENet-12x1 (g=8) | 34.70 | 13.75 | 2,272,872 | 151.03M | clavichord93/MENet | Success |\n| 456-MENet-24x1 (g=3) | 29.57 | 10.43 | 5,304,784 | 560.72M | clavichord93/MENet | Success |\n| MobileNet x0.25 | 45.78 | 22.18 | 470,072 | 42.30M | osmr's repo | Success |\n| MobileNet x0.5 | 36.12 | 14.81 | 1,331,592 | 152.04M | osmr's repo | Success |\n| MobileNet x0.75 | 32.71 | 12.28 | 2,585,560 | 329.22M | Gluon Model Zoo| Success |\n| MobileNet x1.0 | 29.25 | 10.03 | 4,231,976 | 573.83M | Gluon Model Zoo| Success |\n| FD-MobileNet x0.25 | 56.19 | 31.38 | 383,160 | 12.44M | osmr's repo | Success |\n| FD-MobileNet x0.5 | 42.62 | 19.69 | 993,928 | 40.93M | osmr's repo | Success |\n| FD-MobileNet x1.0 | 35.95 | 14.72 | 2,901,288 | 146.08M | clavichord93/FD-MobileNet | Success |\n| MobileNetV2 x0.25 | 48.89 | 25.24 | 1,516,392 | 32.22M | Gluon Model Zoo| Success |\n| MobileNetV2 x0.5 | 35.51 | 14.64 | 1,964,736 | 95.62M | Gluon Model Zoo| Success |\n| MobileNetV2 x0.75 | 30.82 | 11.26 | 2,627,592 | 191.61M | Gluon Model Zoo| Success |\n| MobileNetV2 x1.0 | 28.51 | 9.90 | 3,504,960 | 320.19M | Gluon Model Zoo| Success |\n| NASNet-A-Mobile | 25.37 | 7.95 | 5,289,978 | 587.29M | Cadene's repo | Success |\n| InceptionV3 | 21.22 | 5.59 | 23,834,568 | 5,746.72M | Gluon Model Zoo| Success |\n| AirNet50-1x64d (r=2) | 22.48 | 6.21 | 27,425,864 | 4,757.77M | soeaver/AirNet-PyTorch | Success |\n| AirNet50-1x64d (r=16) | 22.91 | 6.46 | 25,714,952 | 4,385.54M | soeaver/AirNet-PyTorch | Success |\n| AirNeXt50-32x4d (r=2) | 20.87 | 5.51 | 27,604,296 | 5,321.18M | soeaver/AirNet-PyTorch | Success |\n| DiracNetV2-18 | 31.47 | 11.70 | 11,511,784 | 1,798.43M | szagoruyko/diracnets | Success |\n| DiracNetV2-34 | 28.75 | 9.93 | 21,616,232 | 3,649.37M | szagoruyko/diracnets | Success |\n| DARTS | 26.70 | 8.74 | 4,718,752 | 537.64M | szagoruyko/diracnets | Success |\n| PolyNet | 19.10 | 4.52 | 95,366,600 | 34,768.84M | Cadene's repo | Success |\n| ZfNet | ? | ? | ? | ? | osmr's repo | Success |\n| FishNet-150 | 22.85 | 6.38 | 24,959,400 | 6,435.02M | osmr's repo | Success |\n\n## Segmentation models converted with gluon2pytorch\n\n\n| Name | Model | pixAcc | mIoU | Source weights | Remarks |\n| --- | ---: | ---: | ---: | ---: | ---: |\n| fcn_resnet101_coco | FCN | 92.2 | 66.2 | Gluon Model Zoo | Success |\n| fcn_resnet101_voc | FCN | N/A | 83.6 | Gluon Model Zoo | Success |\n\n\n## Code snippets\nLook at the `tests` directory.\n\n## License\nThis software is covered by MIT License.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nerox8664/gluon2pytorch", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "gluon2pytorch", "package_url": "https://pypi.org/project/gluon2pytorch/", "platform": "", "project_url": "https://pypi.org/project/gluon2pytorch/", "project_urls": { "Homepage": "https://github.com/nerox8664/gluon2pytorch" }, "release_url": "https://pypi.org/project/gluon2pytorch/0.0.6/", "requires_dist": null, "requires_python": "", "summary": "The deep learning models convertor", "version": "0.0.6" }, "last_serial": 5875873, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d9a2cb454616516d9c6bcf6fa710742e", "sha256": "b0509bf19a02fd0d4a0d324b70cf2ee266c876efba353ba5412eab4b2b9bc116" }, "downloads": -1, "filename": "gluon2pytorch-0.0.1.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "d9a2cb454616516d9c6bcf6fa710742e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9339, "upload_time": "2018-10-31T16:16:35", "url": "https://files.pythonhosted.org/packages/97/9f/c5c44b924909d08b664a41d635ba332c318c4737a1af8573905b2586d3bb/gluon2pytorch-0.0.1.linux-x86_64.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "571c6409d67a2b0df4d9a61bc175bcd4", "sha256": "8f9d78af143892e09a89c46d36c9dd52dfe90b822f664ec8c8e8cedc2428d917" }, "downloads": -1, "filename": "gluon2pytorch-0.0.2.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "571c6409d67a2b0df4d9a61bc175bcd4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12497, "upload_time": "2018-11-07T06:49:33", "url": "https://files.pythonhosted.org/packages/b2/6a/e84aac726082c648cf0407d6d91313916723924c44806c5d18f4d31f47a5/gluon2pytorch-0.0.2.linux-x86_64.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "878f19cabb61c0ceca9356eb668b1281", "sha256": "e32d0fd456934f500d689e9e51ea28dc7d2bee7dd397279be825245221a09aaa" }, "downloads": -1, "filename": "gluon2pytorch-0.0.3.tar.gz", "has_sig": false, "md5_digest": "878f19cabb61c0ceca9356eb668b1281", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10565, "upload_time": "2018-12-13T09:13:14", "url": "https://files.pythonhosted.org/packages/c8/e3/5125650ecfc7c4501a2ce01634a8d06c19589383113a72bc1cc92d6fb58a/gluon2pytorch-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "e355ff7347026b7185c6bb64847cd695", "sha256": "e53b5d3935e7d6c874bf101d05239db2e8d1c7dd00f00f0648f56881bff009d3" }, "downloads": -1, "filename": "gluon2pytorch-0.0.4.tar.gz", "has_sig": false, "md5_digest": "e355ff7347026b7185c6bb64847cd695", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11119, "upload_time": "2019-04-18T10:06:30", "url": "https://files.pythonhosted.org/packages/10/d4/048889d8dd851a122441b7e2bc5145a7ad08ffcaeab21616fec7603feee2/gluon2pytorch-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "ce577d543a6a328c5d54f4bcdfa23e46", "sha256": "bbefe40823267010ee40a85e7ba925247fcfdf0c706b63bdd8e0c1e5ca627621" }, "downloads": -1, "filename": "gluon2pytorch-0.0.5.tar.gz", "has_sig": false, "md5_digest": "ce577d543a6a328c5d54f4bcdfa23e46", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11135, "upload_time": "2019-09-23T19:42:21", "url": "https://files.pythonhosted.org/packages/6b/21/8c860e17f88eb2824d9cbddaffa469c5a687ef2bca714289b0d3dd1cd0ba/gluon2pytorch-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "97297c8dd4489c46c5a7b4c5da7657a1", "sha256": "ea9b07c676f737c20301bffdd55a898e48e76717ff8783db00f264f454ebbe31" }, "downloads": -1, "filename": "gluon2pytorch-0.0.6.tar.gz", "has_sig": false, "md5_digest": "97297c8dd4489c46c5a7b4c5da7657a1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11032, "upload_time": "2019-09-23T20:03:33", "url": "https://files.pythonhosted.org/packages/bf/28/db6e10686899afe8a433b2165fe5e2d3e761092a22aec2e2692df59fc1b1/gluon2pytorch-0.0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "97297c8dd4489c46c5a7b4c5da7657a1", "sha256": "ea9b07c676f737c20301bffdd55a898e48e76717ff8783db00f264f454ebbe31" }, "downloads": -1, "filename": "gluon2pytorch-0.0.6.tar.gz", "has_sig": false, "md5_digest": "97297c8dd4489c46c5a7b4c5da7657a1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11032, "upload_time": "2019-09-23T20:03:33", "url": "https://files.pythonhosted.org/packages/bf/28/db6e10686899afe8a433b2165fe5e2d3e761092a22aec2e2692df59fc1b1/gluon2pytorch-0.0.6.tar.gz" } ] }