microsoft / metric-transfer.pytorch

Deep Metric Transfer for Label Propagation with Limited Annotated Data
MIT License
49 stars 19 forks source link
image-classification semi-supervised-learning unsupervised-learning

Deep Metric Transfer for Label Propagation with Limited Annotated Data

This repo contains the pytorch implementation for the semi-supervised learning paper (arxiv).

Requirements

Highlight

Main results

The test accuracy of our methods and the state-of-the-art methods on CIFAR10 dataset with different number of labeled data.

Method 50 100 250 500 1000 2000 4000 8000
PI-model 27.36 37.20 47.07 56.30 63.70 76.50 84.17 87.30
Mean-Teacher 29.66 36.60 45.49 57.20 65.00 79.00 84.38 87.50
VAT 23.00 35.58 47.61 62.90 72.80 84.00 86.79 88.10
Pseudo-Label 21.00 34.00 45.83 60.30 68.20 78.00 84.79 86.20
Ours 56.34 63.53 71.26 74.77 79.38 82.34 84.52 87.48

Quick start

Usage

The proposed method contains three main steps: metric pretraining, label propagation, and supervised finetune.

Metric pretraining

The metric pretraining can be unsupervised or supervised, from the same or different dataset.

We provide code for instance discrimination, which is borrowed from the original pytorch release of instance discrimination. You can run the following command in root director of code to train the instance discrimination on cifar10 dataset:

export PYTHONPATH=$PYTHONPATH:$(pwd)
CUDA_VISIBLE_DEVICES=0 python unsupervised/cifar.py \
    --lr-scheduler cosine-with-restart \
    --epochs 1270

For other metric or imagenet dataset, such as colorization on cifar10 dataset, or instance discrimination on imagenet datset, ref to offical released code: colorization, instance discrimination. We also provide the pretrained weight. Refer to scripts/download_model.sh for more details.

Label propagation

We then can propagation the label using the trained metric from the few labeled examples to a vast collection of unannotated images.

We consider two propagation algorithms: K-nearest neighbors(i.e. knn) and spectral clustering(also called normalized cut, i.e nc). The implementation is in notebooks folder, which is in jupyter notebook format. You can simplely run the notebook to load the weight of metric pretraining approach and propagate to get the pseudo label.

We alse provide the pseudo label for cifar10 and imagenet dataset. Refer to scripts/download_model.sh for more details.

Supervised finetune

With the estimated pseudo labels on the unlabeled data, we can train a classifier with more data. For simplicity, we omit the confidence weighted supervised training in the current version. Instead, we only use a portion of the most confident pseudo label to training.

Refer to quickstart part for more command instruction.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Citation

If you find this paper useful in your research, please consider citing:

@inproceedings{liu2018deep,
  title={Deep Metric Transfer for Label Propagation with Limited Annotated Data},
  author={Liu, Bin and Wu, Zhirong and Hu, Han and Lin, Stephen},
  journal={arXiv preprint arXiv:1812.08781},
  year={2018}
}

Contact

For any questions, please feel free to create a new issue or reach

Bin Liu: liubinthss@gmail.com