GithubHelp home page GithubHelp logo

metrician's Introduction

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

metrician's People

Contributors

tedtroxell avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.