All Projects โ†’ FrancescoSaverioZuppichini โ†’ Pytorch Deep Learning Template

FrancescoSaverioZuppichini / Pytorch Deep Learning Template

A Pytorch Computer Vision template to quick start your next project! ๐Ÿš€๐Ÿš€

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pytorch Deep Learning Template

Malware Detection
Malware Detection and Classification Using Machine Learning
Stars: โœญ 217 (-1.36%)
Mutual labels:  jupyter-notebook
Medical Ai Course Materials
ใƒกใƒ‡ใ‚ฃใ‚ซใƒซAIใ‚ณใƒผใ‚น ใ‚ชใƒณใƒฉใ‚คใƒณ่ฌ›็พฉ่ณ‡ๆ–™
Stars: โœญ 218 (-0.91%)
Mutual labels:  jupyter-notebook
Research Paper Notes
Notes and Summaries on ML-related Research Papers (with optional implementations)
Stars: โœญ 218 (-0.91%)
Mutual labels:  jupyter-notebook
Paddlehelix
Bio-Computing Platform featuring Large-Scale Representation Learning and Multi-Task Deep Learning โ€œ่žบๆ—‹ๆกจโ€็”Ÿ็‰ฉ่ฎก็ฎ—ๅทฅๅ…ท้›†
Stars: โœญ 213 (-3.18%)
Mutual labels:  jupyter-notebook
Latex ocr
๐Ÿ’Ž ๆ•ฐๅญฆๅ…ฌๅผ่ฏ†ๅˆซ
Stars: โœญ 218 (-0.91%)
Mutual labels:  jupyter-notebook
50 Days Of Ml
A day to day plan for this challenge (50 Days of Machine Learning) . Covers both theoretical and practical aspects
Stars: โœญ 218 (-0.91%)
Mutual labels:  jupyter-notebook
Tensorflow
Deep Learning Zero to All - Tensorflow
Stars: โœญ 216 (-1.82%)
Mutual labels:  jupyter-notebook
Weightwatcher
The WeightWatcher tool for predicting the accuracy of Deep Neural Networks
Stars: โœญ 213 (-3.18%)
Mutual labels:  jupyter-notebook
Tcdf
Temporal Causal Discovery Framework (PyTorch): discovering causal relationships between time series
Stars: โœญ 217 (-1.36%)
Mutual labels:  jupyter-notebook
Cardio
CardIO is a library for data science research of heart signals
Stars: โœญ 218 (-0.91%)
Mutual labels:  jupyter-notebook
How To Read Pytorch
Quick, visual, principled introduction to pytorch code through five colab notebooks.
Stars: โœญ 218 (-0.91%)
Mutual labels:  jupyter-notebook
Data Visualization
Data Visualization with Python
Stars: โœญ 217 (-1.36%)
Mutual labels:  jupyter-notebook
Ml Tutorial Experiment
Coding the Machine Learning Tutorial for Learning to Learn
Stars: โœญ 2,489 (+1031.36%)
Mutual labels:  jupyter-notebook
Python Sonic
Programming Music with Python, Sonic Pi and Supercollider
Stars: โœญ 217 (-1.36%)
Mutual labels:  jupyter-notebook
Gwu data mining
Materials for GWU DNSC 6279 and DNSC 6290.
Stars: โœญ 217 (-1.36%)
Mutual labels:  jupyter-notebook
Stock market prediction
This is the code for "Stock Market Prediction" by Siraj Raval on Youtube
Stars: โœญ 217 (-1.36%)
Mutual labels:  jupyter-notebook
Arima Lstm Hybrid Corrcoef Predict
Applied an ARIMA-LSTM hybrid model to predict future price correlation coefficients of two assets
Stars: โœญ 218 (-0.91%)
Mutual labels:  jupyter-notebook
Kitti Dataset
Visualising LIDAR data from KITTI dataset.
Stars: โœญ 217 (-1.36%)
Mutual labels:  jupyter-notebook
Python Awesome
Learn Python, Easy to learn, Awesome
Stars: โœญ 219 (-0.45%)
Mutual labels:  jupyter-notebook
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 (-1.36%)
Mutual labels:  jupyter-notebook

Pytorch Deep Learning Template

A clean and simple template to kick start your next dl project ๐Ÿš€๐Ÿš€

Francesco Saverio Zuppichini

In this article, we present you a deep learning template based on Pytorch. This template aims to make it easier for you to start a new deep learning computer vision project with PyTorch. The main features are:

  • modularity: we split each logic piece into a different python submodule
  • data-augmentation: we included imgaug
  • ready to go: by using poutyne a Keras-like framework you don't have to write any train loop.
  • torchsummary to show a summary of your models
  • reduce the learning rate on a plateau
  • auto-saving the best model
  • experiment tracking with comet
  • logging using python logging module
  • a playground notebook to quick test/play around

Installation

Clone the repo and go inside it. Then, run:

pip install -r requirements.txt

Motivation

Let's face it, usually data scientists are not software engineers and they usually end up with spaghetti code, most of the time on a big unusable Jupiter-notebook. With this repo, I have proposed a clean example of how your code should be split and modularized to make scalability and sharability possible. In this example, we will try to classify Darth Vader and Luke Skywalker. We have 100 images per class gathered using google images. The dataset is here. You just have to extract it in this folder and run main.py. We are fine-tuning resnet18 and it should be able to reach > 90% accuracy in 5/10 epochs.

Structure

The template is inside ./template.

.
โ”œโ”€โ”€ callbacks // here you can create your custom callbacks
โ”œโ”€โ”€ checkpoint // were we store the trained models
โ”œโ”€โ”€ data // here we define our dataset
โ”‚ โ””โ”€โ”€ transformation // custom transformation, e.g. resize and data augmentation
โ”œโ”€โ”€ dataset // the data
โ”‚ โ”œโ”€โ”€ train
โ”‚ โ””โ”€โ”€ val
โ”œโ”€โ”€ logger.py // were we define our logger
โ”œโ”€โ”€ losses // custom losses
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ models // here we create our models
โ”‚ โ”œโ”€โ”€ MyCNN.py
โ”‚ โ”œโ”€โ”€ resnet.py
โ”‚ โ””โ”€โ”€ utils.py
โ”œโ”€โ”€ playground.ipynb // a notebook that can be used to fast experiment with things
โ”œโ”€โ”€ Project.py // a class that represents the project structure
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ test // you should always perform some basic testing
โ”‚ โ””โ”€โ”€ test_myDataset.py
โ””โ”€โ”€ utils.py // utilities functions

We strongly encourage to play around with the template

Keep your structure clean and concise

Every deep learning project has at least three mains steps:

  • data gathering/processing
  • modeling
  • training/evaluating

Project

One good idea is to store all the paths at an interesting location, e.g. the dataset folder, in a shared class that can be accessed by anyone in the folder. You should never hardcode any paths and always define them once and import them. So, if you later change your structure you will only have to modify one file. If we have a look at Project.py we can see how we defined the data_dir and the checkpoint_dir once for all. We are using the 'new' Path APIs that support different OS out of the box, and also makes it easier to join and concatenate paths. alt For example, if we want to know the data location we can :

from Project import Project
project = Project() 
print(project.data_dir) # /foo/baa/โ€ฆ/dataset

Data

In the data package you can define your own Dataset, as always by subclassing torch.data.utils.Dataset, exposing transformations and utilities to work with your data. In our example, we directly used ImageDataset from torchvision but we included a skeleton for a custom Dataset in /data/MyDataset

Transformation

You usually have to do some preprocessing on the data, e.g. resize the images and apply data augmentation. All your transformation should go inside .data.trasformation. In our template, we included a wrapper for imgaug alt

Dataloaders

As you know, you have to create a Dataloader to feed your data into the model. In the data.__init__.py file we expose a very simple function get_dataloaders to automatically configure the train, val and test data loaders using few parameters alt

Losses

Sometimes you may need to define your custom losses, you can include them in the ./losses package. For example alt

Metrics

Sometimes you may need to define your custom metrics. For example alt

Logging

We included python logging module. You can import and use it by:

from logger import logging
logging.info('print() is for noobs')

Models

All your models go inside models, in our case, we have a very basic cnn and we override the resnet18 function to provide a frozen model to finetune.

alt

Train/Evaluation

In our case we kept things simple, all the training and evaluation logic is inside .main.py where we used poutyne as the main library. We already defined a useful list of callbacks:

  • learning rate scheduler
  • auto-save of the best model
  • early stopping Usually, this is all you need! alt

Callbacks

You may need to create custom callbacks, with poutyne is very easy since it support Keras-like API. You custom callbacks should go inside ./callbacks. For example, we have created one to update Comet every epoch. alt

Track your experiment

We are using comet to automatically track our models' results. This is what comet's board looks like after a few models run. alt Running main.py produces the following output: alt

Utils

We also created different utilities function to plot both dataset and dataloader. They are in utils.py. For example, calling show_dl on our train and val dataset produces the following outputs. alt alt As you can see data-augmentation is correctly applied on the train set

Conclusions

I hope you found some useful information and hopefully it this template will help you on your next amazing project :)

Let me know if you have some ideas/suggestions to improve it.

Thank you for reading

TODO

  • [ ] one example for lightning
  • [ ] one example with fastai
  • [ ] show how to setup anaconda
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].