# deep-trainer
[![Lint and Test](https://github.com/raphaelreme/deep-trainer/actions/workflows/tests.yml/badge.svg)](https://github.com/raphaelreme/deep-trainer/actions/workflows/tests.yml)
Baseline code to train deep neural networks.
Currently only available for PyTorch Framework.
## Install
### Pip
```bash
$ pip install deep-trainer
```
### Conda
Not yet available
## Getting started
```python
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` shows how to train a PreActResNet with Deep Trainer.
Install the additional requirements and use it with:
```bash
$ # 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.
Raw data
{
"_id": null,
"home_page": "https://github.com/raphaelreme/deep-trainer",
"name": "deep-trainer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "deep learning, pytorch",
"author": "Raphael Reme",
"author_email": "raphaelreme-dev@protonmail.com",
"download_url": "https://files.pythonhosted.org/packages/9f/22/df79a356781e66604d3f8078e55f0fca01159735bf3c9349b44ce2cc6eda/deep_trainer-0.1.5.tar.gz",
"platform": null,
"description": "# deep-trainer\n\n[![Lint and Test](https://github.com/raphaelreme/deep-trainer/actions/workflows/tests.yml/badge.svg)](https://github.com/raphaelreme/deep-trainer/actions/workflows/tests.yml)\n\nBaseline code to train deep neural networks.\nCurrently only available for PyTorch Framework.\n\n\n## Install\n\n### Pip\n\n```bash\n$ pip install deep-trainer\n```\n\n### Conda\n\nNot yet available\n\n\n## Getting started\n\n```python\nimport torch\nfrom deep_trainer import PytorchTrainer\n\n\n# Datasets\ntrainset = #....\nvalset = #....\ntestset = #....\n\n# Dataloaders\ntrain_loader = torch.utils.data.DataLoader(trainset, 64, shuffle=True)\nval_loader = torch.data.utils.DataLoader(valset, 256)\ntest_loader = torch.data.utils.DataLoader(testset, 256)\n\n# Model & device\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nmodel = #....\nmodel.to(device)\n\n# Optimizer & Scheduler\noptimizer = torch.optim.Adam(model.parameters(), lr=0.001)\nscheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=len(trainset) * 50, 0.1) # Decay by 10 every 50 epochs\n\n# Criterion\ncriterion = torch.nn.CrossEntropyLoss() # For classification for instance\n\n# Training\ntrainer = PytorchTrainer(model, optimizer, scheduler, save_mode=\"small\", device=device)\ntrainer.train(150, train_loader, criterion, val_loader=val_loader)\n\n# Testing\ntrainer.load(\"experiments/checkpoints/best.ckpt\")\ntrainer.evaluate(test_loader, criterion)\n```\n\n\n## Example\n\n`example/example.py` shows how to train a PreActResNet with Deep Trainer.\n\nInstall the additional requirements and use it with:\n\n```bash\n$ # See hyperparameters available\n$ python example.py -h\n$\n$ # Launch the default training\n$ python example.py\n$\n$ # Once done (or during the training), look for default tensorboard logs\n$ tensorboard --logdir experiments/logs/\n```\n\nThis script is reaching around 94-95% accuracy on validation with Cifar10 and a PreActResNet18.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Helper to train deep neural networks",
"version": "0.1.5",
"project_urls": {
"Homepage": "https://github.com/raphaelreme/deep-trainer"
},
"split_keywords": [
"deep learning",
" pytorch"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "78aec96369cd99f1d0081d3f7b4de2761ec09942223ed19975105b4626a4c5da",
"md5": "3e144d30d85eefea0483ac75e1f82433",
"sha256": "1a6835709b295794aab72a2a62f4c7b4f3e1390af759682885f0226a599233fd"
},
"downloads": -1,
"filename": "deep_trainer-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3e144d30d85eefea0483ac75e1f82433",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 15435,
"upload_time": "2024-08-05T11:49:28",
"upload_time_iso_8601": "2024-08-05T11:49:28.338681Z",
"url": "https://files.pythonhosted.org/packages/78/ae/c96369cd99f1d0081d3f7b4de2761ec09942223ed19975105b4626a4c5da/deep_trainer-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9f22df79a356781e66604d3f8078e55f0fca01159735bf3c9349b44ce2cc6eda",
"md5": "94d1c09bc58a7e3c8df2ec2a11051071",
"sha256": "ec0cea4b047c5578418aa90934df7baaf9878b7247813bde33b2b1a517eb9d7f"
},
"downloads": -1,
"filename": "deep_trainer-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "94d1c09bc58a7e3c8df2ec2a11051071",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 14729,
"upload_time": "2024-08-05T11:49:29",
"upload_time_iso_8601": "2024-08-05T11:49:29.798766Z",
"url": "https://files.pythonhosted.org/packages/9f/22/df79a356781e66604d3f8078e55f0fca01159735bf3c9349b44ce2cc6eda/deep_trainer-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-05 11:49:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "raphaelreme",
"github_project": "deep-trainer",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "deep-trainer"
}