{"id":15293018,"url":"https://github.com/oidiotlin/torchtracer","last_synced_at":"2025-04-11T12:11:24.737Z","repository":{"id":62584986,"uuid":"149237157","full_name":"OIdiotLin/torchtracer","owner":"OIdiotLin","description":"A python package for visualization and storage management in a pytorch AI task.","archived":false,"fork":false,"pushed_at":"2024-05-03T19:41:18.000Z","size":22,"stargazers_count":54,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T08:38:09.607Z","etag":null,"topics":["lab","machine-learning","pytorch","tools"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OIdiotLin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-18T06:08:07.000Z","updated_at":"2025-03-11T05:54:22.000Z","dependencies_parsed_at":"2024-08-03T12:01:16.135Z","dependency_job_id":null,"html_url":"https://github.com/OIdiotLin/torchtracer","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":0.09999999999999998,"last_synced_commit":"ca85c414b27e3edabaa2fea17ab9943fa668f952"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OIdiotLin%2Ftorchtracer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OIdiotLin%2Ftorchtracer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OIdiotLin%2Ftorchtracer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OIdiotLin%2Ftorchtracer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OIdiotLin","download_url":"https://codeload.github.com/OIdiotLin/torchtracer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248398318,"owners_count":21097291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lab","machine-learning","pytorch","tools"],"created_at":"2024-09-30T16:37:44.618Z","updated_at":"2025-04-11T12:11:24.717Z","avatar_url":"https://github.com/OIdiotLin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# torchtracer\n\n[![Build Status](https://travis-ci.com/OIdiotLin/torchtracer.svg?branch=master)](https://travis-ci.com/OIdiotLin/torchtracer)\n![](https://img.shields.io/badge/python-3.6-blue.svg)\n![](https://img.shields.io/badge/pytorch-0.4.1-orange.svg)\n\n`torchtracer` is a tool package for visualization and storage management in pytorch AI task.\n\n## Getting Started\n\n### PyTorch Required\n\nThis tool is developed for PyTorch AI task. Thus, PyTorch is needed of course.\n\n### Installing\n\nYou can use `pip` to install `torchtracer`.\n\n```bash\npip install torchtracer\n``` \n\n## How to use?\n\n### Import `torchtracer`\n\n```python\nfrom torchtracer import Tracer\n```\n\n### Create an instance of `Tracer`\n\nAssume that the root is `./checkpoints` and current task id is `lmmnb`.\n\n***Avoiding messing working directory, you should make root directory manually.***\n\n```python\ntracer = Tracer('checkpoints').attach('lmmnb')\n```\n\nThis step will create a directory `checkpoints` inside which is a directory `lmmnb` for current AI task.\n\nAlso, you could call `.attach()` without task id. **Datetime will be used as task id.**\n\n```python\ntracer = Tracer('checkpoints').attach()\n```\n\n### Saving config\n\nRaw config should be a `dict` like this:\n\n```python\n# `net` is a defined nn.Module\nargs = {'epoch_n': 120,\n        'batch_size': 10,\n        'criterion': nn.MSELoss(),\n        'optimizer': torch.optim.RMSprop(net.parameters(), lr=1e-3)}\n```\n\nThe config dict should be wrapped with `torchtracer.data.Config`\n\n```python\ncfg = Config(args)\ntracer.store(cfg)\n```\n\nThis step will create `config.json` in `./checkpoints/lmmnb/`, which contains JSON information like this:\n\n```json\n{\n  \"epoch_n\": 120,\n  \"batch_size\": 10,\n  \"criterion\": \"MSELoss\",\n  \"optimizer\": {\n    \"lr\": 0.001,\n    \"momentum\": 0,\n    \"alpha\": 0.99,\n    \"eps\": 1e-08,\n    \"centered\": false,\n    \"weight_decay\": 0,\n    \"name\": \"RMSprop\"\n  }\n}\n```\n\n### Logging\n\nDuring the training iteration, you could print any information you want by using `Tracer.log(msg, file)`.\n\nIf `file` not specified, it will output `msg` to `./checkpoints/lmmnb/log`. Otherwise, it will be `./checkpoints/lmmnb/something.log`.\n\n```python\ntracer.log(msg='Epoch #{:03d}\\ttrain_loss: {:.4f}\\tvalid_loss: {:.4f}'.format(epoch, train_loss, valid_loss),\n           file='losses')\n```\n\nThis step will create a log file `losses.log` in `./checkpoints/lmmnb/`, which contains logs like:\n\n```text\nEpoch #001\ttrain_loss: 18.6356\tvalid_loss: 21.3882\nEpoch #002\ttrain_loss: 19.1731\tvalid_loss: 17.8482\nEpoch #003\ttrain_loss: 19.6756\tvalid_loss: 19.1418\nEpoch #004\ttrain_loss: 20.0638\tvalid_loss: 18.3875\nEpoch #005\ttrain_loss: 18.4679\tvalid_loss: 19.6304\n...\n```\n\n### Saving model\n\nThe model object should be wrapped with `torchtracer.data.Model`\n\nIf `file` not specified, it will generates model files `model.txt`. Otherwise, it will be `somename.txt`\n\n```python\ntracer.store(Model(model), file='somename')\n```\n\nThis step will create 2 files: \n\n- **description**: `somename.txt`\n\n```text\nSequential\nSequential(\n  (0): Linear(in_features=1, out_features=6, bias=True)\n  (1): ReLU()\n  (2): Linear(in_features=6, out_features=12, bias=True)\n  (3): ReLU()\n  (4): Linear(in_features=12, out_features=12, bias=True)\n  (5): ReLU()\n  (6): Linear(in_features=12, out_features=1, bias=True)\n)\n```\n\n- **parameters**: `somename.pth`\n\n### Saving matplotlib images\n\nUse `tracer.store(figure, file)` to save matplotlib figure in `images/`\n\n```python\n# assume that `train_losses` and `valid_losses` are lists of losses. \n# create figure manually.\nplt.plot(train_losses, label='train loss', c='b')\nplt.plot(valid_losses, label='valid loss', c='r')\nplt.title('Demo Learning on SQRT')\nplt.legend()\n# save figure. remember to call `plt.gcf()`\ntracer.store(plt.gcf(), 'losses.png')\n```\n\nThis step will save a png file `losses.png` representing losses curves.\n\n### Progress bar for epochs\n\nUse `tracer.epoch_bar_init(total)` to initialize a progress bar.\n\n```python\ntracer.epoch_bar_init(epoch_n)\n```\n\nUse `tracer.epoch_bar.update(n=1, **params)` to update postfix of the progress bar.\n\n```python\ntracer.epoch_bar.update(train_loss=train_loss, valid_loss=train_loss)\n```\n\n```plain\n(THIS IS A DEMO) \nTracer start at /home/oidiotlin/projects/torchtracer/checkpoints\nTracer attached with task: rabbit\nEpoch: 100%|█████████| 120/120 [00:02\u003c00:00, 41.75it/s, train_loss=0.417, valid_loss=0.417]\n```\n\n**DO NOT FORGET TO CALL** `tracer.epoch_bar.close()` to finish the bar.\n\n## Contribute\n\nIf you like this project, welcome to pull request \u0026 create issues.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foidiotlin%2Ftorchtracer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foidiotlin%2Ftorchtracer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foidiotlin%2Ftorchtracer/lists"}