No project description provided
Project description
torchility
A tool for training pytorch deep learning model more simply which is based on Pytorch-lightning.
Dependency
- pytorch > 1.7
- pytorch-lightning > 1.1
Usage
- MNIST
from torchility import Trainer
import torch
from torch import nn
from torch.nn import functional as F
from torchvision.datasets import MNIST
from torch.utils.data import DataLoader, random_split
# datasets
mnist_full = MNIST(data_dir, train=True, download=True)
train_ds, val_ds = random_split(mnist_full, [55000, 5000])
test_ds = MNIST(data_dir, train=False, download=True)
# dataloaders
train_dl = DataLoader(train_ds, batch_size=32)
val_dl = DataLoader(val_ds, batch_size=32)
test_dl = DataLoader(val_ds, batch_size=32)
# pytorch model
model = nn.Sequential(
nn.Flatten(),
nn.Linear(28*28, 64),
nn.ReLU(),
nn.Linear(64, 64),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(64, 10)
)
# optimizer
opt = torch.optim.Adam(model.parameters(), lr=2e-4)
# trainer
trainer = Trainer()
# compile
trainer.compile(model, F.cross_entropy, opt)
# train and validate
trainer.fit(train_dl, val_dl, epochs=1)
# test
trainer.test(test_dl)
- See the
examples
for more examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torchility-0.1.2.2.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for torchility-0.1.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25f17b21dbb8b7837126b1731c60c459670b220fc7b48aa62e2b3f992bc948ba |
|
MD5 | ab8393d54c30780db021720075af179f |
|
BLAKE2b-256 | 938f3e6816d7af34b154a748afa3609d671694744651a5affe543d00c8f80c0c |