All Projects → miracleyoo → pytorch-lightning-template

miracleyoo / pytorch-lightning-template

Licence: Apache-2.0 license
An easy/swift-to-adapt PyTorch-Lighting template. 套壳模板,简单易用,稍改原来Pytorch代码,即可适配Lightning。You can translate your previous Pytorch code much easier using this template, and keep your freedom to edit all the functions as well. Big-project-friendly as well.

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pytorch-lightning-template

gestop
A tool to navigate the desktop with hand gestures. Builds on mediapipe.
Stars: ✭ 20 (-96.4%)
Mutual labels:  pytorch-lightning
hydra-zen
Pythonic functions for creating and enhancing Hydra applications
Stars: ✭ 165 (-70.27%)
Mutual labels:  pytorch-lightning
Transformer-QG-on-SQuAD
Implement Question Generator with SOTA pre-trained Language Models (RoBERTa, BERT, GPT, BART, T5, etc.)
Stars: ✭ 28 (-94.95%)
Mutual labels:  pytorch-lightning
disent
🧶 Modular VAE disentanglement framework for python built with PyTorch Lightning ▸ Including metrics and datasets ▸ With strongly supervised, weakly supervised and unsupervised methods ▸ Easily configured and run with Hydra config ▸ Inspired by disentanglement_lib
Stars: ✭ 41 (-92.61%)
Mutual labels:  pytorch-lightning
icedata
IceData: Datasets Hub for the *IceVision* Framework
Stars: ✭ 41 (-92.61%)
Mutual labels:  pytorch-lightning
hififace
Unofficial PyTorch Implementation for HifiFace (https://arxiv.org/abs/2106.09965)
Stars: ✭ 227 (-59.1%)
Mutual labels:  pytorch-lightning
classy
classy is a simple-to-use library for building high-performance Machine Learning models in NLP.
Stars: ✭ 61 (-89.01%)
Mutual labels:  pytorch-lightning
deepfillv2-pylightning
Clean minimal implementation of Free-Form Image Inpainting with Gated Convolutions in pytorch lightning. Inspired from pytorch implementation by @avalonstrel.
Stars: ✭ 13 (-97.66%)
Mutual labels:  pytorch-lightning
pl-dreamer
Simplistic Pytorch Implementation of the Dreamer-RL
Stars: ✭ 19 (-96.58%)
Mutual labels:  pytorch-lightning
deepaudio-speaker
neural network based speaker embedder
Stars: ✭ 19 (-96.58%)
Mutual labels:  pytorch-lightning
covid-mask-detector
Detect whether a person is wearing a mask or not
Stars: ✭ 102 (-81.62%)
Mutual labels:  pytorch-lightning
slp
Utils and modules for Speech Language and Multimodal processing using pytorch and pytorch lightning
Stars: ✭ 17 (-96.94%)
Mutual labels:  pytorch-lightning
ConSSL
PyTorch Implementation of SOTA SSL methods
Stars: ✭ 61 (-89.01%)
Mutual labels:  pytorch-lightning
ride
Training wheels, side rails, and helicopter parent for your Deep Learning projects in Pytorch
Stars: ✭ 18 (-96.76%)
Mutual labels:  pytorch-lightning
skillful nowcasting
Implementation of DeepMind's Deep Generative Model of Radar (DGMR) https://arxiv.org/abs/2104.00954
Stars: ✭ 117 (-78.92%)
Mutual labels:  pytorch-lightning
pytorch tempest
My repo for training neural nets using pytorch-lightning and hydra
Stars: ✭ 124 (-77.66%)
Mutual labels:  pytorch-lightning
Fast-AgingGAN
A deep learning model to age faces in the wild, currently runs at 60+ fps on GPUs
Stars: ✭ 133 (-76.04%)
Mutual labels:  pytorch-lightning
lightning-hydra-template
PyTorch Lightning + Hydra. A very user-friendly template for rapid and reproducible ML experimentation with best practices. ⚡🔥⚡
Stars: ✭ 1,905 (+243.24%)
Mutual labels:  pytorch-lightning
BrainMaGe
Brain extraction in presence of abnormalities, using single and multiple MRI modalities
Stars: ✭ 23 (-95.86%)
Mutual labels:  pytorch-lightning
VideoTransformer-pytorch
PyTorch implementation of a collections of scalable Video Transformer Benchmarks.
Stars: ✭ 159 (-71.35%)
Mutual labels:  pytorch-lightning

Pytorch-Lightning-Template

Chinese Version 中文版

Introduction

Pytorch-Lightning is a very convenient library. It can be seen as an abstraction and packaging of Pytorch. Its advantages are strong reusability, easy maintenance, clear logic, etc. The disadvantage is that it is too heavy and requires quite a bit of time to learn and understand. In addition, since it directly binds the model and the training code, it is not suitable for real projects with multiple model and dataset files. The same is true for the data module design. The strong coupling of things like DataLoader and custom Datasets also causes a similar problem: the same code is copied and pasted inelegantly here and there.

After much exploration and practice, I have summarized the following templates, which can also be a further abstraction of Pytorch-Lightning. In the first version, all the template content is under the root folder. However, after using it for more than a month, I found that more specified templates for different types of projects can boost coding efficiency. For example, classification and super-resolution tasks all have some fixed demand points. The project code can be implemented faster by directly modifying specialized templates, and some avoidable bugs have also been reduced.

**Currently, since this is still a new library, there are only these two templates. However, later as I apply it to other projects, new specialized templates will also be added. If you have used this template for your tasks (such as NLP, GAN, speech recognition, etc.), you are welcome to submit a PR so that you can integrate your template into the library for more people to use. If your task is not on the list yet, starting from the classification template is a good choice. Since most of the underlying logic and code of the templates are the same, this can be done very quickly. **

Everyone is welcome to try this set of code styles. It is quite convenient to reuse if you are used to it, and it is not easy to fall back into the hole. A more detailed explanation and a complete guide to Pytorch-Lightning can be found in the this article Zhihu blog.

File Structure

root-
	|-data
		|-__init__.py
		|-data_interface.py
		|-xxxdataset1.py
		|-xxxdataset2.py
		|-...
	|-model
		|-__init__.py
		|-model_interface.py
		|-xxxmodel1.py
		|-xxxmodel2.py
		|-...
	|-main.py
	|-utils.py

Installation

No installation is needed. Directly run git clone https://github.com/miracleyoo/pytorch-lightning-template.git to clone it to your local position. Choose your problem type like classification, and copy the corresponding template to your project directory.

Explanation of Structure

  • Thre are only main.py and utils.py in the root directory. The former is the entrance of the code, and the latter is a support file.

  • There is a __init__.py file in both data and modle folder to make them into packages. In this way, the import becomes easier.

  • Create a class DInterface(pl.LightningDataModule): in data_interface to work as the interface of all different customeized Dataset files. Corresponding Dataset class is imported in the __init__() function. Instantiation are done in the setup(), and train_dataloader, val_dataloader, test_dataloader functions are created.

  • Similarly, class class MInterface(pl.LightningModule): are created in model_interface to work as the interface of all your model files. Corresponding model class is imported in the __init__() function. The only things you need to modify in the interface is the functions like configure_optimizers, training_step, validation_step which control your own training process. One interface for all models, and the difference are handled in args.

  • main.py is only responsible for the following tasks:

    • Define parser, add parse items. (Attention: If there are some arguments which are supposed to be controled outside, like in the command line, you can directly add a parse item in main.py file. For example, there is a string argument called random_arg, you can add parser.add_argument('--random_arg', default='test', type=str) to the main.py file.) Two Interface class will automatically select and pass those arguments to the corresponding model/data class.
    • Choose the needed callback functions, like auto-save, Early Stop, and LR Scheduler。
    • Instantiate MInterface, DInterface, Trainer

Fin.

Attention

One thing that you need to pay attention to is, in order to let the MInterface and DInterface be able to parse your newly added models and datasets automatically by simply specify the argument --model_name and --dataset, we use snake case (like standard_net.py) for model/dataset file, and use the same content with camel case for class name, like StandardNet.

The same is true for data folder.

Although this seems restricting your naming of models and datasets, but it can also make your code easier to read and understand. Please pay attention to this point to avoid parsing issues.

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].