Skip to main content

Automatic metric logging for Pytorch

Project description

Metrician

GitHub all releases GitHub GitHub Workflow Status PyPi Metrician is a small lightweight module that easily and automatically records performance metrics for you. Right now, Metrician is only compatible with Pytorch. There are a lot of great tools out there like Pytoch Lighting that have built in loggers. Although there is nothing wrong with these tools (in fact, I'm a big fan), I find myself writing the same few lines of code over and over and over again, just to log the same metrics. I hate redundancy, so I wrote a tool to fix that issue. You're still able to use the same libraries, but now you don't have to code as much.

Usage

import torch
from torch import nn
from metrician import MetricWriter, Defaults

# initialize data
X = torch.randn( 10, 10 ) # input size 10
Y = torch.randn( 10,4 ) # 4 classes

# initialize simple model, loss and optimizer
model = nn.Linear(10,4)
optim = torch.optim.SGD(model.parameters())
loss_fn = nn.L1Loss()

# initialize Metric Writer
mw = MetricWriter( Defaults.SimpleClf ) # initialize with basic classifier metrics

# inside your training loop
for _ in range(EPOCHS):
	y = model( X )
	# you can either pass the loss function into the metric writer to automatically
	# record the loss or do that seperately. If you pass in the loss, it will automatically
	# call your loss function for you i.e. (loss = loss_fn(yhat,y) ) and return the result
	# if you are recording every couple of steps/batches it's recommended that you do not pass
	# the loss function to the metric writer
	loss = mw(y,Y,loss_fn)
	loss.backward()
	optim.step()

Feeling Lazy?

With Metrician you can leverage existing class methods to automatically create a config, reducing the amount of code you need.

import torch
from torch import nn
from metrician import MetricWriter, Defaults

# initialize data
X = torch.randn( 10, 10 ) # input size 10
Y = torch.randn( 10,4 ) # 4 classes

# initialize simple classification model
model = nn.Linear(10,4)
# initialize Metric Writer
mw = MetricWriter.from_model( model )
# print( mw.cfg.config_type )
# >>> classification

# or

# initialize simple regression model
model = nn.Linear(10,1)
# initialize Metric Writer
mw = MetricWriter.from_model( model )
# print( mw.cfg.config_type )
# >>> regression
...

Want to integrate it into another library like Pytorch Lightening?

Metrician is an easy module to integrate into any existing Pytorch library/framework.

def __init__(self):
    ...
    self.accuracy = pl.metrics.Accuracy()
	self.mw = MetricWriter( Defaults.SimpleCLF )
def training_step(self, batch, batch_idx):
    x, y = batch
    preds = self(x)
	# instead of normally typing
	# self.log('my_loss', loss,)
	# ...
	# self.log('my_accuracy',self.accuracy(preds, y))
	# instead type
	self.mw( (preds, y) )

TODOs

  • add histograms, embeddings and graphs
  • Tensorflow Support
  • ?????
  • profit

Project details


Download files

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

Source Distribution

metrician-0.0.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

metrician-0.0.2-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: metrician-0.0.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.5

File hashes

Hashes for metrician-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2170dbb25288afbe0cfd7f235685ea2ee782b1b843ab4d3f5f265d3305e855f4
MD5 55545235e1faaba91083f985c6b20e7d
BLAKE2b-256 6d0aedd230b178845ab9e57b5b2d8be4cc018eec901f05e363de86a98b97f580

See more details on using hashes here.

File details

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

File metadata

  • Download URL: metrician-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.5

File hashes

Hashes for metrician-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fb7bcbef02d20fd23340d8bf024d2f6e59155452b6a143a75bf3cac0b8c75401
MD5 fc0c7891c3268d9042733b5717c31380
BLAKE2b-256 11a58fc042860015f67a302864ce2956211afecff13532ae83c736503f1024df

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 Pingdom Monitoring Sentry Error logging StatusPage Status page