All Projects → lucidrains → Pixel Level Contrastive Learning

lucidrains / Pixel Level Contrastive Learning

Licence: mit
Implementation of Pixel-level Contrastive Learning, proposed in the paper "Propagate Yourself", in Pytorch

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pixel Level Contrastive Learning

Densepoint
DensePoint: Learning Densely Contextual Representation for Efficient Point Cloud Processing (ICCV 2019)
Stars: ✭ 110 (-9.09%)
Mutual labels:  artificial-intelligence
Awesome Robotic Tooling
Tooling for professional robotic development in C++ and Python with a touch of ROS, autonomous driving and aerospace.
Stars: ✭ 1,876 (+1450.41%)
Mutual labels:  artificial-intelligence
Nonautoreggenprogress
Tracking the progress in non-autoregressive generation (translation, transcription, etc.)
Stars: ✭ 118 (-2.48%)
Mutual labels:  artificial-intelligence
Blazingsql
BlazingSQL is a lightweight, GPU accelerated, SQL engine for Python. Built on RAPIDS cuDF.
Stars: ✭ 1,652 (+1265.29%)
Mutual labels:  artificial-intelligence
Owl Bt
owl-bt is editor for Behavior trees. It has been inspired by Unreal engine behavior trees in a way, that it supports special node items like decorators and services. This makes trees smaller and much more readable.
Stars: ✭ 112 (-7.44%)
Mutual labels:  artificial-intelligence
Spoken language identification
Identify a spoken language using artificial intelligence (LID).
Stars: ✭ 114 (-5.79%)
Mutual labels:  artificial-intelligence
Reflexityai
Provide a basic framework to build an Utility IA in Unity using the xNode editor of Siccity
Stars: ✭ 109 (-9.92%)
Mutual labels:  artificial-intelligence
Projects
Just for Learning ! ^-^ !
Stars: ✭ 120 (-0.83%)
Mutual labels:  artificial-intelligence
Xaynet
Xaynet represents an agnostic Federated Machine Learning framework to build privacy-preserving AI applications.
Stars: ✭ 111 (-8.26%)
Mutual labels:  artificial-intelligence
Gpflappybird
Flappy Bird AI using Cartesian Genetic Programming (Evolutionary Computation)
Stars: ✭ 117 (-3.31%)
Mutual labels:  artificial-intelligence
Bootcamp machine Learning
Bootcamp to learn basics in Machine Learning
Stars: ✭ 113 (-6.61%)
Mutual labels:  artificial-intelligence
Gini
A fast SAT solver
Stars: ✭ 112 (-7.44%)
Mutual labels:  artificial-intelligence
Tenginekit
TengineKit - Free, Fast, Easy, Real-Time Face Detection & Face Landmarks & Face Attributes & Hand Detection & Hand Landmarks & Body Detection & Body Landmarks & Iris Landmarks & Yolov5 SDK On Mobile.
Stars: ✭ 2,103 (+1638.02%)
Mutual labels:  artificial-intelligence
Awesome Causal Inference
A (concise) curated list of awesome Causal Inference resources.
Stars: ✭ 107 (-11.57%)
Mutual labels:  artificial-intelligence
Minebot
Minebot
Stars: ✭ 119 (-1.65%)
Mutual labels:  artificial-intelligence
Lanegcn
[ECCV2020 Oral] Learning Lane Graph Representations for Motion Forecasting
Stars: ✭ 110 (-9.09%)
Mutual labels:  artificial-intelligence
Arc
The Abstraction and Reasoning Corpus
Stars: ✭ 1,598 (+1220.66%)
Mutual labels:  artificial-intelligence
Modelchimp
Experiment tracking for machine and deep learning projects
Stars: ✭ 121 (+0%)
Mutual labels:  artificial-intelligence
Auto ml
[UNMAINTAINED] Automated machine learning for analytics & production
Stars: ✭ 1,559 (+1188.43%)
Mutual labels:  artificial-intelligence
Reinforcement Learning An Introduction
Python Implementation of Reinforcement Learning: An Introduction
Stars: ✭ 11,042 (+9025.62%)
Mutual labels:  artificial-intelligence

Pixel-level Contrastive Learning

Implementation of Pixel-level Contrastive Learning, proposed in the paper "Propagate Yourself", in Pytorch. In addition to doing contrastive learning on the pixel level, the online network further passes the pixel level representations to a Pixel Propagation Module and enforces a similarity loss to the target network. They beat all previous unsupervised and supervised methods in segmentation tasks.

Install

$ pip install pixel-level-contrastive-learning

Usage

Below is an example of how you would use the framework to self-supervise training of a resnet, taking the output of layer 4 (8 x 8 'pixels').

import torch
from pixel_level_contrastive_learning import PixelCL
from torchvision import models
from tqdm import tqdm

resnet = models.resnet50(pretrained=True)

learner = PixelCL(
    resnet,
    image_size = 256,
    hidden_layer_pixel = 'layer4',  # leads to output of 8x8 feature map for pixel-level learning
    hidden_layer_instance = -2,     # leads to output for instance-level learning
    projection_size = 256,          # size of projection output, 256 was used in the paper
    projection_hidden_size = 2048,  # size of projection hidden dimension, paper used 2048
    moving_average_decay = 0.99,    # exponential moving average decay of target encoder
    ppm_num_layers = 1,             # number of layers for transform function in the pixel propagation module, 1 was optimal
    ppm_gamma = 2,                  # sharpness of the similarity in the pixel propagation module, already at optimal value of 2
    distance_thres = 0.7,           # ideal value is 0.7, as indicated in the paper, which makes the assumption of each feature map's pixel diagonal distance to be 1 (still unclear)
    similarity_temperature = 0.3,   # temperature for the cosine similarity for the pixel contrastive loss
    alpha = 1.,                      # weight of the pixel propagation loss (pixpro) vs pixel CL loss
    use_pixpro = True,               # do pixel pro instead of pixel contrast loss, defaults to pixpro, since it is the best one
    cutout_ratio_range = (0.6, 0.8)  # a random ratio is selected from this range for the random cutout
).cuda()

opt = torch.optim.Adam(learner.parameters(), lr=1e-4)

def sample_batch_images():
    return torch.randn(10, 3, 256, 256).cuda()

for _ in tqdm(range(100000)):
    images = sample_batch_images()
    loss = learner(images) # if positive pixel pairs is equal to zero, the loss is equal to the instance level loss

    opt.zero_grad()
    loss.backward()
    print(loss.item())
    opt.step()
    learner.update_moving_average() # update moving average of target encoder

# after much training, save the improved model for testing on downstream task
torch.save(resnet, 'improved-resnet.pt')

You can also return the number of positive pixel pairs on forward, for logging or other purposes

loss, positive_pairs = learner(images, return_positive_pairs = True)

Citations

@misc{xie2020propagate,
    title={Propagate Yourself: Exploring Pixel-Level Consistency for Unsupervised Visual Representation Learning}, 
    author={Zhenda Xie and Yutong Lin and Zheng Zhang and Yue Cao and Stephen Lin and Han Hu},
    year={2020},
    eprint={2011.10043},
    archivePrefix={arXiv},
    primaryClass={cs.CV}
}
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].