torchility
A Pytorch-lightning based tool for training pytorch deep learning model more simply.
Install
pip install torchility
Dependency
- pytorch>=2.0
- pytorch-lightning>=2.0,<2.1
- torchmetrics>=0.11,<0.12
- matplotlib>=3.3
- pyyaml>=5.4
- tensorboardX>=2.6
Usage
Example
- MNIST
from torchility import Trainer
import torch
from torch import nn
from torch.nn import functional as F
from torchvision.datasets import MNIST
from torchvision import transforms
from torch.utils.data import DataLoader, random_split
import warnings
warnings.simplefilter("ignore") # ignore annoying warnings
# datasets
data_dir = './datasets'
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))])
mnist_full = MNIST(data_dir, train=True, transform=transform, download=True)
train_ds, val_ds = random_split(mnist_full, [55000, 5000])
test_ds = MNIST(data_dir, train=False, transform=transform, download=True)
# dataloaders
train_dl = DataLoader(train_ds, batch_size=32)
val_dl = DataLoader(val_ds, batch_size=32)
test_dl = DataLoader(test_ds, batch_size=32)
# pytorch model
channels, width, height = (1, 28, 28)
model = nn.Sequential(
nn.Flatten(),
nn.Linear(channels * width * height, 64),
nn.ReLU(),
nn.Dropout(0.1),
nn.Linear(64, 64),
nn.ReLU(),
nn.Dropout(0.1),
nn.Linear(64, 10)
)
# optimizer
opt = torch.optim.Adam(model.parameters(), lr=2e-4)
# trainer
trainer = Trainer(model, F.cross_entropy, opt, epochs=2)
# train and validate
trainer.fit(train_dl, val_dl)
# test
trainer.test(test_dl)
- See the
examplesfor more examples
Data Flow
Metadata
Release files for torchility 0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torchility-0.9.tar.gz | 23.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torchility-0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.7 kB
Release files / torchility-0.9.tar.gz
| Download URL | torchility-0.9.tar.gz |
|---|---|
| Size | 23.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
033b36b5f3f417017748cf5daec02b5867ff63979a8d40c34240243a4f85b097
|
|
BLAKE2b-256 checksum How to use checksums |
28ba79480521e63d5865dc164c1c3d47489a40f8c67a6c40ec26e22ba60cccab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / torchility-0.9-py3-none-any.whl
| Download URL | torchility-0.9-py3-none-any.whl |
|---|---|
| Size | 28.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e121e57114ba432d69ca82d190dd926fe22bd0d3796f9af476cf8ac2a7ce149
|
|
BLAKE2b-256 checksum How to use checksums |
98ac915f036c8d7dd95d3274b5bbc28511b49fa42982985f9eb3f37a75b73532
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|