Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorboard/plugins/image/metadata.py: 44%
16 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"""Internal information about the images plugin."""
18from tensorboard.compat.proto import summary_pb2
19from tensorboard.plugins.image import plugin_data_pb2
21PLUGIN_NAME = "images"
23# The most recent value for the `version` field of the `ImagePluginData`
24# proto.
25PROTO_VERSION = 0
28def create_summary_metadata(
29 display_name, description, *, converted_to_tensor=None
30):
31 """Create a `summary_pb2.SummaryMetadata` proto for image plugin data.
33 Returns:
34 A `summary_pb2.SummaryMetadata` protobuf object.
35 """
36 content = plugin_data_pb2.ImagePluginData(
37 version=PROTO_VERSION,
38 converted_to_tensor=converted_to_tensor,
39 )
40 metadata = summary_pb2.SummaryMetadata(
41 display_name=display_name,
42 summary_description=description,
43 plugin_data=summary_pb2.SummaryMetadata.PluginData(
44 plugin_name=PLUGIN_NAME, content=content.SerializeToString()
45 ),
46 )
47 return metadata
50def parse_plugin_metadata(content):
51 """Parse summary metadata to a Python object.
53 Arguments:
54 content: The `content` field of a `SummaryMetadata` proto
55 corresponding to the image plugin.
57 Returns:
58 An `ImagePluginData` protobuf object.
59 """
60 if not isinstance(content, bytes):
61 raise TypeError("Content type must be bytes")
62 result = plugin_data_pb2.ImagePluginData.FromString(content)
63 if result.version == 0:
64 return result
65 # No other versions known at this time, so no migrations to do.
66 return result