Coder Social home page Coder Social logo

leo-zhou / tensorboard-pytorch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lanpa/tensorboardx

0.0 2.0 0.0 2.21 MB

tensorboard for pytorch (and chainer, mxnet, numpy, ...)

Home Page: http://tensorboard-pytorch.rtfd.io

License: MIT License

Shell 0.07% Python 99.93%

tensorboard-pytorch's Introduction

Build Status PyPI version Downloads

tensorboard-pytorch

Write tensorboard events with simple function call.

Supports scalar, image, histogram, audio, text, graph, embedding and pr_curve.

see demo (result of demo.py and some images generated by BEGAN)

If the demo code onnx_graph.py is not working, you have to build pytorch and onnx from source.

Install

#tested on anaconda2/anaconda3, pytorch 0.3, torchvision 0.2

pip install tensorboardX

pip install tensorflow (for tensorboard web server)

or build from source: pip install git+https://github.com/lanpa/tensorboard-pytorch

API

http://tensorboard-pytorch.readthedocs.io/en/latest/tensorboard.html

Usage

import torch
import torchvision.utils as vutils
import numpy as np
import torchvision.models as models
from torchvision import datasets
from tensorboardX import SummaryWriter

resnet18 = models.resnet18(False)
writer = SummaryWriter()
sample_rate = 44100
freqs = [262, 294, 330, 349, 392, 440, 440, 440, 440, 440, 440]

for n_iter in range(100):
    s1 = torch.rand(1) # value to keep
    s2 = torch.rand(1)
    writer.add_scalar('data/scalar1', s1[0], n_iter) #data grouping by `slash`
    writer.add_scalar('data/scalar2', s2[0], n_iter)
    writer.add_scalars('data/scalar_group', {"xsinx":n_iter*np.sin(n_iter),
                                             "xcosx":n_iter*np.cos(n_iter),
                                             "arctanx": np.arctan(n_iter)}, n_iter)
    x = torch.rand(32, 3, 64, 64) # output from network
    if n_iter%10==0:
        x = vutils.make_grid(x, normalize=True, scale_each=True)
        writer.add_image('Image', x, n_iter)
        x = torch.zeros(sample_rate*2)
        for i in range(x.size(0)):
            x[i] = np.cos(freqs[n_iter//10]*np.pi*float(i)/float(sample_rate)) # sound amplitude should in [-1, 1]
        writer.add_audio('myAudio', x, n_iter, sample_rate=sample_rate)
        writer.add_text('Text', 'text logged at step:'+str(n_iter), n_iter)
        for name, param in resnet18.named_parameters():
            writer.add_histogram(name, param.clone().cpu().data.numpy(), n_iter)
        writer.add_pr_curve('xoxo', np.random.randint(2, size=100), np.random.rand(100), n_iter) #needs tensorboard 0.4RC or later
dataset = datasets.MNIST('mnist', train=False, download=True)
images = dataset.test_data[:100].float()
label = dataset.test_labels[:100]
features = images.view(100, 784)
writer.add_embedding(features, metadata=label, label_img=images.unsqueeze(1))

# export scalar data to JSON for external processing
writer.export_scalars_to_json("./all_scalars.json")

writer.close()

python demo.py

tensorboard --logdir runs

Screenshots

Tweaks

To show more images in tensorboard's image tab, just modify the hardcoded event_accumulator in ~/anaconda3/lib/python3.6/site-packages/tensorflow/tensorboard/backend/application.py as you wish.

For tensorflow-tensorboard>0.17 see lanpa#44

Reference:

https://github.com/TeamHG-Memex/tensorboard_logger

https://github.com/dmlc/tensorboard

tensorboard-pytorch's People

Contributors

lanpa avatar andres-fr avatar lucabergamini avatar levirve avatar eklitzke avatar greaber avatar stonesjtu avatar ruotianluo avatar

Watchers

James Cloos avatar  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.