-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix image classification training scripts and readme #309
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a8104e4
fix script, remove outdated readme text
hetong007 7f66c09
fix metric for smoothed label
hetong007 7069585
enable resuming from previous params and states
hetong007 a945585
fix
hetong007 a73f23f
Trigger CI
hetong007 7465726
Merge remote-tracking branch 'upstream/master' into fix_script2
hetong007 35673dd
fix scripts
hetong007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,150 +1,4 @@ | ||
# CIFAR10 | ||
|
||
Here we present examples of training resnet/wide-resnet on CIFAR10 dataset. | ||
|
||
The main training script is `train.py`. The script takes various parameters, thus we offer suggested parameters, and corresponding results. | ||
|
||
We also experiment the [Mix-Up augmentation method](https://arxiv.org/abs/1710.09412), and compare results for each model. | ||
|
||
## Models | ||
|
||
We offer models in `ResNetV1`, `ResNetV2` and `WideResNet`, with various parameters. Following is a list of available pretrained models for certain parameters, and their accuracy on CIFAR10: | ||
|
||
| Model | Accuracy | | ||
|------------------|----------| | ||
| ResNet20_v1 | 0.9160 | | ||
| ResNet56_v1 | 0.9387 | | ||
| ResNet110_v1 | 0.9471 | | ||
| ResNet20_v2 | 0.9158 | | ||
| ResNet56_v2 | 0.9413 | | ||
| ResNet110_v2 | 0.9484 | | ||
| WideResNet16_10 | 0.9614 | | ||
| WideResNet28_10 | 0.9667 | | ||
| WideResNet40_8 | 0.9673 | | ||
|
||
## Demo | ||
|
||
Before training your own model, you may want to take a look at how it will look like. | ||
|
||
Here we provide you a script `demo.py` to load a pre-trained model and predict on an image. | ||
|
||
**Execution** | ||
|
||
``` | ||
python demo --model cifar_resnet110_v2 --input-pic ~/Pictures/demo.jpg | ||
``` | ||
|
||
**Parameters Explained** | ||
|
||
- `--model`: The model to use. | ||
- `--saved-params`: the path to a locally saved model. | ||
- `--input-pic`: the path to the input picture file. | ||
|
||
## Training | ||
|
||
Training can be done by either `train.py` or `train_mixup.py`. | ||
|
||
Training a model on ResNet110_v2 can be done with | ||
|
||
``` | ||
python train.py --num-epochs 240 --mode hybrid --num-gpus 2 -j 32 --batch-size 64\ | ||
--wd 0.0001 --lr 0.1 --lr-decay 0.1 --lr-decay-epoch 80,160 --model cifar_resnet110_v2 | ||
``` | ||
|
||
With mixup, the command is | ||
|
||
``` | ||
python train_mixup.py --num-epochs 350 --mode hybrid --num-gpus 2 -j 32 --batch-size 64\ | ||
--wd 0.0001 --lr 0.1 --lr-decay 0.1 --lr-decay-epoch 150,250 --model cifar_resnet110_v2 | ||
``` | ||
|
||
To get results from a different ResNet, modify `--model`. | ||
|
||
Results: | ||
|
||
| Model | Accuracy | Mix-Up | | ||
|--------------|----------|--------| | ||
| ResNet20_v1 | 0.9115 | 0.9161 | | ||
| ResNet20_v2 | 0.9117 | 0.9119 | | ||
| ResNet56_v2 | 0.9307 | 0.9414 | | ||
| ResNet110_v2 | 0.9414 | 0.9447 | | ||
|
||
Pretrained Model: | ||
|
||
| Model | Accuracy | | ||
|--------------|----------| | ||
| ResNet20_v1 | 0.9160 | | ||
| ResNet56_v1 | 0.9387 | | ||
| ResNet110_v1 | 0.9471 | | ||
| ResNet20_v2 | 0.9130 | | ||
| ResNet56_v2 | 0.9413 | | ||
| ResNet110_v2 | 0.9464 | | ||
|
||
by script: | ||
|
||
``` | ||
python train_mixup.py --num-epochs 450 --mode hybrid --num-gpus 2 -j 32 --batch-size 64 --wd 0.0001 --lr 0.1 --lr-decay 0.1 --lr-decay-epoch 150,250 --model cifar_resnet20_v1 | ||
``` | ||
|
||
## Wide ResNet | ||
|
||
Training a model on WRN-28-10 can be done with | ||
|
||
``` | ||
python train.py --num-epochs 200 --mode hybrid --num-gpus 2 -j 32 --batch-size 64\ | ||
--wd 0.0005 --lr 0.1 --lr-decay 0.2 --lr-decay-epoch 60,120,160\ | ||
--model cifar_wideresnet28 --width-factor 10 | ||
``` | ||
|
||
With mixup, the command is | ||
|
||
``` | ||
python train_mixup.py --num-epochs 350 --mode hybrid --num-gpus 2 -j 32 --batch-size 64\ | ||
--wd 0.0001 --lr 0.1 --lr-decay 0.1 --lr-decay-epoch 80,160,240\ | ||
--model cifar_wideresnet28 --width-factor 10 | ||
``` | ||
|
||
To get results from a different WRN, modify `--model` and `--width-factor`. | ||
|
||
Results: | ||
|
||
| Model | Accuracy | Mix-Up | | ||
|--------------|----------|--------| | ||
| WRN-16-10 | 0.9527 | 0.9602 | | ||
| WRN-28-10 | 0.9584 | 0.9667 | | ||
| WRN-40-8 | 0.9559 | 0.9620 | | ||
|
||
Pretrained Model: | ||
|
||
| Model | Accuracy | | ||
|------------------|----------| | ||
| WideResNet20_v1 | 0.9614 | | ||
| WideResNet56_v1 | 0.9667 | | ||
| WideResNet110_v1 | 0.9673 | | ||
|
||
by scripts: | ||
|
||
``` | ||
python train_mixup.py --num-epochs 500 --mode hybrid --num-gpus 2 -j 32 --batch-size 64 --wd 0.0001 --lr 0.1 --lr-decay 0.1 --lr-decay-epoch 100,200,300 --model cifar_wideresnet16_10 | ||
``` | ||
|
||
**Parameters Explained** | ||
|
||
- `--batch-size`: per-device batch size for the training. | ||
- `--num-gpus`: the number of GPUs to use for computation, default is `0` and it means only using CPU. | ||
- `--model`: The model to train. For `CIFAR10` we offer [`ResNet`](https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/cifarresnet.py) and [`WideResNet`](https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/cifarwideresnet.py) as options. | ||
- `--num-data-workers`/`-j`: the number of data processing workers. | ||
- `--num-epochs`: the number of training epochs. | ||
- `--lr`: the initial learning rate in training. | ||
- `--momentum`: the momentum parameter. | ||
- `--wd`: the weight decay parameter. | ||
- `--lr-decay`: the learning rate decay factor. | ||
- `--lr-decay-period`: the learning rate decay period, i.e. for every `--lr-decay-period` epochs, the learning rate will decay by a factor of `--lr-decay`. | ||
- `--lr-decay-epoch`: epochs at which the learning rate decay by a factor of `--lr-decay`. | ||
- `--width-factor`: parameters for `WideResNet` model. | ||
- `--drop-rate`: parameters for `WideResNet` model. | ||
- `--mode`: whether to use `hybrid` mode to speed up the training process. | ||
- `--save-period`: for every `--save-period`, the model will be saved to disk. | ||
- `--save-dir`: the directory to save the models. | ||
- `--logging-dir`: the directory to save the training logs. | ||
# Image Classification on CIFAR10 | ||
|
||
Please refer to [GluonCV Model Zoo](http://gluon-cv.mxnet.io/model_zoo/index.html#image-classification) | ||
for available pretrained models, training hyper-parameters, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,4 @@ | ||
# Image Classification | ||
|
||
Here we present an examples to train gluon on image classification tasks. | ||
|
||
## ImageNet | ||
|
||
Here we present examples of training resnet on ImageNet dataset. | ||
|
||
The main training script is `train_imagenet.py`. The script takes various parameters, thus we offer suggested parameters, and corresponding results. | ||
|
||
### ResNet50_v2 | ||
|
||
Training a ResNet50_v2 can be done with: | ||
|
||
``` | ||
python train_imagenet.py --batch-size 64 --num-gpus 4 -j 32 --mode hybrid\ | ||
--num-epochs 120 --lr 0.1 --momentum 0.9 --wd 0.0001\ | ||
--lr-decay 0.1 --lr-decay-epoch 30,60,90 --model resnet50_v2 | ||
``` | ||
|
||
Results: | ||
|
||
| Model | Top-1 Error | Top-5 Error | | ||
|--------------|-------------|-------------| | ||
| ResNet50_v2 | 0.2428 | 0.0738 | | ||
|
||
# Image Classification on ImageNet | ||
|
||
Please refer to [GluonCV Model Zoo](http://gluon-cv.mxnet.io/model_zoo/index.html#image-classification) | ||
for available pretrained models, training hyper-parameters, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this
label
is not used now? After adding line 362 thetrain_metric
seems to be updated withhard_label
, irrelevant to the smoothedlabel
.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.
label
is used in loss calculation.