Code Monkey home page Code Monkey logo

lightning-semi-supervised-learning's Introduction

Semi Supervised Learning with PyTorch Lightning

This project aims to use PyTorch Lightning to implement state-of-the-art algorithms in semi-supervised leanring (SSL).

Semi-Supervised Learning

The semi-supervised learning is to leverage abundant unlabeled samples to improve models under the the scenario of scarce data. There are several assumptions which are usually used in semi-supervised learning,

  • Smoothness assumption
  • Low-density assumption
  • Manifold assumption

Most of the approaches try to exploit regularization on models to satisfy the assumptions. In this repository, we will first focus on methods using consistency loss.

What is PyTorch Lightning

PyTorch Lightning is a PyTorch Wrapper to standardize the training and testing process of AI projects. The projects using PyTorch Lightning can focus on the implementation of the algorithm, and there is no need to worry about some complicated engineering parts, such as multi-GPU training, 16-bit precision, Tensorboard logging, and TPU training.

In this project, we leverage PyTorch Lightning as the coding backbone and implement algorithms with minimum changes. The necessary implementation of a new algorithm is put in module.

Requirements

pip install -r requirements.txt

Module Flow

  • configs: Contained the config files for approaches.
  • models: Contained all the models.
  • dataloader: Data loader for every dataset.
  • module: SSL modules inherited pytorch_lightning.LightningModule.

To implement a new method, one usually need to define new config, data loader and PL module.

Usage

  • Please refer to argparser.py for hyperparameters.
  • read_from_tb.py is used to extract the final accuracies from tensorboard logs.

Fully-Supervised Training

python main.py -c configs/config_mixup.ini -g [GPU ID] --affix [FILE NAME]

Train for Mixmatch

python main.py -c configs/config_mixmatch.ini -g [GPU ID] --num_labeled [NUMBER OF UNLABELED DATA] --affix [FILE NAME]

Results

Supervised Training

The result is the average of three runs (seed=1, 2, 3).

Acc
full train with mixup 4.41±0.03

Mixmatch

The experiments run for five times (seed=1,2,3,4,5) in the paper, but only three times (seed=1,2,3) for this implementation.

time (hr:min) 250 500 1000 2000 4000
Paper 11.08±0.87 9.65±0.94 7.75±0.32 7.03±0.15 6.24±0.06
Reproduce 17:24 10.93±1.20 9.72±0.63 8.02±0.74 - -
This repo 17:40 11.10±1.00 10.05±0.45 8.00±0.42 7.13±0.13 6.22±0.08

Plans

  1. Remixmatch
  2. Fixmatch
  3. GAN based method (DSGAN, BadGAN)
  4. Other approach using consistency loss (VAT, mean teacher)
  5. Polish the code for CustomSemiDataset in data_loader/base_data.py

lightning-semi-supervised-learning's People

Contributors

ylsung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lightning-semi-supervised-learning's Issues

Do you have any idea of implementing mean teacher with pytorch lightning?

I am confusing of how to implement it, specially forward method.

In torch:

x_semi = get_semi_data()
y_semi = self.teahcer(x_semi).detach()

x, label = get_data()
y = self.student(x)
y_pred = self.student(x_semi)

cost = loss(label, y) + loss(y_semi, y_pred)
cost.backward()

update_ema(self.teahcer, self.student)

how about pytorch lightning?

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.