Skip to main content
# torchpack

Torchpack is a set of interfaces to simplify the usage of PyTorch.

Documentation is ongoing.


## Example

```python
######################## file1: config.py #######################
work_dir = './demo' # dir to save log file and checkpoints
optimizer = dict(
algorithm='SGD', args=dict(lr=0.001, momentum=0.9, weight_decay=5e-4))
workflow = [('train', 2), ('val', 1)] # train 2 epochs and then validate 1 epochs, iteratively
max_epoch = 16
lr_policy = dict(policy='step', step=12) # decrese learning rate by 10 every 12 epochs
checkpoint_cfg = dict(interval=1) # save checkpoint at every epoch
log_cfg = dict(interval=50) # log at every 50 iterations

######################### file2: main.py ########################
import torch
from torchpack import Config, Runner
from collections import OrderedDict

# define how to process a batch and return a dict
def batch_processor(model, data, train_mode):
img, label = data
volatile = False if train_mode else True
img_var = torch.autograd.Variable(img, volatile=volatile)
label_var = torch.autograd.Variable(label, requires_grad=False)
pred = model(img)
loss = F.cross_entropy(pred, label_var)
accuracy = get_accuracy(pred, label_var)
log_vars = OrderedDict()
log_vars['loss'] = loss.data[0]
log_vars['accuracy'] = accuracy.data[0]
outputs = dict(
loss=loss, log_vars=log_vars, num_samples=img.size(0))
return outputs

cfg = Config.from_file('config.py') # or config.yaml/config.json
model = resnet18()
runner = Runner(model, cfg.optimizer, batch_processor, cfg.work_dir)
runner.register_default_hooks(cfg.lr_policy, cfg.checkpoint_cfg, cfg.log_cfg)

runner.run([train_loader, val_loader], cfg.workflow, cfg.max_epoch)
```

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchpack-0.0.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchpack-0.0.2-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file torchpack-0.0.2.tar.gz.

File metadata

  • Download URL: torchpack-0.0.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for torchpack-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5d8654623ff516b14e130cca7cf2f3e3707ce7266af4e628a5e93464c8f5cc16
MD5 55b5b3d07424651ad2ffc46e9ed18393
BLAKE2b-256 06cef1a5d17ec583bb3e88b7151b9681ed819ca4a49d566fd97f1f45bf0784aa

See more details on using hashes here.

File details

Details for the file torchpack-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for torchpack-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88327960c03da34eb865ecc931b1218728c37656343dcd7e62245cfa2d58c213
MD5 ffdc47c4967a1e7a058eb2be7a6aefb8
BLAKE2b-256 ce5cae848fdbc17cf0ca10621ddb88b070ef8dafeb14d20c40aa702762d57390

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page