Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorboard/plugins/custom_scalar/summary.py: 31%

16 statements  

« 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"""Contains summaries related to laying out the custom scalars dashboard.""" 

16 

17 

18from tensorboard.plugins.custom_scalar import layout_pb2 

19from tensorboard.plugins.custom_scalar import metadata 

20 

21 

22def op(scalars_layout, collections=None): 

23 """Creates a summary that contains a layout. 

24 

25 When users navigate to the custom scalars dashboard, they will see a layout 

26 based on the proto provided to this function. 

27 

28 Args: 

29 scalars_layout: The scalars_layout_pb2.Layout proto that specifies the 

30 layout. 

31 collections: Optional list of graph collections keys. The new 

32 summary op is added to these collections. Defaults to 

33 `[Graph Keys.SUMMARIES]`. 

34 

35 Returns: 

36 A tensor summary op that writes the layout to disk. 

37 """ 

38 # TODO(nickfelt): remove on-demand imports once dep situation is fixed. 

39 import tensorflow.compat.v1 as tf 

40 

41 assert isinstance(scalars_layout, layout_pb2.Layout) 

42 summary_metadata = metadata.create_summary_metadata() 

43 return tf.summary.tensor_summary( 

44 name=metadata.CONFIG_SUMMARY_TAG, 

45 tensor=tf.constant(scalars_layout.SerializeToString(), dtype=tf.string), 

46 collections=collections, 

47 summary_metadata=summary_metadata, 

48 ) 

49 

50 

51def pb(scalars_layout): 

52 """Creates a summary that contains a layout. 

53 

54 When users navigate to the custom scalars dashboard, they will see a layout 

55 based on the proto provided to this function. 

56 

57 Args: 

58 scalars_layout: The scalars_layout_pb2.Layout proto that specifies the 

59 layout. 

60 

61 Returns: 

62 A summary proto containing the layout. 

63 """ 

64 # TODO(nickfelt): remove on-demand imports once dep situation is fixed. 

65 import tensorflow.compat.v1 as tf 

66 

67 assert isinstance(scalars_layout, layout_pb2.Layout) 

68 tensor = tf.make_tensor_proto( 

69 scalars_layout.SerializeToString(), dtype=tf.string 

70 ) 

71 tf_summary_metadata = tf.SummaryMetadata.FromString( 

72 metadata.create_summary_metadata().SerializeToString() 

73 ) 

74 summary = tf.Summary() 

75 summary.value.add( 

76 tag=metadata.CONFIG_SUMMARY_TAG, 

77 metadata=tf_summary_metadata, 

78 tensor=tensor, 

79 ) 

80 return summary