Home

Awesome

S4L: Self-Supervised Semi-Supervised Learning

Tensorflow implementation of experiments from our paper on self-supervised semi-supervised learning.

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

@article{zhai2019s4l,
         title={S4L: Self-Supervised Semi-Supervised Learning},
         author={Zhai, Xiaohua and Avital Oliver and Kolesnikov, Alexander and Beyer, Lucas},
         journal={arXiv preprint arXiv:1901.09005},
         year={2019}
}

Overview

This codebase allows to reproduce core experiments from our paper. In particular, we release S4L-Rotation and S4L-Exemplar models along with our reimplementation of popular semi-supervised learning baselines, such as pseudo-label, VAT and Entropy Minization. Moreover, we provide code for training supervised baseline models on on 1% and 10% of ImageNet images that are substatinally better than those previously reported in the literature.

Preparing data

Please refer to the instructions in the slim library for downloading and preprocessing ImageNet data.

Clone the repository and install dependencies

git clone https://github.com/google-research/s4l
cd s4l
python -m pip install -e . --user

We depend on some external files that need to be downloaded and placed in the root repository folder. You can run the following commands to download them:

wget https://raw.githubusercontent.com/tensorflow/models/master/research/slim/preprocessing/inception_preprocessing.py

Running on Google Cloud using TPUs

Step 1:

Create your own TPU cloud instance by following the official documentation.

For quick reference, at the time of writing this, run the following command in cloud shell (modify according to your needs):

ctpu up --name host-v3-8 --zone europe-west4-a --tpu-size v3-8

Step 2:

SSH to the VM instance created for your TPU above in step one above. Clone the repository and install dependencies as described earlier.

Step 3:

Run model training script. For example:

gsutil mb gs://workdir
./config/supervised_imagenet_1p.sh --tpu_name host-v3-8 --dataset_dir <Google cloud bucket with preprocessed Imagenet Dataset> --workdir gs://workdir

You could start a TensorBoard to visualize the training/evaluation progress:

tensorboard --port 2222 --logdir gs://workdir

After/during training, run the self supervised model evaluation script:

./config/supervised_imagenet_1p.sh --tpu_name host-v3-8 --dataset_dir <Google cloud bucket with preprocessed Imagenet Dataset> --workdir gs://workdir --run_eval

Results and pretrained models

Since this is an open-source reproduction of the code we used for the paper's experiments, we validated that we do indeed reproduce the results. The following table summarizes the results we got using this codebase trained on Cloud TPUs, and compares it to the numbers we report in the paper. All results are on 10% of labelled data unless noted otherwise.

All pre-trained models are made available as TF Hub modules in the gs://s4l-models bucket, which you can use as-is, or browse here.

ModelTPU sizeTop5 (Paper)Top5Top1
Supervised (1%)v3-848.4348.3125.09
Supervisedv3-880.4380.4256.36
S4L-Rotationv3-3283.8283.8561.37
S4L-Exemplarv3-3283.7283.7162.17
Pseudo-labelsv3-882.4182.8660.24
VATv3-3282.7882.7159.98
VAT + EntMinv3-3283.3983.2860.87
MOAM Step 1v3-12888.8088.7069.46
MOAM Step 2v3-12889.96TODOTODO
MOAM Step 3v3-12891.23TODOTODO

Authors

This is not an official Google product