# 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
```python
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 `examples` for more examples
### Data Flow
<img src="imgs/data_flow.png" width="60%" alt="https://github.com/hitlic/torchility"/>
Raw data
{
"_id": null,
"home_page": "https://github.com/hitlic/torchility",
"name": "torchility",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "hitlic",
"author_email": "liuchen.lic@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/28/ba/79480521e63d5865dc164c1c3d47489a40f8c67a6c40ec26e22ba60cccab/torchility-0.9.tar.gz",
"platform": null,
"description": "# torchility\r\n\r\nA Pytorch-lightning based tool for training pytorch deep learning model more simply.\r\n\r\n## Install\r\n\r\n- `pip install torchility`\r\n### Dependency\r\n- pytorch>=2.0\r\n- pytorch-lightning>=2.0,<2.1\r\n- torchmetrics>=0.11,<0.12\r\n- matplotlib>=3.3\r\n- pyyaml>=5.4\r\n- tensorboardX>=2.6\r\n\r\n## Usage\r\n\r\n### Example\r\n\r\n- MNIST\r\n\r\n```python\r\nfrom torchility import Trainer\r\nimport torch\r\nfrom torch import nn\r\nfrom torch.nn import functional as F\r\nfrom torchvision.datasets import MNIST\r\nfrom torchvision import transforms\r\nfrom torch.utils.data import DataLoader, random_split\r\nimport warnings\r\nwarnings.simplefilter(\"ignore\") # ignore annoying warnings\r\n\r\n# datasets\r\ndata_dir = './datasets'\r\ntransform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))])\r\nmnist_full = MNIST(data_dir, train=True, transform=transform, download=True)\r\ntrain_ds, val_ds = random_split(mnist_full, [55000, 5000])\r\ntest_ds = MNIST(data_dir, train=False, transform=transform, download=True)\r\n\r\n# dataloaders\r\ntrain_dl = DataLoader(train_ds, batch_size=32)\r\nval_dl = DataLoader(val_ds, batch_size=32)\r\ntest_dl = DataLoader(test_ds, batch_size=32)\r\n\r\n# pytorch model\r\nchannels, width, height = (1, 28, 28)\r\nmodel = nn.Sequential(\r\n nn.Flatten(),\r\n nn.Linear(channels * width * height, 64),\r\n nn.ReLU(),\r\n nn.Dropout(0.1),\r\n nn.Linear(64, 64),\r\n nn.ReLU(),\r\n nn.Dropout(0.1),\r\n nn.Linear(64, 10)\r\n)\r\n\r\n# optimizer\r\nopt = torch.optim.Adam(model.parameters(), lr=2e-4)\r\n# trainer\r\ntrainer = Trainer(model, F.cross_entropy, opt, epochs=2)\r\n# train and validate\r\ntrainer.fit(train_dl, val_dl)\r\n# test\r\ntrainer.test(test_dl)\r\n```\r\n\r\n- See the `examples` for more examples \r\n\r\n### Data Flow\r\n\r\n<img src=\"imgs/data_flow.png\" width=\"60%\" alt=\"https://github.com/hitlic/torchility\"/>\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "",
"version": "0.9",
"project_urls": {
"Homepage": "https://github.com/hitlic/torchility"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "98ac915f036c8d7dd95d3274b5bbc28511b49fa42982985f9eb3f37a75b73532",
"md5": "43675649e1d977b9e4f4aff264172123",
"sha256": "8e121e57114ba432d69ca82d190dd926fe22bd0d3796f9af476cf8ac2a7ce149"
},
"downloads": -1,
"filename": "torchility-0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "43675649e1d977b9e4f4aff264172123",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 28057,
"upload_time": "2023-12-02T04:53:32",
"upload_time_iso_8601": "2023-12-02T04:53:32.220493Z",
"url": "https://files.pythonhosted.org/packages/98/ac/915f036c8d7dd95d3274b5bbc28511b49fa42982985f9eb3f37a75b73532/torchility-0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "28ba79480521e63d5865dc164c1c3d47489a40f8c67a6c40ec26e22ba60cccab",
"md5": "b5333893f3f708f74a2127e1fb23cc36",
"sha256": "033b36b5f3f417017748cf5daec02b5867ff63979a8d40c34240243a4f85b097"
},
"downloads": -1,
"filename": "torchility-0.9.tar.gz",
"has_sig": false,
"md5_digest": "b5333893f3f708f74a2127e1fb23cc36",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 23675,
"upload_time": "2023-12-02T04:53:34",
"upload_time_iso_8601": "2023-12-02T04:53:34.865675Z",
"url": "https://files.pythonhosted.org/packages/28/ba/79480521e63d5865dc164c1c3d47489a40f8c67a6c40ec26e22ba60cccab/torchility-0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-02 04:53:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hitlic",
"github_project": "torchility",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "torchility"
}