Skip to content

Commit f6e9262

Browse files
Merge branch 'dev-ssl' into master
2 parents 68e84a4 + 230df3a commit f6e9262

39 files changed

+3601
-33
lines changed

docs/dalib/benchmarks/re_identification.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We adopt cross dataset setting (another one is cross camera setting). The model
1616

1717
For a fair comparison, our model is trained with standard cross entropy loss and triplet loss. We adopt modified resnet architecture from `Mutual Mean-Teaching: Pseudo Label Refinery for Unsupervised Domain Adaptation on Person Re-identification (ICLR 2020) <https://arxiv.org/pdf/2001.01526.pdf>`_.
1818

19-
As we are given unlabeled samples from target domain, we can utilize clustering algorithms to produce pseudo labels on target domain and then use them as supervision signals to perform self-training. This simple method turns out to be a strong baseline. We use ``Baseline_Cluster`` to represent this baseline in our results.
19+
As we are given unlabelled samples from target domain, we can utilize clustering algorithms to produce pseudo labels on target domain and then use them as supervision signals to perform self-training. This simple method turns out to be a strong baseline. We use ``Baseline_Cluster`` to represent this baseline in our results.
2020

2121
.. note::
2222

docs/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ Transfer Learning
8080
:caption: Semi Supervised Learning Methods
8181
:titlesonly:
8282

83-
ssllib/semi_supervised_learning.rst
83+
ssllib/consistency_regularization.rst
84+
ssllib/contrastive_learning.rst
85+
ssllib/holistic_methods.rst
86+
ssllib/proxy_label.rst
8487

8588

8689

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=======================================
2+
Consistency Regularization
3+
=======================================
4+
5+
.. _PI_MODEL:
6+
7+
Pi Model
8+
------------------
9+
10+
.. autofunction:: ssllib.pi_model.sigmoid_rampup
11+
12+
.. autofunction:: ssllib.pi_model.softmax_mse_loss
13+
14+
.. autofunction:: ssllib.pi_model.symmetric_mse_loss
15+
16+
.. autoclass:: ssllib.pi_model.SoftmaxMSELoss
17+
18+
.. autoclass:: ssllib.pi_model.SoftmaxKLLoss
19+
20+
21+
.. _MEAN_TEACHER:
22+
23+
Mean Teacher
24+
------------------
25+
26+
.. autofunction:: ssllib.mean_teacher.update_ema_variables
27+
28+
.. autoclass:: ssllib.mean_teacher.SymmetricMSELoss
29+
30+
.. autoclass:: ssllib.mean_teacher.MeanTeacher
31+
32+
33+
.. _UDA:
34+
35+
Unsupervised Data Augmentation (UDA)
36+
------------------------------------
37+
38+
.. autoclass:: ssllib.rand_augment.RandAugment
39+
40+
.. autoclass:: ssllib.uda.SupervisedUDALoss
41+
42+
.. autoclass:: ssllib.uda.UnsupervisedUDALoss
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=======================================
2+
Contrastive Learning
3+
=======================================
4+
5+
.. _SELF_TUNING:
6+
7+
Self-Tuning
8+
------------------
9+
10+
.. autoclass:: ssllib.self_tuning.Classifier
11+
12+
.. autoclass:: ssllib.self_tuning.SelfTuning

docs/ssllib/holistic_methods.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=======================================
2+
Holistic Methods
3+
=======================================
4+
5+
.. _FIXMATCH:
6+
7+
FixMatch
8+
------------------
9+
10+
.. autoclass:: ssllib.fix_match.FixMatchConsistencyLoss

docs/ssllib/proxy_label.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=======================================
2+
Proxy-Label Based Methods
3+
=======================================
4+
5+
.. _PSEUDO:
6+
7+
Pseudo Label
8+
------------------
9+
10+
Given model predictions :math:`y` on unlabeled samples, we can directly utilize them to generate
11+
pseudo labels :math:`label=\mathop{\arg\max}\limits_{i}~y[i]`. Then we use these pseudo labels as supervision to train
12+
our model. Details can be found at `projects/self_tuning/pseudo_label.py`.

examples/task_adaptation/image_classification/README.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ and prepare them following [Documentation for Retinopathy](/common/vision/datase
3232

3333
Supported methods include:
3434

35-
- [Explicit inductive bias for transfer learning with convolutional networks
36-
(L2-SP, ICML 2018)](https://arxiv.org/abs/1802.01483)
35+
- [Learning Without Forgetting (LWF, ECCV 2016)](https://arxiv.org/abs/1606.09282)
36+
- [Explicit inductive bias for transfer learning with convolutional networks (L2-SP, ICML 2018)](https://arxiv.org/abs/1802.01483)
3737
- [Catastrophic Forgetting Meets Negative Transfer: Batch Spectral Shrinkage for Safe Transfer Learning (BSS, NIPS 2019)](https://proceedings.neurips.cc/paper/2019/file/c6bff625bdb0393992c9d4db0c6bbe45-Paper.pdf)
3838
- [DEep Learning Transfer using Fea- ture Map with Attention for convolutional networks (DELTA, ICLR 2019)](https://openreview.net/pdf?id=rkgbwsAcYm)
3939
- [Co-Tuning for Transfer Learning (Co-Tuning, NIPS 2020)](http://ise.thss.tsinghua.edu.cn/~mlong/doc/co-tuning-for-transfer-learning-nips20.pdf)
4040
- [Stochastic Normalization (StochNorm, NIPS 2020)](https://papers.nips.cc/paper/2020/file/bc573864331a9e42e4511de6f678aa83-Paper.pdf)
41-
- [Learning Without Forgetting (LWF, ECCV 2016)](https://arxiv.org/abs/1606.09282)
4241
- [Bi-tuning of Pre-trained Representations (Bi-Tuning)](https://arxiv.org/abs/2011.06182?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+arxiv%2FQSXk+%28ExcitingAds%21+cs+updates+on+arXiv.org%29)
4342

4443
## Experiment and Results
@@ -78,52 +77,52 @@ If you use these methods in your research, please consider citing.
7877

7978
```
8079
@inproceedings{LWF,
81-
author = {Zhizhong Li and
80+
author = {Zhizhong Li and
8281
Derek Hoiem},
83-
title = {Learning without Forgetting},
84-
booktitle={ECCV},
85-
year = {2016},
82+
title = {Learning without Forgetting},
83+
booktitle={ECCV},
84+
year = {2016},
8685
}
8786
8887
@inproceedings{L2SP,
89-
title={Explicit inductive bias for transfer learning with convolutional networks},
90-
author={Xuhong, LI and Grandvalet, Yves and Davoine, Franck},
91-
booktitle={ICML},
92-
year={2018},
88+
title={Explicit inductive bias for transfer learning with convolutional networks},
89+
author={Xuhong, LI and Grandvalet, Yves and Davoine, Franck},
90+
booktitle={ICML},
91+
year={2018},
9392
}
9493
9594
@inproceedings{BSS,
96-
title={Catastrophic forgetting meets negative transfer: Batch spectral shrinkage for safe transfer learning},
97-
author={Chen, Xinyang and Wang, Sinan and Fu, Bo and Long, Mingsheng and Wang, Jianmin},
98-
booktitle={NeurIPS},
99-
year={2019}
95+
title={Catastrophic forgetting meets negative transfer: Batch spectral shrinkage for safe transfer learning},
96+
author={Chen, Xinyang and Wang, Sinan and Fu, Bo and Long, Mingsheng and Wang, Jianmin},
97+
booktitle={NeurIPS},
98+
year={2019}
10099
}
101100
102101
@inproceedings{DELTA,
103-
title={Delta: Deep learning transfer using feature map with attention for convolutional networks},
104-
author={Li, Xingjian and Xiong, Haoyi and Wang, Hanchao and Rao, Yuxuan and Liu, Liping and Chen, Zeyu and Huan, Jun},
105-
booktitle={ICLR},
106-
year={2019}
102+
title={Delta: Deep learning transfer using feature map with attention for convolutional networks},
103+
author={Li, Xingjian and Xiong, Haoyi and Wang, Hanchao and Rao, Yuxuan and Liu, Liping and Chen, Zeyu and Huan, Jun},
104+
booktitle={ICLR},
105+
year={2019}
107106
}
108107
109108
@inproceedings{StocNorm,
110-
title={Stochastic Normalization},
111-
author={Kou, Zhi and You, Kaichao and Long, Mingsheng and Wang, Jianmin},
112-
booktitle={NeurIPS},
113-
year={2020}
109+
title={Stochastic Normalization},
110+
author={Kou, Zhi and You, Kaichao and Long, Mingsheng and Wang, Jianmin},
111+
booktitle={NeurIPS},
112+
year={2020}
114113
}
115114
116115
@inproceedings{CoTuning,
117-
title={Co-Tuning for Transfer Learning},
118-
author={You, Kaichao and Kou, Zhi and Long, Mingsheng and Wang, Jianmin},
119-
booktitle={NeurIPS},
120-
year={2020}
116+
title={Co-Tuning for Transfer Learning},
117+
author={You, Kaichao and Kou, Zhi and Long, Mingsheng and Wang, Jianmin},
118+
booktitle={NeurIPS},
119+
year={2020}
121120
}
122121
123122
@article{BiTuning,
124-
title={Bi-tuning of Pre-trained Representations},
125-
author={Zhong, Jincheng and Wang, Ximei and Kou, Zhi and Wang, Jianmin and Long, Mingsheng},
126-
journal={arXiv preprint arXiv:2011.06182},
127-
year={2020}
123+
title={Bi-tuning of Pre-trained Representations},
124+
author={Zhong, Jincheng and Wang, Ximei and Kou, Zhi and Wang, Jianmin and Long, Mingsheng},
125+
journal={arXiv preprint arXiv:2011.06182},
126+
year={2020}
128127
}
129128
```

projects/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Here are a few projects that are built on Trans-Learn. They are examples of how to use Trans-Learn as a library, to
2+
facilitate your own research.
3+
4+
## Projects by [THUML](https://github.com/thuml)
5+
6+
- [Self-Tuning for Data-Efficient Deep Learning (2021 ICML)](http://ise.thss.tsinghua.edu.cn/~mlong/doc/Self-Tuning-for-Data-Efficient-Deep-Learning-icml21.pdf)

projects/self_tuning/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Self-Tuning
2+
3+
In this repository, we implement self-tuning and various SSL (semi-supervised learning) algorithms in Trans-Learn.
4+
5+
## Installation
6+
7+
Example scripts support all models in [PyTorch-Image-Models](https://github.com/rwightman/pytorch-image-models). You
8+
need to install timm to use PyTorch-Image-Models.
9+
10+
```
11+
pip install timm
12+
```
13+
14+
## Dataset
15+
16+
Following datasets can be downloaded automatically:
17+
18+
- [CUB200](http://www.vision.caltech.edu/visipedia/CUB-200-2011.html)
19+
- [StanfordCars](https://ai.stanford.edu/~jkrause/cars/car_dataset.html)
20+
- [Aircraft](https://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/)
21+
22+
## Supported Methods
23+
24+
Supported methods include:
25+
26+
- Pseudo Label (directly utilize model predictions as pseudo labels on unlabeled samples)
27+
- [Temporal Ensembling for Semi-Supervised Learning (pi model, ICLR 2017)](https://arxiv.org/abs/1610.02242)
28+
- [Weight-averaged consistency targets improve semi-supervised deep learning results (mean teacher, NIPS 2017)](https://openreview.net/references/pdf?id=ry8u21rtl)
29+
- [Unsupervised Data Augmentation for Consistency Training (uda, NIPS 2020)](https://proceedings.neurips.cc/paper/2020/file/44feb0096faa8326192570788b38c1d1-Paper.pdf)
30+
- [FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence (FixMatch, NIPS 2020)](https://proceedings.neurips.cc/paper/2020/file/f7ac67a9aa8d255282de7d11391e1b69-Paper.pdf)
31+
- [Self-Tuning for Data-Efficient Deep Learning (self-tuning, ICML 2021)](http://ise.thss.tsinghua.edu.cn/~mlong/doc/Self-Tuning-for-Data-Efficient-Deep-Learning-icml21.pdf)
32+
33+
## Experiments and Results
34+
35+
### SSL with supervised pre-trained model
36+
37+
The shell files give the script to reproduce our [results](benchmark.md) with specified hyper-parameters. For example,
38+
if you want to run baseline on CUB200 with 15% labeled samples, use the following script
39+
40+
```shell script
41+
# SSL with ResNet50 backbone on CUB200.
42+
# Assume you have put the datasets under the path `data/cub200`,
43+
# or you are glad to download the datasets automatically from the Internet to this path
44+
CUDA_VISIBLE_DEVICES=0 python baseline.py data/cub200 -d CUB200 -sr 15 --seed 0 --log logs/baseline/cub200_15
45+
```
46+
47+
### SSL with unsupervised pre-trained model
48+
49+
Take MoCo as an example.
50+
51+
1. Download MoCo pretrained checkpoints from https://github.com/facebookresearch/moco
52+
2. Convert the format of the MoCo checkpoints to the standard format of pytorch
53+
54+
```shell
55+
mkdir checkpoints
56+
python convert_moco_to_pretrained.py checkpoints/moco_v1_200ep_pretrain.pth.tar checkpoints/moco_v1_200ep_backbone.pth checkpoints/moco_v1_200ep_fc.pth
57+
```
58+
59+
3. Start training
60+
61+
```shell
62+
CUDA_VISIBLE_DEVICES=0 python baseline.py data/cub200 -d CUB200 -sr 15 --seed 0 --log logs/baseline_moco/cub200_15 \
63+
--pretrained checkpoints/moco_v1_200ep_backbone.pth
64+
```
65+
66+
## TODO
67+
68+
Support datasets: CIFAR10, CIFAR100, ImageNet
69+
70+
## Citation
71+
72+
If you use these methods in your research, please consider citing.
73+
74+
```
75+
@inproceedings{pi-model,
76+
title={Temporal ensembling for semi-supervised learning},
77+
author={Laine, Samuli and Aila, Timo},
78+
booktitle={ICLR},
79+
year={2017}
80+
}
81+
@inproceedings{mean-teacher,
82+
title={Mean teachers are better role models: Weight-averaged consistency targets improve semi-supervised deep learning results},
83+
author={Tarvainen, Antti and Valpola, Harri},
84+
booktitle={NIPS},
85+
year={2017}
86+
}
87+
@inproceedings{uda,
88+
title={Unsupervised data augmentation for consistency training},
89+
author={Xie, Qizhe and Dai, Zihang and Hovy, Eduard and Luong, Minh-Thang and Le, Quoc V},
90+
booktitle={NIPS},
91+
year={2019}
92+
}
93+
@inproceedings{fixmatch,
94+
title={Fixmatch: Simplifying semi-supervised learning with consistency and confidence},
95+
author={Sohn, Kihyuk and Berthelot, David and Li, Chun-Liang and Zhang, Zizhao and Carlini, Nicholas and Cubuk, Ekin D and Kurakin, Alex and Zhang, Han and Raffel, Colin},
96+
booktitle={NIPS},
97+
year={2020}
98+
}
99+
@inproceedings{self-tuning,
100+
title={Self-tuning for data-efficient deep learning},
101+
author={Wang, Ximei and Gao, Jinghan and Long, Mingsheng and Wang, Jianmin},
102+
booktitle={ICML},
103+
year={2021},
104+
}
105+
```

0 commit comments

Comments
 (0)