TensorBoard - Plot training and validation losses on the same graph?

前端 未结 8 1770
不思量自难忘°
不思量自难忘° 2020-12-02 18:34

Is there a way to plot both the training losses and validation losses on the same graph?

It\'s easy to have two separate scalar summaries for each of them i

8条回答
  •  不思量自难忘°
    2020-12-02 19:01

    For completeness, since tensorboard 1.5.0 this is now possible.

    You can use the custom scalars plugin. For this, you need to first make tensorboard layout configuration and write it to the event file. From the tensorboard example:

    import tensorflow as tf
    from tensorboard import summary
    from tensorboard.plugins.custom_scalar import layout_pb2
    
    # The layout has to be specified and written only once, not at every step
    
    layout_summary = summary.custom_scalar_pb(layout_pb2.Layout(
      category=[
        layout_pb2.Category(
          title='losses',
          chart=[
              layout_pb2.Chart(
                  title='losses',
                  multiline=layout_pb2.MultilineChartContent(
                    tag=[r'loss.*'],
                  )),
              layout_pb2.Chart(
                  title='baz',
                  margin=layout_pb2.MarginChartContent(
                    series=[
                      layout_pb2.MarginChartContent.Series(
                        value='loss/baz/scalar_summary',
                        lower='baz_lower/baz/scalar_summary',
                        upper='baz_upper/baz/scalar_summary'),
                    ],
                  )), 
          ]),
        layout_pb2.Category(
          title='trig functions',
          chart=[
              layout_pb2.Chart(
                  title='wave trig functions',
                  multiline=layout_pb2.MultilineChartContent(
                    tag=[r'trigFunctions/cosine', r'trigFunctions/sine'],
                  )),
              # The range of tangent is different. Let's give it its own chart.
              layout_pb2.Chart(
                  title='tan',
                  multiline=layout_pb2.MultilineChartContent(
                    tag=[r'trigFunctions/tangent'],
                  )),
          ],
          # This category we care less about. Let's make it initially closed.
          closed=True),
      ]))
    
    writer = tf.summary.FileWriter(".")
    writer.add_summary(layout_summary)
    # ...
    # Add any summary data you want to the file
    # ...
    writer.close()
    

    A Category is group of Charts. Each Chart corresponds to a single plot which displays several scalars together. The Chart can plot simple scalars (MultilineChartContent) or filled areas (MarginChartContent, e.g. when you want to plot the deviation of some value). The tag member of MultilineChartContent must be a list of regex-es which match the tags of the scalars that you want to group in the Chart. For more details check the proto definitions of the objects in https://github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/custom_scalar/layout.proto. Note that if you have several FileWriters writing to the same directory, you need to write the layout in only one of the files. Writing it to a separate file also works.

    To view the data in TensorBoard, you need to open the Custom Scalars tab. Here is an example image of what to expect https://user-images.githubusercontent.com/4221553/32865784-840edf52-ca19-11e7-88bc-1806b1243e0d.png

提交回复
热议问题