Git Product home page Git Product logo

atharva-phatak / torchflare Goto Github PK

View Code? Open in Web Editor NEW
84.0 4.0 7.0 18.51 MB

TorchFlare is a simple, beginner-friendly, and easy-to-use PyTorch Framework train your models effortlessly.

Home Page: https://torchflare.readthedocs.io/en/latest/

License: Apache License 2.0

Python 100.00%
deep-learning pytorch python deep-neural-networks image-classification infrastructure natural-language-processing text-classification image-processing image-segmentation

torchflare's Introduction

image

PyPI API GitHub release (latest by date) CodeFactor Test Documentation Status Publish-PyPI DeepSource DeepSource codecov made-with-python GitHub license Code style: black

TorchFlare

TorchFlare is a simple, beginner-friendly and an easy-to-use PyTorch Framework to train your models with ease. It provides an almost Keras-like experience for training your models with all the callbacks, metrics, etc

Features

  • A high-level module for Keras-like training.
  • Flexibility to write custom training and validation loops for advanced use cases.
  • Off-the-shelf Pytorch style Datasets/Dataloaders for standard tasks such as Image classification, Image segmentation, Text Classification, etc
  • Callbacks for model checkpoints, early stopping, and much more!
  • TorchFlare uses powerful torchmetrics in the backend for metric computations!
  • Reduction of the boiler plate code required for training your models.
  • Create interactive UI for model prototyping and POC

Currently, TorchFlare supports CPU and GPU training. DDP and TPU support will be coming soon!


Installation

pip install torchflare

Documentation

The Documentation is available here


Getting Started

The core idea around TorchFlare is the Experiment class. It handles all the internal stuff like boiler plate code for training, calling callbacks,metrics,etc. The only thing you need to focus on is creating you PyTorch Model.

Also, there are off-the-shelf pytorch style datasets/dataloaders available for standard tasks, so that you don't have to worry about creating Pytorch Datasets/Dataloaders.

Here is an easy-to-understand example to show how Experiment class works.

import torch
import torchmetrics
import torch.nn as nn
from torchflare.experiments import Experiment, ModelConfig
import torchflare.callbacks as cbs

# Some dummy dataloaders
train_dl = SomeTrainingDataloader()
valid_dl = SomeValidationDataloader()
test_dl = SomeTestingDataloader()

Create a pytorch Model

class Net(nn.Module):
    def __init__(self, n_classes, p_dropout):
        super().__init__()
        self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
        self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
        self.conv2_drop = nn.Dropout2d(p=p_dropout)
        self.fc1 = nn.Linear(320, 50)
        self.fc2 = nn.Linear(50, n_classes)

    def forward(self, x):
        x = F.relu(F.max_pool2d(self.conv1(x), 2))
        x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))
        x = x.view(-1, 320)
        x = F.relu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        return x

Define callbacks and metrics

metric_list = [
    torchmetrics.Accuracy(num_classes=num_classes)
]

callbacks = [
    cbs.EarlyStopping(monitor="val_accuracy", mode="max"),
    cbs.ModelCheckpoint(monitor="val_accuracy"),
    cbs.ReduceLROnPlateau(mode="max", patience=2),
]

Define Model Configuration

#Defining Model Config for experiment.
config = ModelConfig(
    nn_module=Net,
    module_params={"n_classes": 10, "p_dropout": 0.3},
    optimizer="Adam",
    optimizer_params={"lr": 3e-4},
    criterion="cross_entropy",
)

Define your experiment

# Set some constants for training
exp = Experiment(
    num_epochs=5,
    fp16=False,
    device="cuda",
    seed=42,
)

exp.compile_experiment(
    model_config=config,
    callbacks=callbacks,
    metrics=metric_list,
    main_metrics="accuracy",
)
# Run your experiment with training dataloader and validation dataloader.
exp.fit_loader(train_dl=train_dl, valid_dl=valid_dl)

For inference, you can use infer method, which yields output per batch. You can use it as follows

outputs = []
for op in exp.predict_on_loader(
    test_loader=test_dl, path_to_model="./models/model.bin", device="cuda"
):
    op = some_post_process_function(op)
    outputs.extend(op)

If you want to access your experiments history or get as a dataframe. You can do it as follows.

history = exp.history  # This will return a dict
exp.get_logs()  # This will return a dataframe constructed from model-history.

Examples


Contributions

To contribute please refer to Contributing Guide


Current Contributors


Author

Citation

Please use this bibtex if you want to cite this repository in your publications:

@misc{TorchFlare,
    author = {Atharva Phatak},
    title = {TorchFlare: Easy model training and experimentation.},
    year = {2020},
    publisher = {GitHub},
    journal = {GitHub repository},
    howpublished = {\url{https://github.com/Atharva-Phatak/torchflare}},
}

torchflare's People

Contributors

atharva-phatak avatar deepsourcebot avatar dependabot-preview[bot] avatar dependabot[bot] avatar imgbotapp avatar pre-commit-ci[bot] avatar thesuranaverse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

torchflare's Issues

Addition of Sklearn metrics

Proposal

  • Create wrapper for sklearn metrics in such a manner that it follows the same structure as metrics already implemented in torchflare.
    1280px-Scikit_learn_logo_small.svg.png

Add DDP support + Major Fixes

Description of Feature

Right now the library is working well but we can improve it further by adding HuggingFace accelerate to handle the DDP steps.
There are few things which should be deprecated

  1. Dataloading systems -> We can use data-pipe by PyTorch (create a contrib version of library)
  2. Fix one logging system -> MLFlow looks like the go-to tool for logging and other services
  3. Remove support of radio
  4. More structured tests would do good.
  5. Fix CI/CD

Addition of Object Detection Pipeline

  • Implement a complete pipeline that supports the object detection model available in torchvision.
  • Implement a dataset class which will process the data in required formats.

Update to Torch 2.9

Description of Feature

Torch 2.0 is blazing fast lets update the versions

Why should the feature be added ?

Pitch

A clear description of what you want to happen.

Alternatives

Additional context

Add Tutorials

  • Add tutorials for Crossvalidation and other stuff.
  • Build Binder/colab for existing tutorials.
  • Test torchflare on kaggle and colab.

icons8-youtube-tutorials-200.png

Integrate hugging face accelerate as the backend for DDP and TPU training

Description of Feature

As I can see torchflare is currently supports only CPU and a single GPU for training, but I think we could use hugging face accelerate to scale it to DDP and TPU

Why should the feature be added ?

To train bigger and complex models

Pitch

A clear description of what you want to happen.

Alternatives

Additional context

Implementation Of Progress Bar

  • Currently torchflare relies of fastprogress package for its progress bar, thus adding additional dependency.

Proposal

Implement a custom progress bar for torchflare which is effective and efficiently conveys the metrics.

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.