Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a78e84e

Browse files
Merge branch 'master' into #192_include_top
2 parents f522b18 + a746930 commit a78e84e

File tree

8 files changed

+490
-101
lines changed

8 files changed

+490
-101
lines changed

‎README.md‎

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# EfficientNet PyTorch
22

3-
### Quickstart
3+
### Quickstart
44

55
Install with `pip install efficientnet_pytorch` and load a pretrained EfficientNet with:
66
```python
@@ -12,46 +12,45 @@ model = EfficientNet.from_pretrained('efficientnet-b0')
1212

1313
#### Update (May 14, 2020)
1414

15-
This update adds comprehensive comments and documentation (thanks to @workingcoder).
15+
This update adds comprehensive comments and documentation (thanks to @workingcoder).
1616

1717
#### Update (January 23, 2020)
1818

1919
This update adds a new category of pre-trained model based on adversarial training, called _advprop_. It is important to note that the preprocessing required for the advprop pretrained models is slightly different from normal ImageNet preprocessing. As a result, by default, advprop models are not used. To load a model with advprop, use:
20-
```
20+
```python
2121
model = EfficientNet.from_pretrained("efficientnet-b0", advprop=True)
2222
```
2323
There is also a new, large `efficientnet-b8` pretrained model that is only available in advprop form. When using these models, replace ImageNet preprocessing code as follows:
24-
```
24+
```python
2525
if advprop: # for models using advprop pretrained weights
2626
normalize = transforms.Lambda(lambda img: img * 2.0 - 1.0)
2727
else:
28-
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
28+
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
2929
std=[0.229, 0.224, 0.225])
30-
3130
```
32-
This update also addresses multiple other issues ([#115](https://github.com/lukemelas/EfficientNet-PyTorch/issues/115), [#128](https://github.com/lukemelas/EfficientNet-PyTorch/issues/128)).
31+
This update also addresses multiple other issues ([#115](https://github.com/lukemelas/EfficientNet-PyTorch/issues/115), [#128](https://github.com/lukemelas/EfficientNet-PyTorch/issues/128)).
3332

3433
#### Update (October 15, 2019)
3534

3635
This 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).
3736

3837
#### Update (October 12, 2019)
3938

40-
This 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!
39+
This 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!
4140

4241
#### Update (July 31, 2019)
4342

4443
_Upgrade the pip package with_ `pip install --upgrade efficientnet-pytorch`
4544

46-
The 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:
45+
The 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:
4746
```python
4847
from efficientnet_pytorch import EfficientNet
49-
model = EfficientNet.from_pretrained('efficientnet-b7')
48+
model = EfficientNet.from_pretrained('efficientnet-b7')
5049
```
5150

5251
#### Update (June 29, 2019)
5352

54-
This 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)).
53+
This 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)).
5554

5655
* [Example: Export to ONNX](#example-export)
5756
* [Example: Extract features](#example-feature-extraction)
@@ -60,29 +59,29 @@ This update adds easy model exporting ([#20](https://github.com/lukemelas/Effici
6059
It is also now incredibly simple to load a pretrained model with a new number of classes for transfer learning:
6160
```python
6261
model = EfficientNet.from_pretrained('efficientnet-b1', num_classes=23)
63-
```
62+
```
6463

6564

6665
#### Update (June 23, 2019)
6766

68-
The B4 and B5 models are now available. Their usage is identical to the other models:
67+
The B4 and B5 models are now available. Their usage is identical to the other models:
6968
```python
7069
from efficientnet_pytorch import EfficientNet
71-
model = EfficientNet.from_pretrained('efficientnet-b4')
70+
model = EfficientNet.from_pretrained('efficientnet-b4')
7271
```
7372

7473
### Overview
75-
This repository contains an op-for-op PyTorch reimplementation of [EfficientNet](https://arxiv.org/abs/1905.11946), along with pre-trained models and examples.
74+
This repository contains an op-for-op PyTorch reimplementation of [EfficientNet](https://arxiv.org/abs/1905.11946), along with pre-trained models and examples.
7675

77-
The 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.
76+
The 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.
7877

79-
At the moment, you can easily:
80-
* Load pretrained EfficientNet models
81-
* Use EfficientNet models for classification or feature extraction
78+
At the moment, you can easily:
79+
* Load pretrained EfficientNet models
80+
* Use EfficientNet models for classification or feature extraction
8281
* Evaluate EfficientNet models on ImageNet or your own images
8382

8483
_Upcoming features_: In the next few days, you will be able to:
85-
* Train new models from scratch on ImageNet with a simple command
84+
* Train new models from scratch on ImageNet with a simple command
8685
* Quickly finetune an EfficientNet on your own dataset
8786
* Export EfficientNet models for production
8887

@@ -95,11 +94,11 @@ _Upcoming features_: In the next few days, you will be able to:
9594
* [Example: Classify](#example-classification)
9695
* [Example: Extract features](#example-feature-extraction)
9796
* [Example: Export to ONNX](#example-export)
98-
6. [Contributing](#contributing)
97+
6. [Contributing](#contributing)
9998

10099
### About EfficientNet
101100

102-
If you're new to EfficientNets, here is an explanation straight from the official TensorFlow implementation:
101+
If you're new to EfficientNets, here is an explanation straight from the official TensorFlow implementation:
103102

104103
EfficientNets 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.
105104

@@ -141,27 +140,25 @@ Or install from source:
141140
git clone https://github.com/lukemelas/EfficientNet-PyTorch
142141
cd EfficientNet-Pytorch
143142
pip install -e .
144-
```
143+
```
145144

146145
### Usage
147146

148147
#### Loading pretrained models
149148

150-
Load an EfficientNet:
149+
Load an EfficientNet:
151150
```python
152151
from efficientnet_pytorch import EfficientNet
153152
model = EfficientNet.from_name('efficientnet-b0')
154153
```
155154

156-
Load a pretrained EfficientNet:
155+
Load a pretrained EfficientNet:
157156
```python
158157
from efficientnet_pytorch import EfficientNet
159158
model = EfficientNet.from_pretrained('efficientnet-b0')
160159
```
161160

162-
Note 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`.
163-
164-
Details about the models are below:
161+
Details about the models are below:
165162

166163
| *Name* |*# Params*|*Top-1 Acc.*|*Pretrained?*|
167164
|:-----------------:|:--------:|:----------:|:-----------:|
@@ -179,7 +176,7 @@ Details about the models are below:
179176

180177
Below 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).
181178

182-
We 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`.
179+
We 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`.
183180

184181
```python
185182
import json
@@ -212,7 +209,7 @@ for idx in torch.topk(outputs, k=5).indices.squeeze(0).tolist():
212209
print('{label:<75} ({p:.2f}%)'.format(label=labels_map[idx], p=prob*100))
213210
```
214211

215-
#### Example: Feature Extraction
212+
#### Example: Feature Extraction
216213

217214
You can easily extract features with `model.extract_features`:
218215
```python
@@ -226,20 +223,20 @@ features = model.extract_features(img)
226223
print(features.shape) # torch.Size([1, 1280, 7, 7])
227224
```
228225

229-
#### Example: Export to ONNX
226+
#### Example: Export to ONNX
230227

231-
Exporting to ONNX for deploying to production is now simple:
228+
Exporting to ONNX for deploying to production is now simple:
232229
```python
233-
import torch
230+
import torch
234231
from efficientnet_pytorch import EfficientNet
235232

236233
model = EfficientNet.from_pretrained('efficientnet-b1')
237234
dummy_input = torch.randn(10, 3, 240, 240)
238235

239236
torch.onnx.export(model, dummy_input, "test-b1.onnx", verbose=True)
240-
```
237+
```
241238

242-
[Here](https://colab.research.google.com/drive/1rOAEXeXHaA8uo3aG2YcFDHItlRJMV0VP) is a Colab example.
239+
[Here](https://colab.research.google.com/drive/1rOAEXeXHaA8uo3aG2YcFDHItlRJMV0VP) is a Colab example.
243240

244241

245242
#### ImageNet
@@ -248,6 +245,6 @@ See `examples/imagenet` for details about evaluating on ImageNet.
248245

249246
### Contributing
250247

251-
If 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.
248+
If 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.
252249

253-
I look forward to seeing what the community does with these models!
250+
I look forward to seeing what the community does with these models!

‎efficientnet_pytorch/__init__.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
__version__ = "0.7.0"
2-
from .model import EfficientNet
2+
from .model import EfficientNet, VALID_MODELS
33
from .utils import (
44
GlobalParams,
55
BlockArgs,
66
BlockDecoder,
77
efficientnet,
88
get_model_params,
99
)
10-

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /