tensorflow / tensorboard

TensorFlow's Visualization Toolkit
Apache License 2.0
6.67k stars 1.65k forks source link

Feature: multiple Y-axis scales on a single chart #2239

Open JafferWilson opened 5 years ago

JafferWilson commented 5 years ago

For bug reports, please include the following:

Here are the two examples:
1 perfectly worked as the scales was same:

import tensorflow as tf
from numpy import random

writer_1 = tf.summary.FileWriter("./logs/plot_1")
writer_2 = tf.summary.FileWriter("./logs/plot_2")

log_var = tf.Variable(0.0)
tf.summary.scalar("loss", log_var)

write_op = tf.summary.merge_all()

session = tf.InteractiveSession()
session.run(tf.global_variables_initializer())

for i in range(100):
    # for writer 1
    summary = session.run(write_op, {log_var: random.rand()})
    writer_1.add_summary(summary, i)
    writer_1.flush()

    # for writer 2
    summary = session.run(write_op, {log_var: random.rand()})
    writer_2.add_summary(summary, i)
    writer_2.flush()
    print(i)

Got this figure which was understandable : good image

But take a look at the second case where the values do not fit in the same range. In that case I need to have two different axes on same chart, so that I get a good and understandable image. Check the code:

import tensorflow as tf
from numpy import random

writer_1 = tf.summary.FileWriter("./logs/plot_1")
writer_2 = tf.summary.FileWriter("./logs/plot_2")

log_var = tf.Variable(0.0)
tf.summary.scalar("loss", log_var)

write_op = tf.summary.merge_all()

session = tf.InteractiveSession()
session.run(tf.global_variables_initializer())

for i in range(100):
    # for writer 1
    summary = session.run(write_op, {log_var: i*10})
    writer_1.add_summary(summary, i)
    writer_1.flush()

    # for writer 2
    summary = session.run(write_op, {log_var: random.rand()})
    writer_2.add_summary(summary, i)
    writer_2.flush()
    print(i)

See the image obtained:
bad image

Please help me with this query. I have tried many things and even have placed this question on Stackoverflow but there is no response.

nfelt commented 5 years ago

If I understand correctly, you're asking for two different y-axes on the same plot, which indicate different scales? Like one on the left side and one on the right?

There is no current support in TensorBoard for multiple y-axes so this would mean adding functionality to do this - not just at the frontend but probably at the time the data is recorded as well, since I don't think we would want to automatically put data on two axes just because their ranges are very different. Sometimes showing that one range is dramatically smaller is actually the most important thing to understand, and showing both lines as having similar visual ranges could be misleading if the user wasn't specifically intending to use different y-scaling.

It would help to know more about what specific use case you have in mind (I assume the code here is a sample, not your actual problem). Have you tried using the option to use log scaling on the y-axis? In this particular case I think it would probably show a lot more of the variation of the blue line, though of course it changes other aspects of the plot as well.

JafferWilson commented 5 years ago

@nfelt Thank you for your reply, Nick. Yes, the above code just a sample. Its not what actually I tried. Actually, it is a little fuzzy thing if I code the actual stuff here. But still I can try and explain it. In my case, There are two different values. One is the loss and the other is the percentage increase in the correct output. It means that, I have calculated the loss function, say you may consider the MSE. I have plotted it using the Tensorboard. But I wanted to compare the percentage of the correct output that I am getting with respect to the actual or expected output of the NN. So I tried to plot two different plots but I came across ambiguity. I was not able to understand. As if I want to see both results simultaneously, I was not able to as I have two graphs.
I wanted to see the values of both the graphs when I hover the mouse on the particular values. Say the two values are loss and percentage accuracy of the model. I tried making them as tag=loss so they appear together. But the scaling was the issue. I tried using matplotlib of python. But it is not as realtime as Tensorboard. It was giving delays. Hence, I need to have two different axes for Y values. I hope I was able to explain you. Please let me know if need some more information.

JafferWilson commented 5 years ago

@nfelt @gowtham-kp Please let me know if there is anything else if you need. I am not getting the solution elsewhere.

nfelt commented 5 years ago

I think we're unlikely to want to implement support for a second Y-scale in the default scalar chart viewer case. It would be a significant amount of work and complicates the basic use case where the values being compared on the chart all represent the same conceptual quantity and so it makes sense to view them all on a uniform Y-scale.

I can leave this open as a feature request for the custom scalar dashboard in a case where manually plotting different logical series together is more explicitly in scope.

For a workaround, I'd recommend just applying the scaling you want to one or both series before logging the data. I realize it's not ideal because the hover table view won't show the original values, but it should at least let you visually track them. Potentially you could log the original values either as a third series or under a different name so you still have access to those.

JafferWilson commented 5 years ago

@nfelt Delighted by your reply. But is this process not going to take an infinite time whereas I may even die before it gets implemented as feature? Does Tensorboard developer have no insights on this? Even if you see normally the matplotlib or plotly gives you such a option then why Tensorboard is not implementing the scalar plugin with that insights? I am afraid as I don't know why Tensorboard is so much complicated?

nfelt commented 5 years ago

TensorBoard isn't supposed to be a general-purpose plotting tool like matplotlib or plotly, so it's expected that we won't support all the features those libraries provide.

We want to improve the custom scalars experience in the near-ish term and this is a feature we'll take under consideration when we do that. But you're right that it won't be a top priority - it's not trivial to add (mostly in terms of UX/design rather than the technical aspects), there's a workaround, and we're a small team and there are other things we want to prioritize as well.

JafferWilson commented 5 years ago

@nfelt Thank you once again for your response, Nick. I will wait.