-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add example for EfficientNet and upgrade PyTorch in Dockerfile #1497
Changes from 5 commits
45c5dbf
a5923d4
92ff82d
0793a2f
d2a9f85
0f16b18
210be47
1d6b780
0eafaac
c3dfc1c
a9fa817
546505c
11c3ff6
9a7a470
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EfficientNet-PyTorch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EfficientNet-PyTorch is with Apache license and cannot be included into our repo. So user has to clone this repo ahead. Add it to gitignore to prevent this directory to be included in our repo. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# EfficientNet | ||
|
||
[arXiv](https://arxiv.org/abs/1905.11946) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please change |
||
|
||
We provide here: | ||
|
||
* Search space and tuners for finding the best tuple (alpha, beta, gamma) for EfficientNet-B1 with | ||
grid search, as discussed in Section 3.3 in [paper](https://arxiv.org/abs/1905.11946). | ||
* Search space for EfficientNet transfer learning on datasets other than ImageNet; | ||
settings are borrowed from Appendix A.5 from | ||
"[Do Better ImageNet Models Transfer Better?](https://arxiv.org/abs/1805.08974)". | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems the work in second paper (https://arxiv.org/abs/1805.08974) is not specific to EfficientNet. What we provided in this example for 2nd paper is just learning rate search (which we already have a lot of examples). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 2nd paper is cited by EfficientNet, for the settings of transfer learning. And yes, it's not important in the big picture. The main reason I show this here is to provide an example on how to use transfer learning with EfficientNet-PyTorch. I'm fine with removing this part. What about @QuanluZhang ? |
||
## Instructions | ||
|
||
1. Clone our modified version of [EfficientNet-PyTorch](https://github.com/ultmaster/EfficientNet-PyTorch). | ||
The modifications were done to adhere to the original [Tensorflow version](https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet) | ||
as close as possible (including EMA, label smoothing and etc.); also added are the interactions with NNI. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also added are the interactions with NNI? (sorry I cannot understand...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made it more clear. |
||
Clone it into `EfficientNet-PyTorch`; then you will see files like `main.py`, `train_imagenet.sh`, as specified | ||
in the configuration files. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why separate this sentence into 2 lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
2. Resolve all the dependencies following the README. | ||
3. Run `nnictl create --config config_lr.yml` if you want to do transfer learning; | ||
or `nnictl create --config config_net.yml` if you want to find the best EfficientNet-B1. | ||
Adjust the training service (PAI/local/remote), batch size in the config files according to your environment. | ||
|
||
For training on ImageNet, you should read `EfficientNet-PyTorch/train_imagenet.sh`. Download ImageNet beforehand | ||
and extract it adhering to [PyTorch format](https://pytorch.org/docs/stable/torchvision/datasets.html#imagenet) | ||
and then replace `/mnt/data/imagenet` in with the location of your ImageNet storage. This file should also be a good example | ||
in case you want to mount ImageNet into the container on OpenPAI. | ||
|
||
*Backward compatibility instructions: Grid Search quniform is changed in NNI v1.0. Use `search_net_old.json` if you are | ||
still using NNI <= 0.9.* | ||
|
||
## Results | ||
|
||
Our experiments show the relationship between acc@1 and alpha, beta, gamma. | ||
|
||
![](assets/search_result.png) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
authorName: unknown | ||
experimentName: lr_efficient_net | ||
trialConcurrency: 4 | ||
maxExecDuration: 48h | ||
maxTrialNum: 140 | ||
trainingServicePlatform: pai | ||
searchSpacePath: search_lr_old.json | ||
useAnnotation: false | ||
tuner: | ||
builtinTunerName: GridSearch | ||
trial: | ||
codeDir: EfficientNet-PyTorch | ||
command: python3 main.py cifar10 -j 4 --epochs 20 -a efficientnet-b0 --pretrained --num-classes 10 --batch-size 64 --optimizer sgd --request-from-nni | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this code(main.py)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is in EfficientNet-PyTorch repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make clear in docs.. |
||
cpuNum: 4 | ||
memoryMB: 16384 | ||
gpuNum: 1 | ||
shmMB: 8192 | ||
virtualCluster: nni | ||
image: msranni/nni:latest | ||
nniManagerIp: <nni_manager_ip> | ||
paiConfig: | ||
userName: <username> | ||
passWord: <password> | ||
host: <host> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
authorName: unknown | ||
experimentName: example_efficient_net | ||
trialConcurrency: 8 | ||
maxExecDuration: 48h | ||
maxTrialNum: 100 | ||
trainingServicePlatform: pai | ||
searchSpacePath: search_net.json | ||
useAnnotation: false | ||
tuner: | ||
codeDir: . | ||
classFileName: tuner.py | ||
className: FixedProductTuner | ||
classArgs: | ||
product: 2 | ||
trial: | ||
codeDir: EfficientNet-PyTorch | ||
command: sh train_imagenet.sh | ||
cpuNum: 4 | ||
memoryMB: 25000 | ||
shmMB: 25000 | ||
gpuNum: 1 | ||
virtualCluster: nni | ||
image: msranni/nni:latest | ||
nniManagerIp: <nni_manager_ip> | ||
paiConfig: | ||
userName: <username> | ||
passWord: <password> | ||
host: <host> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"lr": { | ||
"_type": "qloguniform", | ||
"_value": [0.00001, 0.1, 7] | ||
}, | ||
"wd": { | ||
"_type": "qloguniform", | ||
"_value": [0.000001, 0.001, 7] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"alpha": { | ||
"_type": "quniform", | ||
"_value": [1.0, 2.0, 0.1] | ||
}, | ||
"beta": { | ||
"_type": "quniform", | ||
"_value": [1.0, 1.5, 0.1] | ||
}, | ||
"gamma": { | ||
"_type": "quniform", | ||
"_value": [1.0, 1.5, 0.1] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"alpha": { | ||
"_type": "quniform", | ||
"_value": [1.0, 2.0, 11] | ||
}, | ||
"beta": { | ||
"_type": "quniform", | ||
"_value": [1.0, 1.5, 11] | ||
}, | ||
"gamma": { | ||
"_type": "quniform", | ||
"_value": [1.0, 1.5, 11] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from nni.gridsearch_tuner.gridsearch_tuner import GridSearchTuner | ||
|
||
|
||
class FixedProductTuner(GridSearchTuner): | ||
|
||
def __init__(self, product): | ||
super().__init__() | ||
self.product = product | ||
|
||
def expand_parameters(self, para): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better adding some docstring here? |
||
para = super().expand_parameters(para) | ||
if all([key in para[0] for key in ["alpha", "beta", "gamma"]]): | ||
ret_para = [] | ||
for p in para: | ||
prod = p["alpha"] * (p["beta"] ** 2) * (p["gamma"] ** 2) | ||
if abs(prod - self.product) < 0.1: | ||
ret_para.append(p) | ||
return ret_para | ||
return para |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to use seperate PR to upgrade Dockfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this PR won't work without this Dockerfile update. Maybe I should update the title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's OK for me to change PR name.