Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorboard/plugins/histogram/metadata.py: 41%
17 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Information about histogram summaries."""
18from tensorboard.compat.proto import summary_pb2
19from tensorboard.plugins.histogram import plugin_data_pb2
21PLUGIN_NAME = "histograms"
23# The most recent value for the `version` field of the
24# `HistogramPluginData` proto.
25PROTO_VERSION = 0
28def create_summary_metadata(display_name, description):
29 """Create a `summary_pb2.SummaryMetadata` proto for histogram plugin data.
31 Returns:
32 A `summary_pb2.SummaryMetadata` protobuf object.
33 """
34 content = plugin_data_pb2.HistogramPluginData(version=PROTO_VERSION)
35 return summary_pb2.SummaryMetadata(
36 display_name=display_name,
37 summary_description=description,
38 plugin_data=summary_pb2.SummaryMetadata.PluginData(
39 plugin_name=PLUGIN_NAME, content=content.SerializeToString()
40 ),
41 )
44def parse_plugin_metadata(content):
45 """Parse summary metadata to a Python object.
47 Arguments:
48 content: The `content` field of a `SummaryMetadata` proto
49 corresponding to the histogram plugin.
51 Returns:
52 A `HistogramPluginData` protobuf object.
53 """
54 if not isinstance(content, bytes):
55 raise TypeError("Content type must be bytes")
56 if content == b"{}":
57 # Old-style JSON format. Equivalent to an all-default proto.
58 return plugin_data_pb2.HistogramPluginData()
59 else:
60 result = plugin_data_pb2.HistogramPluginData.FromString(content)
61 if result.version == 0:
62 return result
63 # No other versions known at this time, so no migrations to do.
64 return result