GithubHelp home page GithubHelp logo

Comments (3)

kkashin avatar kkashin commented on April 19, 2024 3

@Paethon - the plotting functionality was designed to work in both notebooks and in standalone html files that we use for generating "reports" that can be easily shared - so yes, other modes are definitely supported. We highlight the notebook usage on the site because in our experience that's the primary way users have interacted with the tool for visualizing the models & results.

Here's an example of how one can run the CNN on MNIST tutorial and get the contour plot in an html file:

import torch
import numpy as np

from ax.plot.contour import plot_contour
from ax.plot.trace import optimization_trace_single_method
from ax.service.managed_loop import optimize
from ax.utils.tutorials.cnn_utils import load_mnist, train, evaluate

# note these new imports!
from ax.plot.render import plot_config_to_html
from ax.utils.report.render import render_report_elements


dtype = torch.float
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

train_loader, valid_loader, test_loader = load_mnist()

def train_evaluate(parameterization):
    net = train(train_loader=train_loader, parameters=parameterization, dtype=dtype, device=device)
    return evaluate(
        net=net,
        data_loader=valid_loader,
        dtype=dtype,
        device=device,
    )

best_parameters, values, experiment, model = optimize(
    parameters=[
        {"name": "lr", "type": "range", "bounds": [1e-6, 0.4], "log_scale": True},
        {"name": "momentum", "type": "range", "bounds": [0.0, 1.0]},
    ],
    evaluation_function=train_evaluate,
    objective_name='accuracy',
)

plot_config = plot_contour(model=model, param_x='lr', param_y='momentum', metric_name='accuracy')

# create an Ax report
with open('report.html', 'w') as outfile:
    outfile.write(render_report_elements(
    "example_report", 
    html_elements=[plot_config_to_html(plot_config)], 
    header=False,
))

We're working on making the plotting a bit more modular (and not always depend on require.js), which will make it even easier to put together a barebones html file without using the render_report_elements that handles the dependency management for you. I should note that when using the report functionality, you get access to a couple other utilities that make it easy to compose reports for viewing of results (see, e.g., benchmarking reports)

Are there other ways of plotting that you had in mind, or does outputting an html file work for you?

from ax.

Paethon avatar Paethon commented on April 19, 2024

Thanks!

Generating an HTML report is actually the best solution for me anyway. I found plot_config_to_html(plot_config) and tried writing that directly to an html-file, but that did not really work out as intended 😄

from ax.

kkashin avatar kkashin commented on April 19, 2024

Great - happy that works for you. Once we do the refactor of the plotting, it should be possible to write plot_config_to_html(plot_config) directly to HTML file and for that to work. Issue now is that you need a bunch of dependencies in the HTML head in order for rendering to work.

from ax.

Related Issues (20)

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.