Helper to train deep neural networks
Project description
deep-trainer
Baseline code to train deep neural networks. Currently only available for PyTorch Framework.
Install
Pip
$ pip install deep-trainer
Conda
Not yet available
Getting started
import torch
from deep_trainer import PytorchTrainer
# Datasets
trainset = #....
valset = #....
testset = #....
# Dataloaders
train_loader = torch.utils.data.DataLoader(trainset, 64, shuffle=True)
val_loader = torch.data.utils.DataLoader(valset, 256)
test_loader = torch.data.utils.DataLoader(testset, 256)
# Model & device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = #....
model.to(device)
# Optimizer & Scheduler
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=len(trainset) * 50, 0.1) # Decay by 10 every 50 epochs
# Criterion
criterion = torch.nn.CrossEntropyLoss() # For classification for instance
# Training
trainer = PytorchTrainer(model, optimizer, scheduler, save_mode="small", device=device)
trainer.train(150, train_loader, criterion, val_loader=val_loader)
# Testing
trainer.load("experiments/checkpoints/best.ckpt")
trainer.evaluate(test_loader, criterion)
Example
example/example.py
show how to train a PreActResNet with Deep Trainer.
Install the additional requirements and use it with:
$ # See hyperparameters available
$ python example.py -h
$
$ # Launch the default training
$ python example.py
$
$ # Once done (or during the training), look for default tensorboard logs
$ tensorboard --logdir experiments/logs/
This script is reaching around 94-95% accuracy on validation with Cifar10 and a PreActResNet18.
Here are the training logs:
Build and Deploy
$ pip install build twine
$ python -m build
$ python -m twine upload dist/*
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
deep-trainer-0.0.14.dev0.tar.gz
(12.9 kB
view hashes)
Built Distribution
Close
Hashes for deep_trainer-0.0.14.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75319e5d89f3da5da729d604205983a8d8991f7f2ef1c17ffca37dd61bc0e99f |
|
MD5 | e1e1c07c3de9a2a1eb551ef724965f4d |
|
BLAKE2b-256 | 68edfca21ca0804a2be07502f1fc869f2438386745f33596b7ca8d30808a6b67 |