torch-utils

Common Utils for PyTorch


Keywords
PyTorch, Utils
License
MIT
Install
pip install torch-utils==0.1.8

Documentation

torch-utils Build Status codecov PyPI version

Common Utils for PyTorch.

Installation

Need Python 3.6+.

pip install torch-utils

Usage

  1. Accuracy
import torch_utils

# ...

top_1, top_5 = torch_utils.accuracy(output=..., target=..., top_k=(1, 5))
  1. Meter
import torch_utils

loss_meter = torch_utils.AverageMeter(name='Meter', length=10)
loss_meter.update(val=...)

print(loss_meter.avg, loss_meter.val)
print(loss_meter)
#> Test 0.00 (0.00)

progress_meter = torch_utils.ProgressMeter(total_steps=100, total_epochs=10)
progress_meter.update(step=10)
assert progress_meter.step == 10
assert progress_meter.ratio == 0.1
assert progress_meter.epoch == 1
print(progress_meter)
#> Step 10/100=10.0% (1/10)