diff --git a/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py b/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py index f3e302ff21f..84fa48d14bb 100644 --- a/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py +++ b/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py @@ -275,8 +275,11 @@ def layout_impl(self): for category in layout_proto.category: if category.title in title_to_category: # A category with this name has been seen before. Do not create a - # new one. Merge their charts. - title_to_category[category.title].chart.extend(category.chart) + # new one. Merge their charts, skipping any duplicates. + title_to_category[category.title].chart.extend([ + c for c in category.chart + if c not in title_to_category[category.title].chart + ]) else: # This category has not been seen before. merged_layout.category.add().MergeFrom(category) diff --git a/tensorboard/plugins/custom_scalar/custom_scalars_plugin_test.py b/tensorboard/plugins/custom_scalar/custom_scalars_plugin_test.py index b644d063c58..f4a20780523 100644 --- a/tensorboard/plugins/custom_scalar/custom_scalars_plugin_test.py +++ b/tensorboard/plugins/custom_scalar/custom_scalars_plugin_test.py @@ -78,7 +78,7 @@ def __init__(self, *args, **kwargs): ] ), # A category with this name is also present in a layout for a - # different run (the logdir run) + # different run (the logdir run) and also contains a duplicate chart layout_pb2.Category( title='cross entropy', chart=[ @@ -92,6 +92,11 @@ def __init__(self, *args, **kwargs): upper='cross entropy upper'), ], )), + layout_pb2.Chart( + title='cross entropy', + multiline=layout_pb2.MultilineChartContent( + tag=[r'cross entropy'], + )), ] ), ]