Giter Club home page Giter Club logo

revisiting-self-supervised's Introduction

Revisiting self-supervised visual representation learning

Tensorflow implementation of experiments from our paper on unsupervised visual representation learning.

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

@inproceedings{kolesnikov2019revisiting,
    title={Revisiting self-supervised visual representation learning},
    author={Kolesnikov, Alexander and Zhai, Xiaohua and Beyer, Lucas},
    journal={The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
    month={June},
    year={2019}
}

Overview

This codebase allows to reproduce core experiments from our paper. It contains our re-implementation of four self-supervised representation learning techniques, utility code for running training and evaluation loops (including on TPUs) and an implementation of standard CNN models, such as ResNet v1, ResNet v2 and VGG19.

Specifically, we provide a re-implementation of the following self-supervised representation learning techniques:

  1. Unsupervised Representation Learning by Predicting Image Rotations
  2. Unsupervised Visual Representation Learning by Context Prediction
  3. Unsupervised Learning of Visual Representations by Solving Jigsaw Puzzles
  4. Discriminative Unsupervised Feature Learning with Exemplar Convolutional Neural Networks

Usage instructions

In the paper we train self-supervised models using 32 or 128 TPU cores. We evaluate the resulting representations by training a logistic regression model on 32 TPU cores.

In this codebase we provide configurations for training/evaluation of our models using an 8 TPU core setup as this setup is more affordable for public TPU users through the Google Cloud API. These configurations produce results close to those reported in the paper, which used more TPU chips.

For debugging or running small experiments we also support training and evaluation using a single GPU device.

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/revisiting-self-supervised
cd revisiting-self-supervised
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
wget https://github.com/MehdiNoroozi/JigsawPuzzleSolver/raw/master/permutations_100_max.bin

Running locally on a single GPU

Run any experiment by running the corresponding shell script with the following options, here exemplified for the fully supervised experiment:

./config/supervised/imagenet.sh \
  --workdir <WORKING_DIRECTORY> \
  --nouse_tpu \
  --master='' \
  --dataset_dir <PREPROCESSED_IMAGENET_PATH>

Running on Google Cloud using TPUs

Step 1:

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

Step 2:

Clone the repository and install dependencies as described above.

Step 3:

Run the self supervised model training script with TPUs. For example:

gsutil mb gs://<WORKING_DIRECTORY>
export TPU_NAME=<TPU_PROJECT_NAME>
config/supervised/imagenet.sh --workdir gs://<WORKING_DIRECTORY> --dataset_dir gs://<PREPROCESSED_IMAGENET_PATH>

After/during training, run the self supervised model evaluation script with TPUs. It generates the loss and metric on the validation set, and exports a hub module under directory gs://<WORKING_DIRECTORY>/export/hub/<TIMESTAMP>/module:

config/supervised/imagenet.sh --workdir gs://<WORKING_DIRECTORY> --dataset_dir gs://<PREPROCESSED_IMAGENET_PATH> --run_eval

Note, that <TPU_PROJECT_NAME> is set by the user when creating the Cloud TPU node. Moreover, ImageNet data and the working directory should be placed in a Google Cloud bucket storage.

Step 4:

Evaluates the self supervised models with logistic regression. You need to pass the exported hub module from step 3 above as an additional argument:

gsutil mb gs://<EVAL_DIRECTORY>
export TPU_NAME=<TPU_PROJECT_NAME>
config/evaluation/rotation_or_exemplar.sh --workdir gs://<EVAL_DIRECTORY> --dataset_dir gs://<PREPROCESSED_IMAGENET_PATH> --hub_module gs://<PATH_TO_YOUR_HUB_MODULE>

config/evaluation/rotation_or_exemplar.sh --workdir gs://<EVAL_DIRECTORY> --dataset_dir gs://<PREPROCESSED_IMAGENET_PATH> --hub_module gs://<PATH_TO_YOUR_HUB_MODULE> --run_eval

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

tensorboard --port 2222 --logdir gs://<EVAL_DIRECTORY>

Pretrained models

If you want to download and try our best self-supervised models please see this Ipython notebook.

Authors

This is not an official Google product

revisiting-self-supervised's People

Contributors

akolesnikoff avatar erjanmx avatar lucasb-eyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

revisiting-self-supervised's Issues

Code for logistic regression by L-BFGS

Hello!

Congratulations for the CVPR paper, and thanks for sharing your implementation.
Is the code for training logistic regression classifiers using L-BFGS available here in the repo? If it is not, can you please tell me how implemented that?

Regards.

Link to pre-trained models is broken

Hey!

I was trying to access the ImageNet pre-trained models, but the link seems to be broken. I was wondering if it would be possible to share the models in some way?

Thanks!

Questions about stride param in resnet50

Hi, thanks for the comprehensive review about recent SOTA self-supervised methods and the open source code.

When I read the code of net arch part, I am a little bit confused about the stride param in resnet50(

x = unit(x, filters, strides=1, **params)
). This param is set to 1 for the second to the final residual block which is different from the traditional resnet50 setting( https://github.com/tensorflow/models/blob/47e783e62a41f1f19baffc316d6530315ea872ac/official/resnet/keras/resnet_model.py#L106 ). Could you please help me for that? thanks a lot.

How to prepare the dataset?

Hi, thank you for interesting work! I am trying to reproduce the experiment in my PC using single GPU.

In the parameters for training the model, I saw --dataset_dir <PREPROCESSED_IMAGENET_PATH>. However, I couldn't find any instruction on how to prepare what inside this folder. Could you please explain it a little bit?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.