15
15
"""Takes a generator of values, and accumulates them for a frontend."""
16
16
17
17
import collections
18
+ import dataclasses
18
19
import threading
19
20
21
+ from typing import Sequence , Tuple
22
+
20
23
from tensorboard .backend .event_processing import directory_watcher
21
24
from tensorboard .backend .event_processing import event_file_loader
22
25
from tensorboard .backend .event_processing import io_wrapper
27
30
from tensorboard .compat .proto import event_pb2
28
31
from tensorboard .compat .proto import graph_pb2
29
32
from tensorboard .compat .proto import meta_graph_pb2
33
+ from tensorboard .compat .proto import tensor_pb2
30
34
from tensorboard .plugins .distribution import compressor
31
35
from tensorboard .util import tb_logging
32
36
33
37
34
38
logger = tb_logging .get_logger ()
35
39
36
- namedtuple = collections .namedtuple
37
- ScalarEvent = namedtuple ("ScalarEvent" , ["wall_time" , "step" , "value" ])
38
-
39
- CompressedHistogramEvent = namedtuple (
40
- "CompressedHistogramEvent" ,
41
- ["wall_time" , "step" , "compressed_histogram_values" ],
42
- )
43
-
44
- HistogramEvent = namedtuple (
45
- "HistogramEvent" , ["wall_time" , "step" , "histogram_value" ]
46
- )
47
-
48
- HistogramValue = namedtuple (
49
- "HistogramValue" ,
50
- ["min" , "max" , "num" , "sum" , "sum_squares" , "bucket_limit" , "bucket" ],
51
- )
52
-
53
- ImageEvent = namedtuple (
54
- "ImageEvent" ,
55
- ["wall_time" , "step" , "encoded_image_string" , "width" , "height" ],
56
- )
57
-
58
- AudioEvent = namedtuple (
59
- "AudioEvent" ,
60
- [
61
- "wall_time" ,
62
- "step" ,
63
- "encoded_audio_string" ,
64
- "content_type" ,
65
- "sample_rate" ,
66
- "length_frames" ,
67
- ],
68
- )
69
-
70
- TensorEvent = namedtuple ("TensorEvent" , ["wall_time" , "step" , "tensor_proto" ])
40
+
41
+ @dataclasses .dataclass (frozen = True )
42
+ class ScalarEvent :
43
+ """Contains information of a scalar event.
44
+
45
+ Attributes:
46
+ wall_time: Timestamp of the event in seconds.
47
+ step: Global step of the event.
48
+ value: A float or int value of the scalar.
49
+ """
50
+
51
+ wall_time : float
52
+ step : int
53
+ value : float
54
+
55
+
56
+ @dataclasses .dataclass (frozen = True )
57
+ class CompressedHistogramEvent :
58
+ """Contains information of a compressed histogram event.
59
+
60
+ Attributes:
61
+ wall_time: Timestamp of the event in seconds.
62
+ step: Global step of the event.
63
+ compressed_histogram_values: A sequence of tuples of basis points and
64
+ associated values in a compressed histogram.
65
+ """
66
+
67
+ wall_time : float
68
+ step : int
69
+ compressed_histogram_values : Sequence [Tuple [float , float ]]
70
+
71
+
72
+ @dataclasses .dataclass (frozen = True )
73
+ class HistogramValue :
74
+ """Holds the information of the histogram values.
75
+
76
+ Attributes:
77
+ min: A float or int min value.
78
+ max: A float or int max value.
79
+ num: Total number of values.
80
+ sum: Sum of all values.
81
+ sum_squares: Sum of squares for all values.
82
+ bucket_limit: Upper values per bucket.
83
+ bucket: Numbers of values per bucket.
84
+ """
85
+
86
+ min : float
87
+ max : float
88
+ num : int
89
+ sum : float
90
+ sum_squares : float
91
+ bucket_limit : Sequence [float ]
92
+ bucket : Sequence [int ]
93
+
94
+
95
+ @dataclasses .dataclass (frozen = True )
96
+ class HistogramEvent :
97
+ """Contains information of a histogram event.
98
+
99
+ Attributes:
100
+ wall_time: Timestamp of the event in seconds.
101
+ step: Global step of the event.
102
+ histogram_value: Information of the histogram values.
103
+ """
104
+
105
+ wall_time : float
106
+ step : int
107
+ histogram_value : HistogramValue
108
+
109
+
110
+ @dataclasses .dataclass (frozen = True )
111
+ class ImageEvent :
112
+ """Contains information of an image event.
113
+
114
+ Attributes:
115
+ wall_time: Timestamp of the event in seconds.
116
+ step: Global step of the event.
117
+ encoded_image_string: Image content encoded in bytes.
118
+ width: Width of the image.
119
+ height: Height of the image.
120
+ """
121
+
122
+ wall_time : float
123
+ step : int
124
+ encoded_image_string : bytes
125
+ width : int
126
+ height : int
127
+
128
+
129
+ @dataclasses .dataclass (frozen = True )
130
+ class AudioEvent :
131
+ """Contains information of an audio event.
132
+
133
+ Attributes:
134
+ wall_time: Timestamp of the event in seconds.
135
+ step: Global step of the event.
136
+ encoded_audio_string: Audio content encoded in bytes.
137
+ content_type: A string describes the type of the audio content.
138
+ sample_rate: Sample rate of the audio in Hz. Must be positive.
139
+ length_frames: Length of the audio in frames (samples per channel).
140
+ """
141
+
142
+ wall_time : float
143
+ step : int
144
+ encoded_audio_string : bytes
145
+ content_type : str
146
+ sample_rate : float
147
+ length_frames : int
148
+
149
+
150
+ @dataclasses .dataclass (frozen = True )
151
+ class TensorEvent :
152
+ """A tensor event.
153
+
154
+ Attributes:
155
+ wall_time: Timestamp of the event in seconds.
156
+ step: Global step of the event.
157
+ tensor_proto: A `TensorProto`.
158
+ """
159
+
160
+ wall_time : float
161
+ step : int
162
+ tensor_proto : tensor_pb2 .TensorProto
163
+
71
164
72
165
## Different types of summary events handled by the event_accumulator
73
166
SUMMARY_TYPES = {
@@ -664,7 +757,8 @@ def _CheckForOutOfOrderStepAndMaybePurge(self, event):
664
757
self .most_recent_step = event .step
665
758
self .most_recent_wall_time = event .wall_time
666
759
667
- def _ConvertHistogramProtoToTuple (self , histo ):
760
+ def _ConvertHistogramProtoToPopo (self , histo ):
761
+ """Converts histogram proto to Python object."""
668
762
return HistogramValue (
669
763
min = histo .min ,
670
764
max = histo .max ,
@@ -677,7 +771,7 @@ def _ConvertHistogramProtoToTuple(self, histo):
677
771
678
772
def _ProcessHistogram (self , tag , wall_time , step , histo ):
679
773
"""Processes a proto histogram by adding it to accumulated state."""
680
- histo = self ._ConvertHistogramProtoToTuple (histo )
774
+ histo = self ._ConvertHistogramProtoToPopo (histo )
681
775
histo_ev = HistogramEvent (wall_time , step , histo )
682
776
self .histograms .AddItem (tag , histo_ev )
683
777
self .compressed_histograms .AddItem (
0 commit comments