All Projects → vballoli → Nfnets Pytorch

vballoli / Nfnets Pytorch

Licence: mit
NFNets and Adaptive Gradient Clipping for SGD implemented in PyTorch

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Nfnets Pytorch

Conditional Pixelcnn Decoder
Tensorflow implementation of Gated Conditional Pixel Convolutional Neural Network
Stars: ✭ 479 (+122.79%)
Mutual labels:  paper, deepmind
neural network papers
记录一些读过的论文,给出个人对论文的评分情况并简述论文insight
Stars: ✭ 152 (-29.3%)
Mutual labels:  paper, image-classification
Igcv3
Code and Pretrained model for IGCV3
Stars: ✭ 191 (-11.16%)
Mutual labels:  image-classification
Transfer Learning Suite
Transfer Learning Suite in Keras. Perform transfer learning using any built-in Keras image classification model easily!
Stars: ✭ 212 (-1.4%)
Mutual labels:  image-classification
Dataturks
ML data annotations made super easy for teams. Just upload data, add your team and build training/evaluation dataset in hours.
Stars: ✭ 200 (-6.98%)
Mutual labels:  image-classification
Nude.js
Nudity detection with JavaScript and HTMLCanvas
Stars: ✭ 2,236 (+940%)
Mutual labels:  image-classification
Group Normalization Tensorflow
A TensorFlow implementation of Group Normalization on the task of image classification
Stars: ✭ 205 (-4.65%)
Mutual labels:  image-classification
Hustpapertemp
华中科技大学本科毕业论文LaTeX模板 2017
Stars: ✭ 189 (-12.09%)
Mutual labels:  paper
Pixel level land classification
Tutorial demonstrating how to create a semantic segmentation (pixel-level classification) model to predict land cover from aerial imagery. This model can be used to identify newly developed or flooded land. Uses ground-truth labels and processed NAIP imagery provided by the Chesapeake Conservancy.
Stars: ✭ 217 (+0.93%)
Mutual labels:  image-classification
Imageatm
Image classification for everyone.
Stars: ✭ 201 (-6.51%)
Mutual labels:  image-classification
Research In Production
A collection of research papers categorized by real-world systems that enact them
Stars: ✭ 205 (-4.65%)
Mutual labels:  paper
Drl4recsys
Courses on Deep Reinforcement Learning (DRL) and DRL papers for recommender systems
Stars: ✭ 196 (-8.84%)
Mutual labels:  paper
Paper
Paper is a fast NoSQL-like storage for Java/Kotlin objects on Android with automatic schema migration support.
Stars: ✭ 2,263 (+952.56%)
Mutual labels:  paper
Epg
Code for the paper "Evolved Policy Gradients"
Stars: ✭ 204 (-5.12%)
Mutual labels:  paper
Htmpapers
Numenta published papers code and data
Stars: ✭ 191 (-11.16%)
Mutual labels:  paper
Awesome Deeplearning Resources
Deep Learning and deep reinforcement learning research papers and some codes
Stars: ✭ 2,483 (+1054.88%)
Mutual labels:  paper
Beauty Net
A simple, flexible, and extensible template for PyTorch. It's beautiful.
Stars: ✭ 190 (-11.63%)
Mutual labels:  image-classification
Deep Learning With Python
Deep learning codes and projects using Python
Stars: ✭ 195 (-9.3%)
Mutual labels:  image-classification
Papers
Summaries of machine learning papers
Stars: ✭ 2,362 (+998.6%)
Mutual labels:  paper
Research Paper Notes
Notes and Summaries on ML-related Research Papers (with optional implementations)
Stars: ✭ 218 (+1.4%)
Mutual labels:  paper

PyTorch implementation of Normalizer-Free Networks and Adaptive Gradient Clipping

Python Package Docs

Paper: https://arxiv.org/abs/2102.06171.pdf

Original code: https://github.com/deepmind/deepmind-research/tree/master/nfnets

Do star this repository if it helps your work, and don't forget to cite if you use this code in your research!

Disclaimer: This technique only works with large datasets(as mentioned in the paper).

Installation

Install from PyPi:

pip3 install nfnets-pytorch

or install the latest code using:

pip3 install git+https://github.com/vballoli/nfnets-pytorch

Usage

WSConv2d

Use WSConv1d, WSConv2d, ScaledStdConv2d(timm) and WSConvTranspose2d like any other torch.nn.Conv2d or torch.nn.ConvTranspose2d modules.

import torch
from torch import nn
from nfnets import WSConv2d, WSConvTranspose2d, ScaledStdConv2d

conv = nn.Conv2d(3,6,3)
w_conv = WSConv2d(3,6,3)

conv_t = nn.ConvTranspose2d(3,6,3)
w_conv_t = WSConvTranspose2d(3,6,3)

Generic AGC (recommended)

import torch
from torch import nn, optim
from torchvision.models import resnet18

from nfnets import WSConv2d
from nfnets.agc import AGC # Needs testing

conv = nn.Conv2d(3,6,3)
w_conv = WSConv2d(3,6,3)

optim = optim.SGD(conv.parameters(), 1e-3)
optim_agc = AGC(conv.parameters(), optim) # Needs testing

# Ignore fc of a model while applying AGC.
model = resnet18()
optim = torch.optim.SGD(model.parameters(), 1e-3)
optim = AGC(model.parameters(), optim, model=model, ignore_agc=['fc'])

SGD - Adaptive Gradient Clipping

Similarly, use SGD_AGC like torch.optim.SGD

# The generic AGC is preferable since the paper recommends not applying AGC to the last fc layer.
import torch
from torch import nn, optim
from nfnets import WSConv2d, SGD_AGC

conv = nn.Conv2d(3,6,3)
w_conv = WSConv2d(3,6,3)

optim = optim.SGD(conv.parameters(), 1e-3)
optim_agc = SGD_AGC(conv.parameters(), 1e-3)

Using it within any PyTorch model

replace_conv replaces the convolution in your model with the convolution class and replaces the batchnorm with identity. While the identity is not ideal, it shouldn't cause a major difference in the latency.

import torch
from torch import nn
from torchvision.models import resnet18

from nfnets import replace_conv, WSConv2d, ScaledStdConv2d

model = resnet18()
replace_conv(model, WSConv2d) # This repo's original implementation
replace_conv(model, ScaledStdConv2d) # From timm

"""
class YourCustomClass(nn.Conv2d):
  ...
replace_conv(model, YourCustomClass)
"""

Docs

Find the docs at readthedocs

Cite Original Work

To cite the original paper, use:

@article{brock2021high,
  author={Andrew Brock and Soham De and Samuel L. Smith and Karen Simonyan},
  title={High-Performance Large-Scale Image Recognition Without Normalization},
  journal={arXiv preprint arXiv:},
  year={2021}
}

Cite this repository

To cite this repository, use:

@misc{nfnets2021pytorch,
  author = {Vaibhav Balloli},
  title = {A PyTorch implementation of NFNets and Adaptive Gradient Clipping},
  year = {2021},
  howpublished = {\url{https://github.com/vballoli/nfnets-pytorch}}
}

TODO

  • [x] WSConv2d
  • [x] SGD - Adaptive Gradient Clipping
  • [x] Function to automatically replace Convolutions in any module with WSConv2d
  • [x] Documentation
  • [x] Generic AGC wrapper.(See this comment for a reference implementation) (Needs testing for now)
  • [x] WSConvTranspose2d
  • [x] WSConv1d(Thanks to @shi27feng)
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].