Skip to main content

A collection of PyTorch utilities designed to streamline the deep learning workflows

Project description

PowerTorch

A collection of PyTorch utilities designed to streamline the deep learning workflows

Getting Started

Installation

You can install the library directly from the repository:

pip install git+https://github.com/yutingshih/powertorch.git

Alternatively, clone the repository and manually install the dependencies:

git clone https://github.com/yutingshih/powertorch.git
cd nth
pip install -r requirements.txt

Quick Test

To verify the installation, run the MNIST example:

python3 -m examples.mnist

Usage

Import Package

from powertorch import helper
from powertorch import models

Prepare Data

trainloader, validloader = helper.prepare_data(
    source=torchvision.datasets.MNIST,
    train=True,
    batch_size=256,
    transform=transforms.ToTensor(),
    splits=[0.8, 0.2],
)

testloader = helper.prepare_data(
    source=torchvision.datasets.MNIST,
    train=False,
    batch_size=256,
    transform=transforms.ToTensor(),
)

Define a Training Task

losses = []
def train_step(batch, index, epoch):
    net.train()
    optimizer.zero_grad()
    inputs, labels = [i.to(device) for i in batch]
    outputs = net(inputs)
    loss = criterion(outputs, labels)
    loss.backward()
    optimizer.step()
    losses.append(loss.item())

trainer = helper.Task(train_step)
trainer.run(trainloader, max_epochs=max_epochs)

Register Event Handlers

Show Progress

trainer = helper.Task(train_step)
trainer.add_event_handler(helper.Event.ITERATION_STARTED,
    lambda: print(f'Progress: {trainer.state.batch}/{len(trainloader)}', end='\r'))
trainer.run(trainloader, max_epochs=max_epochs)

Evaluate Model

def evaluate_model(dataloader):
    # (skip) ...

trainer = helper.Task(train_step)
trainer.add_event_handler(helper.Event.EPOCH_COMPLETED, evaluate_model, testloader)
trainer.run(trainloader, max_epochs=max_epochs)

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

powertorch-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

powertorch-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file powertorch-0.1.0.tar.gz.

File metadata

  • Download URL: powertorch-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for powertorch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ced57dbf94100cbb7f2d40c3f05accb3be136b85b53aab7f9417dea73b93e98
MD5 7abf6ef05bbc38db9fc73706dc96f380
BLAKE2b-256 b182408f5fff0b12cafb6de92ce3da8596fefef96d466ab30f69c59940909e66

See more details on using hashes here.

File details

Details for the file powertorch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: powertorch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for powertorch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b197cd99568ca991e92f9c23720b6cd2948343271dca3f328b288902b42d868
MD5 13819e663c05058106ed74453ae9fa9d
BLAKE2b-256 b7d813abc28e0f2b3c11ed221e8fd4b8cf19fa749be3b8307dc45b485f1e43d6

See more details on using hashes here.

Supported by

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