A python package for visualization and storage management in a pytorch AI task.
Project description
torchtracer
torchtracer is a tool package for visualization and storage management in pytorch AI task.
Getting Started
PyTorch Required
This tool is developed for PyTorch AI task. Thus, PyTorch is needed of course.
Installing
You can use pip to install torchtracer.
pip install torchtracer
How to use?
Import torchtracer
from torchtracer import Tracer
Create an instance of Tracer
Assume that the root is ./checkpoints and current task id is lmmnb.
Avoiding messing working directory, you should make root directory manually.
tracer = Tracer('checkpoints').attach('lmmnb')
This step will create a directory checkpoints inside which is a directory lmmnb for current AI task.
Also, you could call .attach() without task id. Datetime will be used as task id.
tracer = Tracer('checkpoints').attach()
Saving config
Raw config should be a dict like this:
# `net` is a defined nn.Module
args = {'epoch_n': 120,
'batch_size': 10,
'criterion': nn.MSELoss(),
'optimizer': torch.optim.RMSprop(net.parameters(), lr=1e-3)}
The config dict should be wrapped with torchtracer.data.Config
cfg = Config(args)
tracer.store(cfg)
This step will create config.json in ./checkpoints/lmmnb/, which contains JSON information like this:
{
"epoch_n": 120,
"batch_size": 10,
"criterion": "MSELoss",
"optimizer": {
"lr": 0.001,
"momentum": 0,
"alpha": 0.99,
"eps": 1e-08,
"centered": false,
"weight_decay": 0,
"name": "RMSprop"
}
}
Logging
During the training iteration, you could print any information you want by using Tracer.log(msg, file).
If file not specified, it will output msg to ./checkpoints/lmmnb/log. Otherwise, it will be ./checkpoints/lmmnb/something.log.
tracer.log(msg='Epoch #{:03d}\ttrain_loss: {:.4f}\tvalid_loss: {:.4f}'.format(epoch, train_loss, valid_loss),
file='losses')
This step will create a log file losses.log in ./checkpoints/lmmnb/, which contains logs like:
Epoch #001 train_loss: 18.6356 valid_loss: 21.3882
Epoch #002 train_loss: 19.1731 valid_loss: 17.8482
Epoch #003 train_loss: 19.6756 valid_loss: 19.1418
Epoch #004 train_loss: 20.0638 valid_loss: 18.3875
Epoch #005 train_loss: 18.4679 valid_loss: 19.6304
...
Saving model
The model object should be wrapped with torchtracer.data.Model
If file not specified, it will generates model files model.txt. Otherwise, it will be somename.txt
tracer.store(Model(model), file='somename')
This step will create 2 files:
- description:
somename.txt
Sequential
Sequential(
(0): Linear(in_features=1, out_features=6, bias=True)
(1): ReLU()
(2): Linear(in_features=6, out_features=12, bias=True)
(3): ReLU()
(4): Linear(in_features=12, out_features=12, bias=True)
(5): ReLU()
(6): Linear(in_features=12, out_features=1, bias=True)
)
- parameters:
somename.pth
Saving matplotlib images
Use tracer.store(figure, file) to save matplotlib figure in images/
# assume that `train_losses` and `valid_losses` are lists of losses.
# create figure manually.
plt.plot(train_losses, label='train loss', c='b')
plt.plot(valid_losses, label='valid loss', c='r')
plt.title('Demo Learning on SQRT')
plt.legend()
# save figure. remember to call `plt.gcf()`
tracer.store(plt.gcf(), 'losses.png')
This step will save a png file losses.png representing losses curves.
Contribute
If you like this project, welcome to pull request & create issues.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchtracer-0.1.5.tar.gz.
File metadata
- Download URL: torchtracer-0.1.5.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84ed9692feb482b773a8b42de831ba9354b87b5a70f22083e754d22c521c6766
|
|
| MD5 |
4fbe15cd303ceceb5e216634300d9653
|
|
| BLAKE2b-256 |
32f503c6ad3300c0a1ce8942b4c4fe2c4c95a476097d6530c7eba9c2e99328e6
|
File details
Details for the file torchtracer-0.1.5-py3-none-any.whl.
File metadata
- Download URL: torchtracer-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a670dcdca2133df135fe9c333d58ffd31bdbaf97cc3032a5d48b8c450971de
|
|
| MD5 |
4d1098fe6b03d35cfa7d4b0e23fa519a
|
|
| BLAKE2b-256 |
3efd1654fa7452a7216caed4372170d7daf948db500feb285719bc9f00fa0188
|