Skip to main content

A new library for Computer Vision

Project description

Pytorch_Fanatics

Pytorch_Fanatics is a Python library for ease of Computer Vision tasks.This contains a bunch of various tools which will help to create customized codes to train CV models.

###This library includes:

  • Dataset class
  • LRFinder
  • EarlyStopping
  • Trainer
  • Logger

Installation

Use the package manager pip to install pytorch_fanatics.

pip install pytorch_fanatics

Usage

1)Dataset Class

from pytorch_fanatics.dataloader import Cloader

Cloader(image_path,targets,resize,transforms) # returns {'image':tensor_image,'target':tensor_labels}
#Use it to load images and labels

2)LRFinder

from pytorch_fanatics.utils import LRFinder

lr_finder=LRFinder(model,train_dataloader,optimizer,device,initial_lr,final_lr,beta) #Create a object
lr_finder.find()       #To find the lr
lr_finder.plot()       #To plot the graph (Loss V/S lr)
#NOTE:
#Use this only after training the model with all layers (except the last) freezed.

3)EarlyStopping

from pytorch_fanatics.utils import EarlyStop

es=EarlyStop(patience=7, mode="max", delta=0.0001) #Create a object
es(epoch_score, model, path)
if es.early_stop=True:
	break
es.reset() # to reset

4)Trainer

from pytorch_fanatics.trainer import Trainer

Trainer.train(model,data_loader,optimizer,device) # trains the model

score=Trainer.evaluate(model,data_loader,device,scheduler=None,metric=metrics.accuracy_score,plot=True)
#Use the score to feed for earlystop if used
#plot=True specifies live plot b/w (training and validation) vs num_epochs

Trainer.predict(model,data_loader,device) # returns probability of classes

Trainer.get_log() #returns a DataFrame object of logs 
#Currently the metrics supported are f1_score,accuracy,precision,recall,roc_auc_score and log_loss
#We are working on other too ..

5)Logger

from pytorch_fanatics.logger import Logger

Logger.save(model,optimizer,scheduler,path)  # saves model,optimizer and schedulers

#To load:
checkpoint=Logger.load(path)  #returns a dictionary
model,optimizer,scheduler=checkpoint['model'],checkpoint['optimizer'],checkpoint['scheduler']

#Helps keep track of training.It will restart from where it had stopped.

NOTE(Regarding model)

class Resnet18(nn.Module):
    def __init__(self):
        super(Resnet18, self).__init__()
        self.base_model =timm.create_model('resnet18',pretrained=True,num_classes=1)
    def forward(self, image, targets):
        batch_size, _, _, _ = image.shape
        out = self.base_model(image)
        loss = nn.BCEWithLogitsLoss()(out.view(batch_size,), targets.type_as(out))
        return out, loss
#Since every loss function has its own format of inputs,To generalise I have created this model.Use this model(edit if required) if you are #using Trainer/LRFinder.For others your simple model will also work fine..

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

References

  • FastAi Documentations for LRFinder.
  • Pytorch Documentations.
  • Abhishek Thakur Sir's Github Project wtfml(Awesome work Have a look at it too).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytorch_fanatics-0.2.7.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

pytorch_fanatics-0.2.7-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pytorch_fanatics-0.2.7.tar.gz.

File metadata

  • Download URL: pytorch_fanatics-0.2.7.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/51.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for pytorch_fanatics-0.2.7.tar.gz
Algorithm Hash digest
SHA256 7fd36f10c7dc8d17b85f6cb004289ee42a3f910ef5f29b76d621a2295dd823f2
MD5 d12d9e8ce23b99553f86a05fcb38f971
BLAKE2b-256 74254dd58b43127a0835abfb0badb129f167ab0b5d30653f26351c2b11de7964

See more details on using hashes here.

File details

Details for the file pytorch_fanatics-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: pytorch_fanatics-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/51.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for pytorch_fanatics-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 94732da80407ea58a124d7bde38606639cf96b17a0b87158058d70b3369a253e
MD5 78014b3b905e7b79bfe5f23bbcd762e7
BLAKE2b-256 eebc290c8ed08ccf7fb04becf66651da07d4d05fbaf4f1d2f4949df312f950e8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page