{"id":16865796,"url":"https://github.com/hellock/torchpack","last_synced_at":"2025-04-11T09:50:46.112Z","repository":{"id":189833752,"uuid":"113763938","full_name":"hellock/torchpack","owner":"hellock","description":"Develop and research with PyTorch more easily.","archived":false,"fork":false,"pushed_at":"2018-10-12T16:59:22.000Z","size":67,"stargazers_count":25,"open_issues_count":1,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T06:41:43.684Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/hellock.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}},"created_at":"2017-12-10T16:07:48.000Z","updated_at":"2023-08-24T08:26:26.000Z","dependencies_parsed_at":"2023-08-22T00:47:21.558Z","dependency_job_id":null,"html_url":"https://github.com/hellock/torchpack","commit_stats":null,"previous_names":["hellock/torchpack"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellock%2Ftorchpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellock%2Ftorchpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellock%2Ftorchpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellock%2Ftorchpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellock","download_url":"https://codeload.github.com/hellock/torchpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248370653,"owners_count":21092852,"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":[],"created_at":"2024-10-13T14:48:32.010Z","updated_at":"2025-04-11T09:50:46.089Z","avatar_url":"https://github.com/hellock.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# torchpack (Deprecated! Please use [mmcv](https://github.com/open-mmlab/mmcv) instead.)\n\n[![PyPI Version](https://img.shields.io/pypi/v/torchpack.svg)](https://pypi.python.org/pypi/torchpack)\n\nTorchpack is a set of interfaces to simplify the usage of PyTorch.\n\nDocumentation is ongoing.\n\n\n## Installation\n\n- Install with pip. \n```\npip install torchpack\n```\n- Install from source.\n```\ngit clone https://github.com/hellock/torchpack.git\ncd torchpack\npython setup.py install\n```\n\n**Note**: If you want to use tensorboard to visualize the training process, you need to\ninstall tensorflow([`installation guide`](https://www.tensorflow.org/install/install_linux)) and tensorboardX(`pip install tensorboardX`).\n\n## What can torchpack do\n\nTorchpack aims to help users to start training with less code, while stays\nflexible and configurable. It provides a `Runner` with lots of `Hooks`.\n\n## Example\n\n```python\n######################## file1: config.py #######################\nwork_dir = './demo'  # dir to save log file and checkpoints\noptimizer = dict(\n    algorithm='SGD', args=dict(lr=0.001, momentum=0.9, weight_decay=5e-4))\nworkflow = [('train', 2), ('val', 1)]  # train 2 epochs and then validate 1 epochs, iteratively\nmax_epoch = 16\nlr_policy = dict(policy='step', step=12)  # decrese learning rate by 10 every 12 epochs\ncheckpoint_cfg = dict(interval=1)  # save checkpoint at every epoch\nlog_cfg = dict(\n    # log at every 50 iterations\n    interval=50,\n    # two logging hooks, one for printing in terminal and one for tensorboard visualization\n    hooks=[\n        ('TextLoggerHook', {}),\n        ('TensorboardLoggerHook', dict(log_dir=work_dir + '/log'))\n    ])\n\n######################### file2: main.py ########################\nimport torch\nfrom torchpack import Config, Runner\nfrom collections import OrderedDict\n\n# define how to process a batch and return a dict\ndef batch_processor(model, data, train_mode):\n    img, label = data\n    label = label.cuda(non_blocking=True)\n    pred = model(img)\n    loss = F.cross_entropy(pred, label)\n    accuracy = get_accuracy(pred, label_var)\n    log_vars = OrderedDict()\n    log_vars['loss'] = loss.item()\n    log_vars['accuracy'] = accuracy.item()\n    outputs = dict(loss=loss, log_vars=log_vars, num_samples=img.size(0))\n    return outputs\n\ncfg = Config.from_file('config.py')  # or config.yaml/config.json\nmodel = resnet18()\nrunner = Runner(model, cfg.optimizer, batch_processor, cfg.work_dir)\nrunner.register_default_hooks(lr_config=cfg.lr_policy,\n                              checkpoint_config=cfg.checkpoint_cfg,\n                              log_config=cfg.log_cfg)\n\nrunner.run([train_loader, val_loader], cfg.workflow, cfg.max_epoch)\n```\n\nFor a full example of training on ImageNet, please see `examples/train_imagenet.py`.\n\n```shell\npython examples/train_imagenet.py examples/config.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellock%2Ftorchpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellock%2Ftorchpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellock%2Ftorchpack/lists"}