README.md 3.17 KB
Newer Older
Xin Pan's avatar
Xin Pan committed
1
2
<font size=4><b>Reproduced ResNet on CIFAR-10 and CIFAR-100 dataset.</b></font>

Taylor Robie's avatar
Taylor Robie committed
3
4
# Deprecated
This code is not actively maintained. Please use the
Hongkun Yu's avatar
Hongkun Yu committed
5
[offical ResNet](https://github.com/tensorflow/models/tree/master/official/vision/image_classification) implementation
Taylor Robie's avatar
Taylor Robie committed
6
7
instead.

Xin Pan's avatar
Xin Pan committed
8
Xin Pan
Xin Pan's avatar
Xin Pan committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

<b>Dataset:</b>

https://www.cs.toronto.edu/~kriz/cifar.html

<b>Related papers:</b>

Identity Mappings in Deep Residual Networks

https://arxiv.org/pdf/1603.05027v2.pdf

Deep Residual Learning for Image Recognition

https://arxiv.org/pdf/1512.03385v1.pdf

Wide Residual Networks

https://arxiv.org/pdf/1605.07146v1.pdf

<b>Settings:</b>

* Random split 50k training set into 45k/5k train/eval split.
Neal Wu's avatar
Neal Wu committed
31
* Pad to 36x36 and random crop. Horizontal flip. Per-image whitening.
Xin Pan's avatar
Xin Pan committed
32
33
34
35
36
37
38
* Momentum optimizer 0.9.
* Learning rate schedule: 0.1 (40k), 0.01 (60k), 0.001 (>60k).
* L2 weight decay: 0.002.
* Batch size: 128. (28-10 wide and 1001 layer bottleneck use 64)

<b>Results:</b>

Neal Wu's avatar
Neal Wu committed
39
![Precisions](g3doc/cifar_resnet.gif)
40

Neal Wu's avatar
Neal Wu committed
41
![Precisions Legends](g3doc/cifar_resnet_legends.gif)
Xin Pan's avatar
Xin Pan committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

CIFAR-10 Model|Best Precision|Steps
--------------|--------------|------
32 layer|92.5%|~80k
110 layer|93.6%|~80k
164 layer bottleneck|94.5%|~80k
1001 layer bottleneck|94.9%|~80k
28-10 wide|95%|~90k

CIFAR-100 Model|Best Precision|Steps
---------------|--------------|-----
32 layer|68.1%|~45k
110 layer|71.3%|~60k
164 layer bottleneck|75.7%|~50k
1001 layer bottleneck|78.2%|~70k
28-10 wide|78.3%|~70k

<b>Prerequisite:</b>

1. Install TensorFlow, Bazel.

2. Download CIFAR-10/CIFAR-100 dataset.

```shell
curl -o cifar-10-binary.tar.gz https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz
curl -o cifar-100-binary.tar.gz https://www.cs.toronto.edu/~kriz/cifar-100-binary.tar.gz
```

<b>How to run:</b>

```shell
73
74
75
# cd to the models repository and run with bash. Expected command output shown.
# The directory should contain an empty WORKSPACE file, the resnet code, and the cifar10 dataset.
# Note: The user can split 5k from train set for eval set.
Neal Wu's avatar
Neal Wu committed
76
77
78
$ ls -R
.:
cifar10  resnet  WORKSPACE
Xin Pan's avatar
Xin Pan committed
79

Neal Wu's avatar
Neal Wu committed
80
81
82
./cifar10:
data_batch_1.bin  data_batch_2.bin  data_batch_3.bin  data_batch_4.bin
data_batch_5.bin  test_batch.bin
Xin Pan's avatar
Xin Pan committed
83

Neal Wu's avatar
Neal Wu committed
84
85
./resnet:
BUILD  cifar_input.py  g3doc  README.md  resnet_main.py  resnet_model.py
Xin Pan's avatar
Xin Pan committed
86
87

# Build everything for GPU.
Neal Wu's avatar
Neal Wu committed
88
$ bazel build -c opt --config=cuda resnet/...
Xin Pan's avatar
Xin Pan committed
89
90

# Train the model.
Neal Wu's avatar
Neal Wu committed
91
92
93
94
95
$ bazel-bin/resnet/resnet_main --train_data_path=cifar10/data_batch* \
                               --log_root=/tmp/resnet_model \
                               --train_dir=/tmp/resnet_model/train \
                               --dataset='cifar10' \
                               --num_gpus=1
Xin Pan's avatar
Xin Pan committed
96

Neal Wu's avatar
Neal Wu committed
97
# While the model is training, you can also check on its progress using tensorboard:
Neal Wu's avatar
Neal Wu committed
98
$ tensorboard --logdir=/tmp/resnet_model
Neal Wu's avatar
Neal Wu committed
99

Xin Pan's avatar
Xin Pan committed
100
101
102
# Evaluate the model.
# Avoid running on the same GPU as the training job at the same time,
# otherwise, you might run out of memory.
Neal Wu's avatar
Neal Wu committed
103
104
105
106
107
108
$ bazel-bin/resnet/resnet_main --eval_data_path=cifar10/test_batch.bin \
                               --log_root=/tmp/resnet_model \
                               --eval_dir=/tmp/resnet_model/test \
                               --mode=eval \
                               --dataset='cifar10' \
                               --num_gpus=0
Xin Pan's avatar
Xin Pan committed
109
```