Skip to main content

pthelper - PyTorch

A python package containing the basic boilerplate code for training and evaluation of PyTorch models. The main purpose of this package is to remove writing the same code for training/inference again and again for different projects.

Apart from training and evaluation, it also contains other helper functions to perform logging stats in the console as well as Keras like model summaries using torchinfo package.

Install

pip install pthelper

Usage

Utility functions

  • Print model details:
from pthelper import utils

model = PyTorchModel()
input_size = (4, 28*28)
device = torch.device('cpu')
utils.model_details(model, input_size, device)

model_summary

Model training and evaluation

  • Train the model:
import torch
import torch.nn as nn
from pthelper import trainer, utils

epochs = 5
model = PyTorchModel()
loss_fn = nn.BCEWithLogitsLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
logger = utils.get_logger()
pt_trainer = trainer.PTHelper(model, loss_fn, optimizer, logger, num_classes=1)
for i in range(epochs):
    train_loss = pt_trainer.train(train_dataloader, epoch=i)
    valid_loss, predictions, targets = pt_trainer.evaluate(valid_dataloader)

Scope

Right now, only binary and multi-class classification tasks are supported. In future releases, more functionality will be added like autoencoders, RNNs, GANs, etc.

Release files for pthelper 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pthelper 0.1.2
File Size Uploaded
pthelper-0.1.2.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pthelper 0.1.2
File Interpreter ABI Platform
pthelper-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / pthelper-0.1.2.tar.gz

Download URL pthelper-0.1.2.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6cea351d3e70fadbfbe48c6a64c1ae90ffb51bedf8f7258efe0db56985bc5984
BLAKE2b-256 checksum
How to use checksums
a9dc194f6598ed40d821f0e31204e134fe699d272f0a8285815a94f7f7ae8bca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.13

Release files / pthelper-0.1.2-py3-none-any.whl

Download URL pthelper-0.1.2-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3981e1ae4938d89dc2913d8d5660e6aaba3a15b0dac213c8e197b3a0c5aa39d
BLAKE2b-256 checksum
How to use checksums
7dd36447f071fb2713fdf27499eeffffda1e9dd1a2fb1868a6e3b91eab80696a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page