This commit is contained in:
D-X-Y
2019-02-01 02:40:20 +11:00
parent 13e908f4df
commit 4eb1a5ccf9
15 changed files with 158 additions and 1479 deletions

100
data/ImageNet-100.txt Normal file
View File

@@ -0,0 +1,100 @@
n01532829
n01560419
n01580077
n01614925
n01664065
n01751748
n01871265
n01924916
n02087394
n02091134
n02091244
n02094433
n02097209
n02102040
n02102480
n02105251
n02106662
n02108422
n02108551
n02123597
n02165105
n02190166
n02268853
n02279972
n02408429
n02412080
n02443114
n02488702
n02509815
n02606052
n02701002
n02782093
n02794156
n02802426
n02804414
n02808440
n02906734
n02917067
n02950826
n02963159
n03017168
n03042490
n03045698
n03063689
n03065424
n03100240
n03109150
n03124170
n03131574
n03272562
n03345487
n03443371
n03461385
n03527444
n03690938
n03692522
n03721384
n03729826
n03792782
n03838899
n03843555
n03874293
n03877472
n03877845
n03908618
n03929660
n03930630
n03933933
n03970156
n03976657
n03982430
n04004767
n04065272
n04141975
n04146614
n04152593
n04192698
n04200800
n04204347
n04317175
n04326547
n04344873
n04370456
n04389033
n04501370
n04515003
n04542943
n04554684
n04562935
n04596742
n04597913
n04606251
n07583066
n07718472
n07734744
n07873807
n07880968
n09229709
n12768682
n12998815

View File

@@ -1,90 +0,0 @@
# EraseReLU: A Simple Way to Ease the Training of Deep Convolution Neural Networks
This project implements [this paper](https://arxiv.org/abs/1709.07634) in [PyTorch](pytorch.org). The implementation refers to [ResNeXt-DenseNet](https://github.com/D-X-Y/ResNeXt-DenseNet)
## Usage
All the model definations are located in the directory `models`.
All the training scripts are located in the directory `scripts` and `Xscripts`.
To train the ResNet-110 with EraseReLU on CIFAR-10:
```bash
sh scripts/warmup_train_2gpu.sh resnet110_erase cifar10
```
To train the original ResNet-110 on CIFAR-10:
```bash
sh scripts/warmup_train_2gpu.sh resnet110 cifar10
```
### MiniImageNet for PatchShuffle
```
sh scripts-shuffle/train_resnet_00000.sh ResNet18
sh scripts-shuffle/train_resnet_10000.sh ResNet18
sh scripts-shuffle/train_resnet_11000.sh ResNet18
```
```
sh scripts-shuffle/train_pmd_00000.sh PMDNet18_300
sh scripts-shuffle/train_pmd_00000.sh PMDNet34_300
sh scripts-shuffle/train_pmd_00000.sh PMDNet50_300
sh scripts-shuffle/train_pmd_11000.sh PMDNet18_300
sh scripts-shuffle/train_pmd_11000.sh PMDNet34_300
sh scripts-shuffle/train_pmd_11000.sh PMDNet50_300
```
### ImageNet
- Use the scripts `train_imagenet.sh` to train models in PyTorch.
- Or you can use the codes in `extra_torch` to train models in Torch.
#### Group Noramlization
```
sh Xscripts/train_vgg_gn.sh 0,1,2,3,4,5,6,7 vgg16_gn 256
sh Xscripts/train_vgg_gn.sh 0,1,2,3,4,5,6,7 vgg16_gn 64
sh Xscripts/train_vgg_gn.sh 0,1,2,3,4,5,6,7 vgg16_gn 16
sh Xscripts/train_res_gn.sh 0,1,2,3,4,5,6,7 resnext50_32_4_gn 16
```
| Model | Batch Size | Top-1 Error | Top-5 Errpr |
|:--------------:|:----------:|:-----------:|:-----------:|
| VGG16-GN | 256 | 28.82 | 9.64 |
## Results
| Model | Error on CIFAR-10 | Error on CIFAR-100|
|:--------------:|:-----------------:|:-----------------:|
| ResNet-56 | 6.97 | 30.60 |
| ResNet-56 (ER) | 6.23 | 28.56 |
## Citation
If you find this project helos your research, please consider cite the paper:
```
@article{dong2017eraserelu,
title={EraseReLU: A Simple Way to Ease the Training of Deep Convolution Neural Networks},
author={Dong, Xuanyi and Kang, Guoliang and Zhan, Kun and Yang, Yi},
journal={arXiv preprint arXiv:1709.07634},
year={2017}
}
```
## Download the ImageNet dataset
The ImageNet Large Scale Visual Recognition Challenge (ILSVRC) dataset has 1000 categories and 1.2 million images. The images do not need to be preprocessed or packaged in any database, but the validation images need to be moved into appropriate subfolders.
1. Download the images from http://image-net.org/download-images
2. Extract the training data:
```bash
mkdir train && mv ILSVRC2012_img_train.tar train/ && cd train
tar -xvf ILSVRC2012_img_train.tar && rm -f ILSVRC2012_img_train.tar
find . -name "*.tar" | while read NAME ; do mkdir -p "${NAME%.tar}"; tar -xvf "${NAME}" -C "${NAME%.tar}"; rm -f "${NAME}"; done
cd ..
```
3. Extract the validation data and move images to subfolders:
```bash
mkdir val && mv ILSVRC2012_img_val.tar val/ && cd val && tar -xvf ILSVRC2012_img_val.tar
wget -qO- https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh | bash
```

View File

@@ -1,5 +1,15 @@
# ImageNet
The class names of ImageNet-1K are in `classes.txt`.
# A 100-class subset of ImageNet-1K : ImageNet-100
The class names of ImageNet-100 are in `ImageNet-100.txt`.
Run `python split-imagenet.py` will automatically create ImageNet-100 based on the data of ImageNet-1K. By default, we assume the data of ImageNet-1K locates at `~/.torch/ILSVRC2012`. If your data is in a different location, you need to modify line-19 and line-20 in `split-imagenet.py`.
# Tiny-ImageNet
The official website is [here](https://tiny-imagenet.herokuapp.com/). Please run `python tiny-imagenet.py` to generate the correct format of Tiny ImageNet for training.
# PTB and WT2
`bash Get-PTB-WT2.sh`
Run `bash Get-PTB-WT2.sh` to download the data.

37
data/split-imagenet.py Normal file
View File

@@ -0,0 +1,37 @@
import os, sys, random
from pathlib import Path
def sample_100_cls():
with open('classes.txt') as f:
content = f.readlines()
content = [x.strip() for x in content]
random.seed(111)
classes = random.sample(content, 100)
classes.sort()
with open('ImageNet-100.txt', 'w') as f:
for cls in classes: f.write('{:}\n'.format(cls))
print('-'*100)
if __name__ == "__main__":
#sample_100_cls()
IN1K_root = Path.home() / '.torch' / 'ILSVRC2012'
IN100_root = Path.home() / '.torch' / 'ILSVRC2012-100'
assert IN1K_root.exists(), 'ImageNet directory does not exist : {:}'.format(IN1K_root)
print ('Create soft link from ImageNet directory into : {:}'.format(IN100_root))
with open('ImageNet-100.txt', 'r') as f:
classes = f.readlines()
classes = [x.strip() for x in classes]
for sub in ['train', 'val']:
xdir = IN100_root / sub
if not xdir.exists(): xdir.mkdir(parents=True, exist_ok=True)
for idx, cls in enumerate(classes):
xdir = IN1K_root / 'train' / cls
assert xdir.exists(), '{:} does not exist'.format(xdir)
os.system('ln -s {:} {:}'.format(xdir, IN100_root / 'train' / cls))
xdir = IN1K_root / 'val' / cls
assert xdir.exists(), '{:} does not exist'.format(xdir)
os.system('ln -s {:} {:}'.format(xdir, IN100_root / 'val' / cls))