All Projects → sayakpaul → SimCLR-in-TensorFlow-2

sayakpaul / SimCLR-in-TensorFlow-2

Licence: MIT license
(Minimally) implements SimCLR (https://arxiv.org/abs/2002.05709) in TensorFlow 2.

Programming Languages

Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to SimCLR-in-TensorFlow-2

adareg-monodispnet
Repository for Bilateral Cyclic Constraint and Adaptive Regularization for Unsupervised Monocular Depth Prediction (CVPR2019)
Stars: ✭ 22 (-70.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
temporal-ssl
Video Representation Learning by Recognizing Temporal Transformations. In ECCV, 2020.
Stars: ✭ 46 (-38.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
Transferlearning
Transfer learning / domain adaptation / domain generalization / multi-task learning etc. Papers, codes, datasets, applications, tutorials.-迁移学习
Stars: ✭ 8,481 (+11208%)
Mutual labels:  unsupervised-learning, self-supervised-learning
PIC
Parametric Instance Classification for Unsupervised Visual Feature Learning, NeurIPS 2020
Stars: ✭ 41 (-45.33%)
Mutual labels:  unsupervised-learning, self-supervised-learning
VQ-APC
Vector Quantized Autoregressive Predictive Coding (VQ-APC)
Stars: ✭ 34 (-54.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
PiCIE
PiCIE: Unsupervised Semantic Segmentation using Invariance and Equivariance in clustering (CVPR2021)
Stars: ✭ 102 (+36%)
Mutual labels:  unsupervised-learning, self-supervised-learning
Simclr
SimCLRv2 - Big Self-Supervised Models are Strong Semi-Supervised Learners
Stars: ✭ 2,720 (+3526.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
Sfmlearner
An unsupervised learning framework for depth and ego-motion estimation from monocular videos
Stars: ✭ 1,661 (+2114.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
Revisiting-Contrastive-SSL
Revisiting Contrastive Methods for Unsupervised Learning of Visual Representations. [NeurIPS 2021]
Stars: ✭ 81 (+8%)
Mutual labels:  unsupervised-learning, self-supervised-learning
naru
Neural Relation Understanding: neural cardinality estimators for tabular data
Stars: ✭ 76 (+1.33%)
Mutual labels:  unsupervised-learning, self-supervised-learning
al-fk-self-supervision
Official PyTorch code for CVPR 2020 paper "Deep Active Learning for Biased Datasets via Fisher Kernel Self-Supervision"
Stars: ✭ 28 (-62.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
awesome-graph-self-supervised-learning
Awesome Graph Self-Supervised Learning
Stars: ✭ 805 (+973.33%)
Mutual labels:  unsupervised-learning, self-supervised-learning
awesome-contrastive-self-supervised-learning
A comprehensive list of awesome contrastive self-supervised learning papers.
Stars: ✭ 748 (+897.33%)
Mutual labels:  unsupervised-learning, self-supervised-learning
learning-topology-synthetic-data
Tensorflow implementation of Learning Topology from Synthetic Data for Unsupervised Depth Completion (RAL 2021 & ICRA 2021)
Stars: ✭ 22 (-70.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
CLSA
official implemntation for "Contrastive Learning with Stronger Augmentations"
Stars: ✭ 48 (-36%)
Mutual labels:  unsupervised-learning, self-supervised-learning
ViCC
[WACV'22] Code repository for the paper "Self-supervised Video Representation Learning with Cross-Stream Prototypical Contrasting", https://arxiv.org/abs/2106.10137.
Stars: ✭ 33 (-56%)
Mutual labels:  unsupervised-learning, self-supervised-learning
mmselfsup
OpenMMLab Self-Supervised Learning Toolbox and Benchmark
Stars: ✭ 2,315 (+2986.67%)
Mutual labels:  unsupervised-learning, self-supervised-learning
PlanSum
[AAAI2021] Unsupervised Opinion Summarization with Content Planning
Stars: ✭ 25 (-66.67%)
Mutual labels:  unsupervised-learning
FKD
A Fast Knowledge Distillation Framework for Visual Recognition
Stars: ✭ 49 (-34.67%)
Mutual labels:  self-supervised-learning
Self-Supervised-Embedding-Fusion-Transformer
The code for our IEEE ACCESS (2020) paper Multimodal Emotion Recognition with Transformer-Based Self Supervised Feature Fusion.
Stars: ✭ 57 (-24%)
Mutual labels:  self-supervised-learning

SimCLR-in-TensorFlow-2

(Minimally) implements SimCLR (A Simple Framework for Contrastive Learning of Visual Representations by Chen et al.) in TensorFlow 2. Uses many delicious pieces of tf.keras and TensorFlow's core APIs. A report is available here.

Acknowledgements

I did not code everything from scratch. This particular research paper felt super amazing to read and often felt natural to understand, that's why I wanted to try it out myself and come up with a minimal implementation. I reused the works of the following for different purposes -

Following are the articles I studied for understanding SimCLR other than the paper:

Thanks a ton to the ML-GDE program for providing the GCP Credits using which I could run the experiments, store the intermediate results on GCS buckets as necessary. All the notebooks can be run on Colab though.

Dataset

Architecture

Model: "model"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
input_2 (InputLayer)         [(None, 224, 224, 3)]     0
_________________________________________________________________
resnet50 (Model)             (None, 7, 7, 2048)        23587712
_________________________________________________________________
global_average_pooling2d (Gl (None, 2048)              0
_________________________________________________________________
dense (Dense)                (None, 256)               524544
_________________________________________________________________
activation (Activation)      (None, 256)               0
_________________________________________________________________
dense_1 (Dense)              (None, 128)               32896
_________________________________________________________________
activation_1 (Activation)    (None, 128)               0
_________________________________________________________________
dense_2 (Dense)              (None, 50)                6450
=================================================================
Total params: 24,151,602
Trainable params: 24,098,482
Non-trainable params: 53,120

Contrastive learning progress

Training with 10% training data using the learned representations (linear evaluation)

loss: 1.1009 - accuracy: 0.5840 - val_loss: 1.1486 - val_accuracy: 0.5280

This is when I only took the base encoder network i.e. without any non-linear projections. I presented results with different projection heads as well (available here) but this one came to be the best.

Learned representations with TSNE

This is when I only took the base encoder network i.e. without any non-linear projections. I presented results with different projection heads as well (available here) but this one came to be the best.

Supervised training with the full training dataset

Here's the architecture that was used:


Model: "model"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
input_4 (InputLayer)         [(None, 224, 224, 3)]     0
_________________________________________________________________
resnet50 (Model)             (None, 7, 7, 2048)        23587712
_________________________________________________________________
global_average_pooling2d_1 ( (None, 2048)              0
_________________________________________________________________
dense_1 (Dense)              (None, 256)               524544
_________________________________________________________________
activation (Activation)      (None, 256)               0
_________________________________________________________________
dense_2 (Dense)              (None, 5)                 1285
=================================================================
Total params: 24,113,541
Trainable params: 24,060,421
Non-trainable params: 53,120

loss: 0.6623 - accuracy: 0.7528 - val_loss: 1.0171 - val_accuracy: 0.6440

We see a 12% increase here. The accuracy with the SimCLR framework could further be increased with better pre-training in terms of the following aspect:

  • More unsupervised data. If we could gather a larger corpurs of images for the pre-training task (think of ImageNet) that would have definitely helped.
  • I only trained using the SimCLR framework for 200 epochs. Longer training could have definitely helped.
  • Architectural considerations and hyperparameter tuning:
    • Temperature (tau) (I used 0.1)
    • Mix and match between the different augmentation policies shown in the paper and the strength of the color distortion.
    • Different projection heads.

SimCLR benefits from larger data. Ting Chen (the first author of the paper) suggested to go for an augmentation policy (when using custom datasets) that's not too easy nor too hard for the contrastive task i.e. the contrastive accuracy should be high (e.g. > 80%).

Pre-trained weights

Available here - Pretrained_Weights.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].