{ "info": { "author": "Luke", "author_email": "lmelaskyriazi@college.harvard.edu", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": "# EfficientNet PyTorch\n\n### Update (October 15, 2019)\n\nThis update allows you to choose whether to use a memory-efficient Swish activation. The memory-efficient version is chosen by default, but it cannot be used when exporting using PyTorch JIT. For this purpose, we have also included a standard (export-friendly) swish activation function. To switch to the export-friendly version, simply call `model.set_swish(memory_efficient=False)` after loading your desired model. This update addresses issues [#88](https://github.com/lukemelas/EfficientNet-PyTorch/pull/88) and [#89](https://github.com/lukemelas/EfficientNet-PyTorch/pull/89).\n\n#### Update (October 12, 2019)\n\nThis update makes the Swish activation function more memory-efficient. It also addresses pull requests [#72](https://github.com/lukemelas/EfficientNet-PyTorch/pull/72), [#73](https://github.com/lukemelas/EfficientNet-PyTorch/pull/73), [#85](https://github.com/lukemelas/EfficientNet-PyTorch/pull/85), and [#86](https://github.com/lukemelas/EfficientNet-PyTorch/pull/86). Thanks to the authors of all the pull requests! \n\n### Update (July 31, 2019)\n\n_Upgrade the pip package with_ `pip install --upgrade efficientnet-pytorch`\n\nThe B6 and B7 models are now available. Additionally, _all_ pretrained models have been updated to use AutoAugment preprocessing, which translates to better performance across the board. Usage is the same as before: \n```python\nfrom efficientnet_pytorch import EfficientNet\nmodel = EfficientNet.from_pretrained('efficientnet-b7') \n```\n\n### Update (June 29, 2019)\n\nThis update adds easy model exporting ([#20](https://github.com/lukemelas/EfficientNet-PyTorch/issues/20)) and feature extraction ([#38](https://github.com/lukemelas/EfficientNet-PyTorch/issues/38)). \n\n * [Example: Export to ONNX](#example-export)\n * [Example: Extract features](#example-feature-extraction)\n * Also: fixed a CUDA/CPU bug ([#32](https://github.com/lukemelas/EfficientNet-PyTorch/issues/32))\n\nIt is also now incredibly simple to load a pretrained model with a new number of classes for transfer learning:\n```python\nmodel = EfficientNet.from_pretrained('efficientnet-b1', num_classes=23)\n``` \n\n\n### Update (June 23, 2019)\n\nThe B4 and B5 models are now available. Their usage is identical to the other models: \n```python\nfrom efficientnet_pytorch import EfficientNet\nmodel = EfficientNet.from_pretrained('efficientnet-b4') \n```\n\n### Overview\nThis repository contains an op-for-op PyTorch reimplementation of [EfficientNet](https://arxiv.org/abs/1905.11946), along with pre-trained models and examples. \n\nThe goal of this implementation is to be simple, highly extensible, and easy to integrate into your own projects. This implementation is a work in progress -- new features are currently being implemented. \n\nAt the moment, you can easily: \n * Load pretrained EfficientNet models \n * Use EfficientNet models for classification or feature extraction \n * Evaluate EfficientNet models on ImageNet or your own images\n\n_Upcoming features_: In the next few days, you will be able to:\n * Train new models from scratch on ImageNet with a simple command \n * Quickly finetune an EfficientNet on your own dataset\n * Export EfficientNet models for production\n\n### Table of contents\n1. [About EfficientNet](#about-efficientnet)\n2. [About EfficientNet-PyTorch](#about-efficientnet-pytorch)\n3. [Installation](#installation)\n4. [Usage](#usage)\n * [Load pretrained models](#loading-pretrained-models)\n * [Example: Classify](#example-classification)\n * [Example: Extract features](#example-feature-extraction)\n * [Example: Export to ONNX](#example-export)\n6. [Contributing](#contributing) \n\n### About EfficientNet\n\nIf you're new to EfficientNets, here is an explanation straight from the official TensorFlow implementation: \n\nEfficientNets are a family of image classification models, which achieve state-of-the-art accuracy, yet being an order-of-magnitude smaller and faster than previous models. We develop EfficientNets based on AutoML and Compound Scaling. In particular, we first use [AutoML Mobile framework](https://ai.googleblog.com/2018/08/mnasnet-towards-automating-design-of.html) to develop a mobile-size baseline network, named as EfficientNet-B0; Then, we use the compound scaling method to scale up this baseline to obtain EfficientNet-B1 to B7.\n\n\n\n \n \n\n
\n \n \n \n
\n\nEfficientNets achieve state-of-the-art accuracy on ImageNet with an order of magnitude better efficiency:\n\n\n* In high-accuracy regime, our EfficientNet-B7 achieves state-of-the-art 84.4% top-1 / 97.1% top-5 accuracy on ImageNet with 66M parameters and 37B FLOPS, being 8.4x smaller and 6.1x faster on CPU inference than previous best [Gpipe](https://arxiv.org/abs/1811.06965).\n\n* In middle-accuracy regime, our EfficientNet-B1 is 7.6x smaller and 5.7x faster on CPU inference than [ResNet-152](https://arxiv.org/abs/1512.03385), with similar ImageNet accuracy.\n\n* Compared with the widely used [ResNet-50](https://arxiv.org/abs/1512.03385), our EfficientNet-B4 improves the top-1 accuracy from 76.3% of ResNet-50 to 82.6% (+6.3%), under similar FLOPS constraint.\n\n### About EfficientNet PyTorch\n\nEfficientNet PyTorch is a PyTorch re-implementation of EfficientNet. It is consistent with the [original TensorFlow implementation](https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet), such that it is easy to load weights from a TensorFlow checkpoint. At the same time, we aim to make our PyTorch implementation as simple, flexible, and extensible as possible.\n\nIf you have any feature requests or questions, feel free to leave them as GitHub issues!\n\n### Installation\n\nInstall via pip:\n```bash\npip install efficientnet_pytorch\n```\n\nOr install from source:\n```bash\ngit clone https://github.com/lukemelas/EfficientNet-PyTorch\ncd EfficientNet-Pytorch\npip install -e .\n``` \n\n### Usage\n\n#### Loading pretrained models\n\nLoad an EfficientNet: \n```python\nfrom efficientnet_pytorch import EfficientNet\nmodel = EfficientNet.from_name('efficientnet-b0')\n```\n\nLoad a pretrained EfficientNet: \n```python\nfrom efficientnet_pytorch import EfficientNet\nmodel = EfficientNet.from_pretrained('efficientnet-b0')\n```\n\nNote that pretrained models have only been released for `N=0,1,2,3,4,5` at the current time, so `.from_pretrained` only supports `'efficientnet-b{N}'` for `N=0,1,2,3,4,5`. \n\nDetails about the models are below: \n\n| *Name* |*# Params*|*Top-1 Acc.*|*Pretrained?*|\n|:-----------------:|:--------:|:----------:|:-----------:|\n| `efficientnet-b0` | 5.3M | 76.3 | \u2713 |\n| `efficientnet-b1` | 7.8M | 78.8 | \u2713 |\n| `efficientnet-b2` | 9.2M | 79.8 | \u2713 |\n| `efficientnet-b3` | 12M | 81.1 | \u2713 |\n| `efficientnet-b4` | 19M | 82.6 | \u2713 |\n| `efficientnet-b5` | 30M | 83.3 | \u2713 |\n| `efficientnet-b6` | 43M | 84.0 | \u2713 |\n| `efficientnet-b7` | 66M | 84.4 | \u2713 |\n\n\n#### Example: Classification\n\nBelow is a simple, complete example. It may also be found as a jupyter notebook in `examples/simple` or as a [Colab Notebook](https://colab.research.google.com/drive/1Jw28xZ1NJq4Cja4jLe6tJ6_F5lCzElb4).\n\nWe assume that in your current directory, there is a `img.jpg` file and a `labels_map.txt` file (ImageNet class names). These are both included in `examples/simple`. \n\n```python\nimport json\nfrom PIL import Image\nimport torch\nfrom torchvision import transforms\n\nfrom efficientnet_pytorch import EfficientNet\nmodel = EfficientNet.from_pretrained('efficientnet-b0')\n\n# Preprocess image\ntfms = transforms.Compose([transforms.Resize(224), transforms.ToTensor(),\n transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),])\nimg = tfms(Image.open('img.jpg')).unsqueeze(0)\nprint(img.shape) # torch.Size([1, 3, 224, 224])\n\n# Load ImageNet class names\nlabels_map = json.load(open('labels_map.txt'))\nlabels_map = [labels_map[str(i)] for i in range(1000)]\n\n# Classify\nmodel.eval()\nwith torch.no_grad():\n outputs = model(img)\n\n# Print predictions\nprint('-----')\nfor idx in torch.topk(outputs, k=5).indices.squeeze(0).tolist():\n prob = torch.softmax(outputs, dim=1)[0, idx].item()\n print('{label:<75} ({p:.2f}%)'.format(label=labels_map[idx], p=prob*100))\n```\n\n#### Example: Feature Extraction \n\nYou can easily extract features with `model.extract_features`:\n```python\nfrom efficientnet_pytorch import EfficientNet\nmodel = EfficientNet.from_pretrained('efficientnet-b0')\n\n# ... image preprocessing as in the classification example ...\nprint(img.shape) # torch.Size([1, 3, 224, 224])\n\nfeatures = model.extract_features(img)\nprint(features.shape) # torch.Size([1, 1280, 7, 7])\n```\n\n#### Example: Export to ONNX \n\nExporting to ONNX for deploying to production is now simple: \n```python\nimport torch \nfrom efficientnet_pytorch import EfficientNet\n\nmodel = EfficientNet.from_pretrained('efficientnet-b1')\ndummy_input = torch.randn(10, 3, 240, 240)\n\ntorch.onnx.export(model, dummy_input, \"test-b1.onnx\", verbose=True)\n``` \n\n[Here](https://colab.research.google.com/drive/1rOAEXeXHaA8uo3aG2YcFDHItlRJMV0VP) is a Colab example. \n\n\n#### ImageNet\n\nSee `examples/imagenet` for details about evaluating on ImageNet.\n\n### Contributing\n\nIf you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues. \n\nI look forward to seeing what the community does with these models!", "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/lukemelas/efficientnet_pytorch", "keywords": "", "license": "Apache", "maintainer": "", "maintainer_email": "", "name": "efficientnet-pytorch", "package_url": "https://pypi.org/project/efficientnet-pytorch/", "platform": "", "project_url": "https://pypi.org/project/efficientnet-pytorch/", "project_urls": { "Homepage": "https://github.com/lukemelas/efficientnet_pytorch" }, "release_url": "https://pypi.org/project/efficientnet-pytorch/0.5.1/", "requires_dist": null, "requires_python": ">=3.5.0", "summary": "EfficientNet implemented in PyTorch.", "version": "0.5.1" }, "last_serial": 5974757, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "2c86ab6caf28f44e4aeee1e3119860f5", "sha256": "15639201a27005af84034cf0114095d0be888649ba33b9d42512aaa167e324d9" }, "downloads": -1, "filename": "efficientnet_pytorch-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2c86ab6caf28f44e4aeee1e3119860f5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 14045, "upload_time": "2019-06-01T11:23:10", "url": "https://files.pythonhosted.org/packages/06/ff/881afd965c46b11fc6f3c8316de9e08d37fc3b71056dbab861b76faee6ca/efficientnet_pytorch-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "34949aa0f1aa0fae7debc33648bfb1c9", "sha256": "efdb9ea0d524d5718e6641defcc416f4c789f19ca88c432e03f2ce9caa637be3" }, "downloads": -1, "filename": "efficientnet_pytorch-0.1.0.tar.gz", "has_sig": false, "md5_digest": "34949aa0f1aa0fae7debc33648bfb1c9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 12695, "upload_time": "2019-06-01T11:23:12", "url": "https://files.pythonhosted.org/packages/e0/16/8802c6015a9bd40f3172473e958f5fafba3b8ffcbffbdd9c1fa9600d7887/efficientnet_pytorch-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "77a2a2cb5b64c64143409030768b1041", "sha256": "64f518cd8f21be6e9124b41660291d545c00531d0de5599f601d4a76502b96d7" }, "downloads": -1, "filename": "efficientnet_pytorch-0.2.0.tar.gz", "has_sig": false, "md5_digest": "77a2a2cb5b64c64143409030768b1041", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 11190, "upload_time": "2019-06-18T23:29:36", "url": "https://files.pythonhosted.org/packages/72/a3/68e95f068658fd26ef2757980e7a177faf7678d1fd8d7f7306a75250145c/efficientnet_pytorch-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "d635f4e1ff3536adcbcb7a5da53d65c8", "sha256": "88e33cc90e45eb332f63013c295836d96edc39dd208cdb42b7002f40f8193e8e" }, "downloads": -1, "filename": "efficientnet_pytorch-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d635f4e1ff3536adcbcb7a5da53d65c8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 15181, "upload_time": "2019-06-29T23:52:38", "url": "https://files.pythonhosted.org/packages/c9/e9/81aa23322344835403b8852e7c24938edf7945da729b653d4cfa779e7571/efficientnet_pytorch-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a092de34ffe67426622a8c24e92d2c50", "sha256": "bca16bc6fbb40b8afccb5801e78e01c022619dd29cde6ad2df0b66eb06034b4f" }, "downloads": -1, "filename": "efficientnet_pytorch-0.3.0.tar.gz", "has_sig": false, "md5_digest": "a092de34ffe67426622a8c24e92d2c50", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 14488, "upload_time": "2019-06-29T23:52:43", "url": "https://files.pythonhosted.org/packages/cd/af/d17f7852a1fc69d347108200b1f24dd0b2dea55e50577dfb039dad626437/efficientnet_pytorch-0.3.0.tar.gz" } ], "0.3.0.dev1": [ { "comment_text": "", "digests": { "md5": "5c322755b93718394a12acd9b4dee0cd", "sha256": "4eb323a30f7d79d0cce7851536019263c8db8d9af5971e2d4d5a323c267303f5" }, "downloads": -1, "filename": "efficientnet_pytorch-0.3.0.dev1-py3-none-any.whl", "has_sig": false, "md5_digest": "5c322755b93718394a12acd9b4dee0cd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 15201, "upload_time": "2019-06-29T23:52:40", "url": "https://files.pythonhosted.org/packages/a0/69/d42e3e2a9b3f2d818a98111f62fd8f1a712047b72ebbec1579b0b1aa0e5a/efficientnet_pytorch-0.3.0.dev1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "261d38ff86041764b9bd2cc0ac219b03", "sha256": "e7071b24877d06cf5a3135df9da00589d84b0f9326f9589917b0c37cc00c409d" }, "downloads": -1, "filename": "efficientnet_pytorch-0.3.0.dev1.tar.gz", "has_sig": false, "md5_digest": "261d38ff86041764b9bd2cc0ac219b03", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 14465, "upload_time": "2019-06-29T23:52:42", "url": "https://files.pythonhosted.org/packages/5a/8d/a56f997b68ceb308c03d08f42a72c3f43cc28872154f184a428dac96f3bd/efficientnet_pytorch-0.3.0.dev1.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "6b0aa738d60e963a63784a702a90d1e1", "sha256": "60be7f742f3804a607db066cbbfb77ecc6ee0c28b2d0415e17a8b543db92257e" }, "downloads": -1, "filename": "efficientnet_pytorch-0.4.0.tar.gz", "has_sig": false, "md5_digest": "6b0aa738d60e963a63784a702a90d1e1", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 11621, "upload_time": "2019-08-01T00:42:36", "url": "https://files.pythonhosted.org/packages/12/f8/35453605c6c471fc406a137a894fb381b05ae9f174b2ca4956592512374e/efficientnet_pytorch-0.4.0.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "d8cde00be2dd7200bf661bea6385a58f", "sha256": "dd50d4f245cb911cfb6c26029ea7a213a1083623c8962aeb3ae61c1e497e4493" }, "downloads": -1, "filename": "efficientnet_pytorch-0.5.0.tar.gz", "has_sig": false, "md5_digest": "d8cde00be2dd7200bf661bea6385a58f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 11920, "upload_time": "2019-10-13T00:46:21", "url": "https://files.pythonhosted.org/packages/96/81/01b9652ea7bcf8a46324bdf509423015a5e9fcbd88c83e9b5e10651e3a75/efficientnet_pytorch-0.5.0.tar.gz" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "97326150663bc3200a91dd8383f8254f", "sha256": "8c1d954c4b15a6574d81147215920db9b192f03e0e0360e2c0606ce3c219bb77" }, "downloads": -1, "filename": "efficientnet_pytorch-0.5.1.tar.gz", "has_sig": false, "md5_digest": "97326150663bc3200a91dd8383f8254f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 12292, "upload_time": "2019-10-15T04:41:05", "url": "https://files.pythonhosted.org/packages/82/18/1c4d61eea11b78235ce270a528e099b19af2f1026aadf45e9c645cd75e2f/efficientnet_pytorch-0.5.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "97326150663bc3200a91dd8383f8254f", "sha256": "8c1d954c4b15a6574d81147215920db9b192f03e0e0360e2c0606ce3c219bb77" }, "downloads": -1, "filename": "efficientnet_pytorch-0.5.1.tar.gz", "has_sig": false, "md5_digest": "97326150663bc3200a91dd8383f8254f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 12292, "upload_time": "2019-10-15T04:41:05", "url": "https://files.pythonhosted.org/packages/82/18/1c4d61eea11b78235ce270a528e099b19af2f1026aadf45e9c645cd75e2f/efficientnet_pytorch-0.5.1.tar.gz" } ] }