{ "info": { "author": "OIdiotLin", "author_email": "oidiotlin@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# 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%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 120/120 [00:02<00: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 & create issues.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/OIdiotLin/torchtracer", "keywords": "", "license": "MIT License", "maintainer": "OIdiotLin", "maintainer_email": "oidiotlin@gmail.com", "name": "torchtracer", "package_url": "https://pypi.org/project/torchtracer/", "platform": "", "project_url": "https://pypi.org/project/torchtracer/", "project_urls": { "Homepage": "https://github.com/OIdiotLin/torchtracer" }, "release_url": "https://pypi.org/project/torchtracer/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "A python package for visualization and storage management in a pytorch AI task.", "version": "0.2.0" }, "last_serial": 4484801, "releases": { "0.1.4": [ { "comment_text": "", "digests": { "md5": "5f40cc4acc7da975d2ecfa79894279fe", "sha256": "8b7f34b655bff5975819d0cb97f711d3de4a7d021a354e3aa9b3473bb2689e46" }, "downloads": -1, "filename": "torchtracer-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "5f40cc4acc7da975d2ecfa79894279fe", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6116, "upload_time": "2018-09-20T07:02:38", "url": "https://files.pythonhosted.org/packages/6c/f1/ec6787592bdc04d03cb1059d7a4618af3b6b2d6582aeb1f7923e16189b64/torchtracer-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "973fb505cd71e9175bcda7a5255cbbf4", "sha256": "2483667aaab8e63401176cc2a0a6ebfc444c0b91e08630025a923d817ce7a9f8" }, "downloads": -1, "filename": "torchtracer-0.1.4.tar.gz", "has_sig": false, "md5_digest": "973fb505cd71e9175bcda7a5255cbbf4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4905, "upload_time": "2018-09-20T07:02:39", "url": "https://files.pythonhosted.org/packages/fe/73/6d631297835d46ce7e6c5d87c60eaaac2fb22ec5ae164944341cd85a28c4/torchtracer-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "4d1098fe6b03d35cfa7d4b0e23fa519a", "sha256": "36a670dcdca2133df135fe9c333d58ffd31bdbaf97cc3032a5d48b8c450971de" }, "downloads": -1, "filename": "torchtracer-0.1.5-py3-none-any.whl", "has_sig": false, "md5_digest": "4d1098fe6b03d35cfa7d4b0e23fa519a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6151, "upload_time": "2018-09-21T03:58:35", "url": "https://files.pythonhosted.org/packages/3e/fd/1654fa7452a7216caed4372170d7daf948db500feb285719bc9f00fa0188/torchtracer-0.1.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4fbe15cd303ceceb5e216634300d9653", "sha256": "84ed9692feb482b773a8b42de831ba9354b87b5a70f22083e754d22c521c6766" }, "downloads": -1, "filename": "torchtracer-0.1.5.tar.gz", "has_sig": false, "md5_digest": "4fbe15cd303ceceb5e216634300d9653", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4938, "upload_time": "2018-09-21T03:58:37", "url": "https://files.pythonhosted.org/packages/32/f5/03c6ad3300c0a1ce8942b4c4fe2c4c95a476097d6530c7eba9c2e99328e6/torchtracer-0.1.5.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "8386af1b6f2c8e5389752ceef4ace959", "sha256": "8193ef47f4bcfc15cc91cd54dddc079d9b59f819a5831a763844367ebcd46ae3" }, "downloads": -1, "filename": "torchtracer-0.2.0.tar.gz", "has_sig": false, "md5_digest": "8386af1b6f2c8e5389752ceef4ace959", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5628, "upload_time": "2018-11-14T09:00:12", "url": "https://files.pythonhosted.org/packages/cc/32/148381ba901e60822c5624235d5111bcff529a52cc72ab5d9bcd0281fbd1/torchtracer-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8386af1b6f2c8e5389752ceef4ace959", "sha256": "8193ef47f4bcfc15cc91cd54dddc079d9b59f819a5831a763844367ebcd46ae3" }, "downloads": -1, "filename": "torchtracer-0.2.0.tar.gz", "has_sig": false, "md5_digest": "8386af1b6f2c8e5389752ceef4ace959", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5628, "upload_time": "2018-11-14T09:00:12", "url": "https://files.pythonhosted.org/packages/cc/32/148381ba901e60822c5624235d5111bcff529a52cc72ab5d9bcd0281fbd1/torchtracer-0.2.0.tar.gz" } ] }