init
This commit is contained in:
49
data/Get-PTB-WT2.sh
Normal file
49
data/Get-PTB-WT2.sh
Normal file
@@ -0,0 +1,49 @@
|
||||
# https://github.com/salesforce/awd-lstm-lm
|
||||
echo "=== Acquiring datasets ==="
|
||||
echo "---"
|
||||
mkdir -p save
|
||||
|
||||
mkdir -p data
|
||||
cd data
|
||||
|
||||
echo "- Downloading WikiText-2 (WT2)"
|
||||
wget --quiet --continue https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-v1.zip
|
||||
unzip -q wikitext-2-v1.zip
|
||||
cd wikitext-2
|
||||
mv wiki.train.tokens train.txt
|
||||
mv wiki.valid.tokens valid.txt
|
||||
mv wiki.test.tokens test.txt
|
||||
cd ..
|
||||
|
||||
echo "- Downloading WikiText-103 (WT2)"
|
||||
wget --continue https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-103-v1.zip
|
||||
unzip -q wikitext-103-v1.zip
|
||||
cd wikitext-103
|
||||
mv wiki.train.tokens train.txt
|
||||
mv wiki.valid.tokens valid.txt
|
||||
mv wiki.test.tokens test.txt
|
||||
cd ..
|
||||
|
||||
echo "- Downloading Penn Treebank (PTB)"
|
||||
wget --quiet --continue http://www.fit.vutbr.cz/~imikolov/rnnlm/simple-examples.tgz
|
||||
tar -xzf simple-examples.tgz
|
||||
|
||||
mkdir -p penn
|
||||
cd penn
|
||||
mv ../simple-examples/data/ptb.train.txt train.txt
|
||||
mv ../simple-examples/data/ptb.test.txt test.txt
|
||||
mv ../simple-examples/data/ptb.valid.txt valid.txt
|
||||
cd ..
|
||||
|
||||
echo "- Downloading Penn Treebank (Character)"
|
||||
mkdir -p pennchar
|
||||
cd pennchar
|
||||
mv ../simple-examples/data/ptb.char.train.txt train.txt
|
||||
mv ../simple-examples/data/ptb.char.test.txt test.txt
|
||||
mv ../simple-examples/data/ptb.char.valid.txt valid.txt
|
||||
cd ..
|
||||
|
||||
rm -rf simple-examples/
|
||||
|
||||
echo "---"
|
||||
echo "Happy language modeling :)"
|
90
data/README.BACK
Executable file
90
data/README.BACK
Executable file
@@ -0,0 +1,90 @@
|
||||
# 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
|
||||
```
|
5
data/README.md
Normal file
5
data/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# 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`
|
1000
data/classes.txt
Normal file
1000
data/classes.txt
Normal file
File diff suppressed because it is too large
Load Diff
3761
data/data/penn/test.txt
Normal file
3761
data/data/penn/test.txt
Normal file
File diff suppressed because it is too large
Load Diff
42068
data/data/penn/train.txt
Normal file
42068
data/data/penn/train.txt
Normal file
File diff suppressed because it is too large
Load Diff
3370
data/data/penn/valid.txt
Normal file
3370
data/data/penn/valid.txt
Normal file
File diff suppressed because it is too large
Load Diff
4358
data/data/wikitext-2/test.txt
Normal file
4358
data/data/wikitext-2/test.txt
Normal file
File diff suppressed because it is too large
Load Diff
36718
data/data/wikitext-2/train.txt
Normal file
36718
data/data/wikitext-2/train.txt
Normal file
File diff suppressed because it is too large
Load Diff
3760
data/data/wikitext-2/valid.txt
Normal file
3760
data/data/wikitext-2/valid.txt
Normal file
File diff suppressed because it is too large
Load Diff
53
data/tiny-imagenet.py
Normal file
53
data/tiny-imagenet.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import os, sys
|
||||
from pathlib import Path
|
||||
|
||||
url = "http://cs231n.stanford.edu/tiny-imagenet-200.zip"
|
||||
|
||||
def load_val():
|
||||
path = 'tiny-imagenet-200/val/val_annotations.txt'
|
||||
cfile = open(path, 'r')
|
||||
content = cfile.readlines()
|
||||
content = [x.strip().split('\t') for x in content]
|
||||
cfile.close()
|
||||
images = [x[0] for x in content]
|
||||
labels = [x[1] for x in content]
|
||||
return images, labels
|
||||
|
||||
def main():
|
||||
os.system("wget {:}".format(url))
|
||||
os.system("rm -rf tiny-imagenet-200")
|
||||
os.system("unzip -o tiny-imagenet-200.zip")
|
||||
images, labels = load_val()
|
||||
savedir = 'tiny-imagenet-200/new_val'
|
||||
if not os.path.exists(savedir): os.makedirs(savedir)
|
||||
for image, label in zip(images, labels):
|
||||
cdir = savedir + '/' + label
|
||||
if not os.path.exists(cdir): os.makedirs(cdir)
|
||||
ori_path = 'tiny-imagenet-200/val/images/' + image
|
||||
os.system("cp {:} {:}".format(ori_path, cdir))
|
||||
os.system("rm -rf tiny-imagenet-200/val")
|
||||
os.system("mv {:} tiny-imagenet-200/val".format(savedir))
|
||||
|
||||
def generate_salt_pepper():
|
||||
targetdir = Path('tiny-imagenet-200/val')
|
||||
noisedir = Path('tiny-imagenet-200/val-noise')
|
||||
assert targetdir.exists(), '{:} does not exist'.format(targetdir)
|
||||
from imgaug import augmenters as iaa
|
||||
import cv2
|
||||
aug = iaa.SaltAndPepper(p=0.2)
|
||||
|
||||
for sub in targetdir.iterdir():
|
||||
if not sub.is_dir(): continue
|
||||
subdir = noisedir / sub.name
|
||||
if not subdir.exists(): os.makedirs('{:}'.format(subdir))
|
||||
images = sub.glob('*.JPEG')
|
||||
for image in images:
|
||||
I = cv2.imread(str(image))
|
||||
Inoise = aug.augment_image(I)
|
||||
savepath = subdir / image.name
|
||||
cv2.imwrite(str(savepath), Inoise)
|
||||
print ('{:} done'.format(sub))
|
||||
|
||||
if __name__ == "__main__":
|
||||
#main()
|
||||
generate_salt_pepper()
|
Reference in New Issue
Block a user