tensorbored 2.21.0rc1769983804__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. tensorbored/__init__.py +112 -0
  2. tensorbored/_vendor/__init__.py +0 -0
  3. tensorbored/_vendor/bleach/__init__.py +125 -0
  4. tensorbored/_vendor/bleach/_vendor/__init__.py +0 -0
  5. tensorbored/_vendor/bleach/_vendor/html5lib/__init__.py +35 -0
  6. tensorbored/_vendor/bleach/_vendor/html5lib/_ihatexml.py +289 -0
  7. tensorbored/_vendor/bleach/_vendor/html5lib/_inputstream.py +918 -0
  8. tensorbored/_vendor/bleach/_vendor/html5lib/_tokenizer.py +1735 -0
  9. tensorbored/_vendor/bleach/_vendor/html5lib/_trie/__init__.py +5 -0
  10. tensorbored/_vendor/bleach/_vendor/html5lib/_trie/_base.py +40 -0
  11. tensorbored/_vendor/bleach/_vendor/html5lib/_trie/py.py +67 -0
  12. tensorbored/_vendor/bleach/_vendor/html5lib/_utils.py +159 -0
  13. tensorbored/_vendor/bleach/_vendor/html5lib/constants.py +2946 -0
  14. tensorbored/_vendor/bleach/_vendor/html5lib/filters/__init__.py +0 -0
  15. tensorbored/_vendor/bleach/_vendor/html5lib/filters/alphabeticalattributes.py +29 -0
  16. tensorbored/_vendor/bleach/_vendor/html5lib/filters/base.py +12 -0
  17. tensorbored/_vendor/bleach/_vendor/html5lib/filters/inject_meta_charset.py +73 -0
  18. tensorbored/_vendor/bleach/_vendor/html5lib/filters/lint.py +93 -0
  19. tensorbored/_vendor/bleach/_vendor/html5lib/filters/optionaltags.py +207 -0
  20. tensorbored/_vendor/bleach/_vendor/html5lib/filters/sanitizer.py +916 -0
  21. tensorbored/_vendor/bleach/_vendor/html5lib/filters/whitespace.py +38 -0
  22. tensorbored/_vendor/bleach/_vendor/html5lib/html5parser.py +2795 -0
  23. tensorbored/_vendor/bleach/_vendor/html5lib/serializer.py +409 -0
  24. tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/__init__.py +30 -0
  25. tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/genshi.py +54 -0
  26. tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/sax.py +50 -0
  27. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/__init__.py +88 -0
  28. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/base.py +417 -0
  29. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/dom.py +239 -0
  30. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/etree.py +343 -0
  31. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/etree_lxml.py +392 -0
  32. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/__init__.py +154 -0
  33. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/base.py +252 -0
  34. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/dom.py +43 -0
  35. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/etree.py +131 -0
  36. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/etree_lxml.py +215 -0
  37. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/genshi.py +69 -0
  38. tensorbored/_vendor/bleach/_vendor/parse.py +1078 -0
  39. tensorbored/_vendor/bleach/callbacks.py +32 -0
  40. tensorbored/_vendor/bleach/html5lib_shim.py +757 -0
  41. tensorbored/_vendor/bleach/linkifier.py +633 -0
  42. tensorbored/_vendor/bleach/parse_shim.py +1 -0
  43. tensorbored/_vendor/bleach/sanitizer.py +638 -0
  44. tensorbored/_vendor/bleach/six_shim.py +19 -0
  45. tensorbored/_vendor/webencodings/__init__.py +342 -0
  46. tensorbored/_vendor/webencodings/labels.py +231 -0
  47. tensorbored/_vendor/webencodings/mklabels.py +59 -0
  48. tensorbored/_vendor/webencodings/x_user_defined.py +325 -0
  49. tensorbored/assets.py +36 -0
  50. tensorbored/auth.py +102 -0
  51. tensorbored/backend/__init__.py +0 -0
  52. tensorbored/backend/application.py +604 -0
  53. tensorbored/backend/auth_context_middleware.py +38 -0
  54. tensorbored/backend/client_feature_flags.py +113 -0
  55. tensorbored/backend/empty_path_redirect.py +46 -0
  56. tensorbored/backend/event_processing/__init__.py +0 -0
  57. tensorbored/backend/event_processing/data_ingester.py +276 -0
  58. tensorbored/backend/event_processing/data_provider.py +535 -0
  59. tensorbored/backend/event_processing/directory_loader.py +142 -0
  60. tensorbored/backend/event_processing/directory_watcher.py +272 -0
  61. tensorbored/backend/event_processing/event_accumulator.py +950 -0
  62. tensorbored/backend/event_processing/event_file_inspector.py +463 -0
  63. tensorbored/backend/event_processing/event_file_loader.py +292 -0
  64. tensorbored/backend/event_processing/event_multiplexer.py +521 -0
  65. tensorbored/backend/event_processing/event_util.py +68 -0
  66. tensorbored/backend/event_processing/io_wrapper.py +223 -0
  67. tensorbored/backend/event_processing/plugin_asset_util.py +104 -0
  68. tensorbored/backend/event_processing/plugin_event_accumulator.py +721 -0
  69. tensorbored/backend/event_processing/plugin_event_multiplexer.py +522 -0
  70. tensorbored/backend/event_processing/reservoir.py +266 -0
  71. tensorbored/backend/event_processing/tag_types.py +29 -0
  72. tensorbored/backend/experiment_id.py +71 -0
  73. tensorbored/backend/experimental_plugin.py +51 -0
  74. tensorbored/backend/http_util.py +263 -0
  75. tensorbored/backend/json_util.py +70 -0
  76. tensorbored/backend/path_prefix.py +67 -0
  77. tensorbored/backend/process_graph.py +74 -0
  78. tensorbored/backend/security_validator.py +202 -0
  79. tensorbored/compat/__init__.py +69 -0
  80. tensorbored/compat/proto/__init__.py +0 -0
  81. tensorbored/compat/proto/allocation_description_pb2.py +35 -0
  82. tensorbored/compat/proto/api_def_pb2.py +82 -0
  83. tensorbored/compat/proto/attr_value_pb2.py +80 -0
  84. tensorbored/compat/proto/cluster_pb2.py +58 -0
  85. tensorbored/compat/proto/config_pb2.py +271 -0
  86. tensorbored/compat/proto/coordination_config_pb2.py +45 -0
  87. tensorbored/compat/proto/cost_graph_pb2.py +87 -0
  88. tensorbored/compat/proto/cpp_shape_inference_pb2.py +70 -0
  89. tensorbored/compat/proto/debug_pb2.py +65 -0
  90. tensorbored/compat/proto/event_pb2.py +149 -0
  91. tensorbored/compat/proto/full_type_pb2.py +74 -0
  92. tensorbored/compat/proto/function_pb2.py +157 -0
  93. tensorbored/compat/proto/graph_debug_info_pb2.py +111 -0
  94. tensorbored/compat/proto/graph_pb2.py +41 -0
  95. tensorbored/compat/proto/histogram_pb2.py +39 -0
  96. tensorbored/compat/proto/meta_graph_pb2.py +254 -0
  97. tensorbored/compat/proto/node_def_pb2.py +61 -0
  98. tensorbored/compat/proto/op_def_pb2.py +81 -0
  99. tensorbored/compat/proto/resource_handle_pb2.py +48 -0
  100. tensorbored/compat/proto/rewriter_config_pb2.py +93 -0
  101. tensorbored/compat/proto/rpc_options_pb2.py +35 -0
  102. tensorbored/compat/proto/saved_object_graph_pb2.py +193 -0
  103. tensorbored/compat/proto/saver_pb2.py +38 -0
  104. tensorbored/compat/proto/step_stats_pb2.py +116 -0
  105. tensorbored/compat/proto/struct_pb2.py +144 -0
  106. tensorbored/compat/proto/summary_pb2.py +111 -0
  107. tensorbored/compat/proto/tensor_description_pb2.py +38 -0
  108. tensorbored/compat/proto/tensor_pb2.py +68 -0
  109. tensorbored/compat/proto/tensor_shape_pb2.py +46 -0
  110. tensorbored/compat/proto/tfprof_log_pb2.py +307 -0
  111. tensorbored/compat/proto/trackable_object_graph_pb2.py +90 -0
  112. tensorbored/compat/proto/types_pb2.py +105 -0
  113. tensorbored/compat/proto/variable_pb2.py +62 -0
  114. tensorbored/compat/proto/verifier_config_pb2.py +38 -0
  115. tensorbored/compat/proto/versions_pb2.py +35 -0
  116. tensorbored/compat/tensorflow_stub/__init__.py +38 -0
  117. tensorbored/compat/tensorflow_stub/app.py +124 -0
  118. tensorbored/compat/tensorflow_stub/compat/__init__.py +131 -0
  119. tensorbored/compat/tensorflow_stub/compat/v1/__init__.py +20 -0
  120. tensorbored/compat/tensorflow_stub/dtypes.py +692 -0
  121. tensorbored/compat/tensorflow_stub/error_codes.py +169 -0
  122. tensorbored/compat/tensorflow_stub/errors.py +507 -0
  123. tensorbored/compat/tensorflow_stub/flags.py +124 -0
  124. tensorbored/compat/tensorflow_stub/io/__init__.py +17 -0
  125. tensorbored/compat/tensorflow_stub/io/gfile.py +1011 -0
  126. tensorbored/compat/tensorflow_stub/pywrap_tensorflow.py +285 -0
  127. tensorbored/compat/tensorflow_stub/tensor_shape.py +1035 -0
  128. tensorbored/context.py +129 -0
  129. tensorbored/data/__init__.py +0 -0
  130. tensorbored/data/grpc_provider.py +365 -0
  131. tensorbored/data/ingester.py +46 -0
  132. tensorbored/data/proto/__init__.py +0 -0
  133. tensorbored/data/proto/data_provider_pb2.py +517 -0
  134. tensorbored/data/proto/data_provider_pb2_grpc.py +374 -0
  135. tensorbored/data/provider.py +1365 -0
  136. tensorbored/data/server_ingester.py +301 -0
  137. tensorbored/data_compat.py +159 -0
  138. tensorbored/dataclass_compat.py +224 -0
  139. tensorbored/default.py +124 -0
  140. tensorbored/errors.py +130 -0
  141. tensorbored/lazy.py +99 -0
  142. tensorbored/main.py +48 -0
  143. tensorbored/main_lib.py +62 -0
  144. tensorbored/manager.py +487 -0
  145. tensorbored/notebook.py +441 -0
  146. tensorbored/plugin_util.py +266 -0
  147. tensorbored/plugins/__init__.py +0 -0
  148. tensorbored/plugins/audio/__init__.py +0 -0
  149. tensorbored/plugins/audio/audio_plugin.py +229 -0
  150. tensorbored/plugins/audio/metadata.py +69 -0
  151. tensorbored/plugins/audio/plugin_data_pb2.py +37 -0
  152. tensorbored/plugins/audio/summary.py +230 -0
  153. tensorbored/plugins/audio/summary_v2.py +124 -0
  154. tensorbored/plugins/base_plugin.py +367 -0
  155. tensorbored/plugins/core/__init__.py +0 -0
  156. tensorbored/plugins/core/core_plugin.py +981 -0
  157. tensorbored/plugins/custom_scalar/__init__.py +0 -0
  158. tensorbored/plugins/custom_scalar/custom_scalars_plugin.py +320 -0
  159. tensorbored/plugins/custom_scalar/layout_pb2.py +85 -0
  160. tensorbored/plugins/custom_scalar/metadata.py +35 -0
  161. tensorbored/plugins/custom_scalar/summary.py +79 -0
  162. tensorbored/plugins/debugger_v2/__init__.py +0 -0
  163. tensorbored/plugins/debugger_v2/debug_data_multiplexer.py +631 -0
  164. tensorbored/plugins/debugger_v2/debug_data_provider.py +634 -0
  165. tensorbored/plugins/debugger_v2/debugger_v2_plugin.py +504 -0
  166. tensorbored/plugins/distribution/__init__.py +0 -0
  167. tensorbored/plugins/distribution/compressor.py +158 -0
  168. tensorbored/plugins/distribution/distributions_plugin.py +116 -0
  169. tensorbored/plugins/distribution/metadata.py +19 -0
  170. tensorbored/plugins/graph/__init__.py +0 -0
  171. tensorbored/plugins/graph/graph_util.py +129 -0
  172. tensorbored/plugins/graph/graphs_plugin.py +336 -0
  173. tensorbored/plugins/graph/keras_util.py +328 -0
  174. tensorbored/plugins/graph/metadata.py +42 -0
  175. tensorbored/plugins/histogram/__init__.py +0 -0
  176. tensorbored/plugins/histogram/histograms_plugin.py +144 -0
  177. tensorbored/plugins/histogram/metadata.py +63 -0
  178. tensorbored/plugins/histogram/plugin_data_pb2.py +34 -0
  179. tensorbored/plugins/histogram/summary.py +234 -0
  180. tensorbored/plugins/histogram/summary_v2.py +292 -0
  181. tensorbored/plugins/hparams/__init__.py +14 -0
  182. tensorbored/plugins/hparams/_keras.py +93 -0
  183. tensorbored/plugins/hparams/api.py +130 -0
  184. tensorbored/plugins/hparams/api_pb2.py +208 -0
  185. tensorbored/plugins/hparams/backend_context.py +606 -0
  186. tensorbored/plugins/hparams/download_data.py +158 -0
  187. tensorbored/plugins/hparams/error.py +26 -0
  188. tensorbored/plugins/hparams/get_experiment.py +71 -0
  189. tensorbored/plugins/hparams/hparams_plugin.py +206 -0
  190. tensorbored/plugins/hparams/hparams_util_pb2.py +69 -0
  191. tensorbored/plugins/hparams/json_format_compat.py +38 -0
  192. tensorbored/plugins/hparams/list_metric_evals.py +57 -0
  193. tensorbored/plugins/hparams/list_session_groups.py +1040 -0
  194. tensorbored/plugins/hparams/metadata.py +125 -0
  195. tensorbored/plugins/hparams/metrics.py +41 -0
  196. tensorbored/plugins/hparams/plugin_data_pb2.py +69 -0
  197. tensorbored/plugins/hparams/summary.py +205 -0
  198. tensorbored/plugins/hparams/summary_v2.py +597 -0
  199. tensorbored/plugins/image/__init__.py +0 -0
  200. tensorbored/plugins/image/images_plugin.py +232 -0
  201. tensorbored/plugins/image/metadata.py +65 -0
  202. tensorbored/plugins/image/plugin_data_pb2.py +34 -0
  203. tensorbored/plugins/image/summary.py +159 -0
  204. tensorbored/plugins/image/summary_v2.py +130 -0
  205. tensorbored/plugins/mesh/__init__.py +14 -0
  206. tensorbored/plugins/mesh/mesh_plugin.py +292 -0
  207. tensorbored/plugins/mesh/metadata.py +152 -0
  208. tensorbored/plugins/mesh/plugin_data_pb2.py +37 -0
  209. tensorbored/plugins/mesh/summary.py +251 -0
  210. tensorbored/plugins/mesh/summary_v2.py +214 -0
  211. tensorbored/plugins/metrics/__init__.py +0 -0
  212. tensorbored/plugins/metrics/metadata.py +17 -0
  213. tensorbored/plugins/metrics/metrics_plugin.py +623 -0
  214. tensorbored/plugins/pr_curve/__init__.py +0 -0
  215. tensorbored/plugins/pr_curve/metadata.py +75 -0
  216. tensorbored/plugins/pr_curve/plugin_data_pb2.py +34 -0
  217. tensorbored/plugins/pr_curve/pr_curves_plugin.py +241 -0
  218. tensorbored/plugins/pr_curve/summary.py +574 -0
  219. tensorbored/plugins/profile_redirect/__init__.py +0 -0
  220. tensorbored/plugins/profile_redirect/profile_redirect_plugin.py +49 -0
  221. tensorbored/plugins/projector/__init__.py +67 -0
  222. tensorbored/plugins/projector/metadata.py +26 -0
  223. tensorbored/plugins/projector/projector_config_pb2.py +54 -0
  224. tensorbored/plugins/projector/projector_plugin.py +795 -0
  225. tensorbored/plugins/projector/tf_projector_plugin/index.js +32 -0
  226. tensorbored/plugins/projector/tf_projector_plugin/projector_binary.html +524 -0
  227. tensorbored/plugins/projector/tf_projector_plugin/projector_binary.js +15536 -0
  228. tensorbored/plugins/scalar/__init__.py +0 -0
  229. tensorbored/plugins/scalar/metadata.py +60 -0
  230. tensorbored/plugins/scalar/plugin_data_pb2.py +34 -0
  231. tensorbored/plugins/scalar/scalars_plugin.py +181 -0
  232. tensorbored/plugins/scalar/summary.py +109 -0
  233. tensorbored/plugins/scalar/summary_v2.py +124 -0
  234. tensorbored/plugins/text/__init__.py +0 -0
  235. tensorbored/plugins/text/metadata.py +62 -0
  236. tensorbored/plugins/text/plugin_data_pb2.py +34 -0
  237. tensorbored/plugins/text/summary.py +114 -0
  238. tensorbored/plugins/text/summary_v2.py +124 -0
  239. tensorbored/plugins/text/text_plugin.py +288 -0
  240. tensorbored/plugins/wit_redirect/__init__.py +0 -0
  241. tensorbored/plugins/wit_redirect/wit_redirect_plugin.py +49 -0
  242. tensorbored/program.py +910 -0
  243. tensorbored/summary/__init__.py +35 -0
  244. tensorbored/summary/_output.py +124 -0
  245. tensorbored/summary/_tf/__init__.py +14 -0
  246. tensorbored/summary/_tf/summary/__init__.py +178 -0
  247. tensorbored/summary/_writer.py +105 -0
  248. tensorbored/summary/v1.py +51 -0
  249. tensorbored/summary/v2.py +25 -0
  250. tensorbored/summary/writer/__init__.py +13 -0
  251. tensorbored/summary/writer/event_file_writer.py +291 -0
  252. tensorbored/summary/writer/record_writer.py +50 -0
  253. tensorbored/util/__init__.py +0 -0
  254. tensorbored/util/encoder.py +116 -0
  255. tensorbored/util/grpc_util.py +311 -0
  256. tensorbored/util/img_mime_type_detector.py +40 -0
  257. tensorbored/util/io_util.py +20 -0
  258. tensorbored/util/lazy_tensor_creator.py +110 -0
  259. tensorbored/util/op_evaluator.py +104 -0
  260. tensorbored/util/platform_util.py +20 -0
  261. tensorbored/util/tb_logging.py +24 -0
  262. tensorbored/util/tensor_util.py +617 -0
  263. tensorbored/util/timing.py +122 -0
  264. tensorbored/version.py +21 -0
  265. tensorbored/webfiles.zip +0 -0
  266. tensorbored-2.21.0rc1769983804.dist-info/METADATA +49 -0
  267. tensorbored-2.21.0rc1769983804.dist-info/RECORD +271 -0
  268. tensorbored-2.21.0rc1769983804.dist-info/WHEEL +5 -0
  269. tensorbored-2.21.0rc1769983804.dist-info/entry_points.txt +6 -0
  270. tensorbored-2.21.0rc1769983804.dist-info/licenses/LICENSE +739 -0
  271. tensorbored-2.21.0rc1769983804.dist-info/top_level.txt +1 -0
@@ -0,0 +1,950 @@
1
+ # Copyright 2015 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
+ """Takes a generator of values, and accumulates them for a frontend."""
16
+
17
+ import collections
18
+ import dataclasses
19
+ import threading
20
+
21
+ from typing import Optional, Sequence, Tuple
22
+
23
+ from tensorbored.backend.event_processing import directory_watcher
24
+ from tensorbored.backend.event_processing import event_file_loader
25
+ from tensorbored.backend.event_processing import event_util
26
+ from tensorbored.backend.event_processing import io_wrapper
27
+ from tensorbored.backend.event_processing import plugin_asset_util
28
+ from tensorbored.backend.event_processing import reservoir
29
+ from tensorbored.backend.event_processing import tag_types
30
+ from tensorbored.compat.proto import config_pb2
31
+ from tensorbored.compat.proto import event_pb2
32
+ from tensorbored.compat.proto import graph_pb2
33
+ from tensorbored.compat.proto import meta_graph_pb2
34
+ from tensorbored.compat.proto import tensor_pb2
35
+ from tensorbored.plugins.distribution import compressor
36
+ from tensorbored.util import tb_logging
37
+
38
+ logger = tb_logging.get_logger()
39
+
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
+
164
+
165
+ ## Different types of summary events handled by the event_accumulator
166
+ SUMMARY_TYPES = {
167
+ "simple_value": "_ProcessScalar",
168
+ "histo": "_ProcessHistogram",
169
+ "image": "_ProcessImage",
170
+ "audio": "_ProcessAudio",
171
+ "tensor": "_ProcessTensor",
172
+ }
173
+
174
+ # Legacy aliases
175
+ COMPRESSED_HISTOGRAMS = tag_types.COMPRESSED_HISTOGRAMS
176
+ HISTOGRAMS = tag_types.HISTOGRAMS
177
+ IMAGES = tag_types.IMAGES
178
+ AUDIO = tag_types.AUDIO
179
+ SCALARS = tag_types.SCALARS
180
+ TENSORS = tag_types.TENSORS
181
+ GRAPH = tag_types.GRAPH
182
+ META_GRAPH = tag_types.META_GRAPH
183
+ RUN_METADATA = tag_types.RUN_METADATA
184
+
185
+ ## Normal CDF for std_devs: (-Inf, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, Inf)
186
+ ## naturally gives bands around median of width 1 std dev, 2 std dev, 3 std dev,
187
+ ## and then the long tail.
188
+ NORMAL_HISTOGRAM_BPS = (0, 668, 1587, 3085, 5000, 6915, 8413, 9332, 10000)
189
+
190
+ DEFAULT_SIZE_GUIDANCE = {
191
+ COMPRESSED_HISTOGRAMS: 500,
192
+ IMAGES: 4,
193
+ AUDIO: 4,
194
+ SCALARS: 10000,
195
+ HISTOGRAMS: 1,
196
+ TENSORS: 10,
197
+ }
198
+
199
+ STORE_EVERYTHING_SIZE_GUIDANCE = {
200
+ COMPRESSED_HISTOGRAMS: 0,
201
+ IMAGES: 0,
202
+ AUDIO: 0,
203
+ SCALARS: 0,
204
+ HISTOGRAMS: 0,
205
+ TENSORS: 0,
206
+ }
207
+
208
+
209
+ class EventAccumulator:
210
+ """An `EventAccumulator` takes an event generator, and accumulates the
211
+ values.
212
+
213
+ The `EventAccumulator` is intended to provide a convenient Python interface
214
+ for loading Event data written during a TensorFlow run. TensorFlow writes out
215
+ `Event` protobuf objects, which have a timestamp and step number, and often
216
+ contain a `Summary`. Summaries can have different kinds of data like an image,
217
+ a scalar value, or a histogram. The Summaries also have a tag, which we use to
218
+ organize logically related data. The `EventAccumulator` supports retrieving
219
+ the `Event` and `Summary` data by its tag.
220
+
221
+ Calling `Tags()` gets a map from `tagType` (e.g. `'images'`,
222
+ `'compressedHistograms'`, `'scalars'`, etc) to the associated tags for those
223
+ data types. Then, various functional endpoints (eg
224
+ `Accumulator.Scalars(tag)`) allow for the retrieval of all data
225
+ associated with that tag.
226
+
227
+ The `Reload()` method synchronously loads all of the data written so far.
228
+
229
+ Histograms, audio, and images are very large, so storing all of them is not
230
+ recommended.
231
+
232
+ Fields:
233
+ audios: A reservoir.Reservoir of audio summaries.
234
+ compressed_histograms: A reservoir.Reservoir of compressed
235
+ histogram summaries.
236
+ histograms: A reservoir.Reservoir of histogram summaries.
237
+ images: A reservoir.Reservoir of image summaries.
238
+ most_recent_step: Step of last Event proto added. This should only
239
+ be accessed from the thread that calls Reload. This is -1 if
240
+ nothing has been loaded yet.
241
+ most_recent_wall_time: Timestamp of last Event proto added. This is
242
+ a float containing seconds from the UNIX epoch, or -1 if
243
+ nothing has been loaded yet. This should only be accessed from
244
+ the thread that calls Reload.
245
+ path: A file path to a directory containing tf events files, or a single
246
+ tf events file. The accumulator will load events from this path.
247
+ scalars: A reservoir.Reservoir of scalar summaries.
248
+ tensors: A reservoir.Reservoir of tensor summaries.
249
+
250
+ @@Tensors
251
+ """
252
+
253
+ def __init__(
254
+ self,
255
+ path,
256
+ size_guidance=None,
257
+ compression_bps=NORMAL_HISTOGRAM_BPS,
258
+ purge_orphaned_data=True,
259
+ ):
260
+ """Construct the `EventAccumulator`.
261
+
262
+ Args:
263
+ path: A file path to a directory containing tf events files, or a single
264
+ tf events file. The accumulator will load events from this path.
265
+ size_guidance: Information on how much data the EventAccumulator should
266
+ store in memory. The DEFAULT_SIZE_GUIDANCE tries not to store too much
267
+ so as to avoid OOMing the client. The size_guidance should be a map
268
+ from a `tagType` string to an integer representing the number of
269
+ items to keep per tag for items of that `tagType`. If the size is 0,
270
+ all events are stored.
271
+ compression_bps: Information on how the `EventAccumulator` should compress
272
+ histogram data for the `CompressedHistograms` tag (for details see
273
+ `ProcessCompressedHistogram`).
274
+ purge_orphaned_data: Whether to discard any events that were "orphaned" by
275
+ a TensorFlow restart.
276
+ """
277
+ size_guidance = size_guidance or DEFAULT_SIZE_GUIDANCE
278
+ sizes = {}
279
+ for key in DEFAULT_SIZE_GUIDANCE:
280
+ if key in size_guidance:
281
+ sizes[key] = size_guidance[key]
282
+ else:
283
+ sizes[key] = DEFAULT_SIZE_GUIDANCE[key]
284
+
285
+ self._first_event_timestamp = None
286
+ self.scalars = reservoir.Reservoir(size=sizes[SCALARS])
287
+
288
+ self._graph = None
289
+ self._graph_from_metagraph = False
290
+ self._meta_graph = None
291
+ self._tagged_metadata = {}
292
+ self.summary_metadata = {}
293
+ self.histograms = reservoir.Reservoir(size=sizes[HISTOGRAMS])
294
+ self.compressed_histograms = reservoir.Reservoir(
295
+ size=sizes[COMPRESSED_HISTOGRAMS], always_keep_last=False
296
+ )
297
+ self.images = reservoir.Reservoir(size=sizes[IMAGES])
298
+ self.audios = reservoir.Reservoir(size=sizes[AUDIO])
299
+ self.tensors = reservoir.Reservoir(size=sizes[TENSORS])
300
+
301
+ # Keep a mapping from plugin name to a dict mapping from tag to plugin data
302
+ # content obtained from the SummaryMetadata (metadata field of Value) for
303
+ # that plugin (This is not the entire SummaryMetadata proto - only the
304
+ # content for that plugin). The SummaryWriter only keeps the content on the
305
+ # first event encountered per tag, so we must store that first instance of
306
+ # content for each tag.
307
+ self._plugin_to_tag_to_content = collections.defaultdict(dict)
308
+
309
+ self._generator_mutex = threading.Lock()
310
+ self.path = path
311
+ self._generator = _GeneratorFromPath(path)
312
+
313
+ self._compression_bps = compression_bps
314
+ self.purge_orphaned_data = purge_orphaned_data
315
+
316
+ self.most_recent_step = -1
317
+ self.most_recent_wall_time = -1
318
+ self.file_version = None
319
+
320
+ # Name of the source writer that writes the event.
321
+ self._source_writer = None
322
+
323
+ # The attributes that get built up by the accumulator
324
+ self.accumulated_attrs = (
325
+ "scalars",
326
+ "histograms",
327
+ "compressed_histograms",
328
+ "images",
329
+ "audios",
330
+ )
331
+ self._tensor_summaries = {}
332
+
333
+ def Reload(self):
334
+ """Loads all events added since the last call to `Reload`.
335
+
336
+ If `Reload` was never called, loads all events in the file.
337
+
338
+ Returns:
339
+ The `EventAccumulator`.
340
+ """
341
+ with self._generator_mutex:
342
+ for event in self._generator.Load():
343
+ self._ProcessEvent(event)
344
+ return self
345
+
346
+ def PluginAssets(self, plugin_name):
347
+ """Return a list of all plugin assets for the given plugin.
348
+
349
+ Args:
350
+ plugin_name: The string name of a plugin to retrieve assets for.
351
+
352
+ Returns:
353
+ A list of string plugin asset names, or empty list if none are available.
354
+ If the plugin was not registered, an empty list is returned.
355
+ """
356
+ return plugin_asset_util.ListAssets(self.path, plugin_name)
357
+
358
+ def RetrievePluginAsset(self, plugin_name, asset_name):
359
+ """Return the contents of a given plugin asset.
360
+
361
+ Args:
362
+ plugin_name: The string name of a plugin.
363
+ asset_name: The string name of an asset.
364
+
365
+ Returns:
366
+ The string contents of the plugin asset.
367
+
368
+ Raises:
369
+ KeyError: If the asset is not available.
370
+ """
371
+ return plugin_asset_util.RetrieveAsset(
372
+ self.path, plugin_name, asset_name
373
+ )
374
+
375
+ def FirstEventTimestamp(self):
376
+ """Returns the timestamp in seconds of the first event.
377
+
378
+ If the first event has been loaded (either by this method or by `Reload`,
379
+ this returns immediately. Otherwise, it will load in the first event. Note
380
+ that this means that calling `Reload` will cause this to block until
381
+ `Reload` has finished.
382
+
383
+ Returns:
384
+ The timestamp in seconds of the first event that was loaded.
385
+
386
+ Raises:
387
+ ValueError: If no events have been loaded and there were no events found
388
+ on disk.
389
+ """
390
+ if self._first_event_timestamp is not None:
391
+ return self._first_event_timestamp
392
+ with self._generator_mutex:
393
+ try:
394
+ event = next(self._generator.Load())
395
+ self._ProcessEvent(event)
396
+ return self._first_event_timestamp
397
+
398
+ except StopIteration:
399
+ raise ValueError("No event timestamp could be found")
400
+
401
+ def GetSourceWriter(self) -> Optional[str]:
402
+ """Returns the name of the event writer."""
403
+ if self._source_writer is not None:
404
+ return self._source_writer
405
+ with self._generator_mutex:
406
+ try:
407
+ event = next(self._generator.Load())
408
+ self._ProcessEvent(event)
409
+ return self._source_writer
410
+ except StopIteration:
411
+ logger.info(
412
+ "End of file in %s, no source writer was found.", self.path
413
+ )
414
+
415
+ def PluginTagToContent(self, plugin_name):
416
+ """Returns a dict mapping tags to content specific to that plugin.
417
+
418
+ Args:
419
+ plugin_name: The name of the plugin for which to fetch plugin-specific
420
+ content.
421
+
422
+ Raises:
423
+ KeyError: if the plugin name is not found.
424
+
425
+ Returns:
426
+ A dict mapping tag names to bytestrings of plugin-specific content-- by
427
+ convention, in the form of binary serialized protos.
428
+ """
429
+ if plugin_name not in self._plugin_to_tag_to_content:
430
+ raise KeyError("Plugin %r could not be found." % plugin_name)
431
+ return self._plugin_to_tag_to_content[plugin_name]
432
+
433
+ def SummaryMetadata(self, tag):
434
+ """Given a summary tag name, return the associated metadata object.
435
+
436
+ Args:
437
+ tag: The name of a tag, as a string.
438
+
439
+ Raises:
440
+ KeyError: If the tag is not found.
441
+
442
+ Returns:
443
+ A `SummaryMetadata` protobuf.
444
+ """
445
+ return self.summary_metadata[tag]
446
+
447
+ def _ProcessEvent(self, event):
448
+ """Called whenever an event is loaded."""
449
+ if self._first_event_timestamp is None:
450
+ self._first_event_timestamp = event.wall_time
451
+
452
+ if event.HasField("source_metadata"):
453
+ new_source_writer = event_util.GetSourceWriter(
454
+ event.source_metadata
455
+ )
456
+ if self._source_writer and self._source_writer != new_source_writer:
457
+ logger.info(
458
+ (
459
+ "Found new source writer for event.proto. "
460
+ "Old: {0}, New: {1}"
461
+ ).format(self._source_writer, new_source_writer)
462
+ )
463
+ self._source_writer = new_source_writer
464
+
465
+ if event.HasField("file_version"):
466
+ new_file_version = event_util.ParseFileVersion(event.file_version)
467
+ if self.file_version and self.file_version != new_file_version:
468
+ ## This should not happen.
469
+ logger.warning(
470
+ (
471
+ "Found new file_version for event.proto. This will "
472
+ "affect purging logic for TensorFlow restarts. "
473
+ "Old: {0} New: {1}"
474
+ ).format(self.file_version, new_file_version)
475
+ )
476
+ self.file_version = new_file_version
477
+
478
+ self._MaybePurgeOrphanedData(event)
479
+
480
+ ## Process the event.
481
+ # GraphDef and MetaGraphDef are handled in a special way:
482
+ # If no graph_def Event is available, but a meta_graph_def is, and it
483
+ # contains a graph_def, then use the meta_graph_def.graph_def as our graph.
484
+ # If a graph_def Event is available, always prefer it to the graph_def
485
+ # inside the meta_graph_def.
486
+ if event.HasField("graph_def"):
487
+ if self._graph is not None:
488
+ logger.warning(
489
+ (
490
+ "Found more than one graph event per run, or there was "
491
+ "a metagraph containing a graph_def, as well as one or "
492
+ "more graph events. Overwriting the graph with the "
493
+ "newest event."
494
+ )
495
+ )
496
+ self._graph = event.graph_def
497
+ self._graph_from_metagraph = False
498
+ elif event.HasField("meta_graph_def"):
499
+ if self._meta_graph is not None:
500
+ logger.warning(
501
+ (
502
+ "Found more than one metagraph event per run. "
503
+ "Overwriting the metagraph with the newest event."
504
+ )
505
+ )
506
+ self._meta_graph = event.meta_graph_def
507
+ if self._graph is None or self._graph_from_metagraph:
508
+ # We may have a graph_def in the metagraph. If so, and no
509
+ # graph_def is directly available, use this one instead.
510
+ meta_graph = meta_graph_pb2.MetaGraphDef()
511
+ meta_graph.ParseFromString(self._meta_graph)
512
+ if meta_graph.graph_def:
513
+ if self._graph is not None:
514
+ logger.warning(
515
+ (
516
+ "Found multiple metagraphs containing graph_defs,"
517
+ "but did not find any graph events. Overwriting the "
518
+ "graph with the newest metagraph version."
519
+ )
520
+ )
521
+ self._graph_from_metagraph = True
522
+ self._graph = meta_graph.graph_def.SerializeToString()
523
+ elif event.HasField("tagged_run_metadata"):
524
+ tag = event.tagged_run_metadata.tag
525
+ if tag in self._tagged_metadata:
526
+ logger.warning(
527
+ 'Found more than one "run metadata" event with tag '
528
+ + tag
529
+ + ". Overwriting it with the newest event."
530
+ )
531
+ self._tagged_metadata[tag] = event.tagged_run_metadata.run_metadata
532
+ elif event.HasField("summary"):
533
+ for value in event.summary.value:
534
+ if value.HasField("metadata"):
535
+ tag = value.tag
536
+ # We only store the first instance of the metadata. This check
537
+ # is important: the `FileWriter` does strip metadata from all
538
+ # values except the first one per each tag, but a new
539
+ # `FileWriter` is created every time a training job stops and
540
+ # restarts. Hence, we must also ignore non-initial metadata in
541
+ # this logic.
542
+ if tag not in self.summary_metadata:
543
+ self.summary_metadata[tag] = value.metadata
544
+ plugin_data = value.metadata.plugin_data
545
+ if plugin_data.plugin_name:
546
+ self._plugin_to_tag_to_content[
547
+ plugin_data.plugin_name
548
+ ][tag] = plugin_data.content
549
+ else:
550
+ logger.warning(
551
+ (
552
+ "This summary with tag %r is oddly not associated with a "
553
+ "plugin."
554
+ ),
555
+ tag,
556
+ )
557
+
558
+ for summary_type, summary_func in SUMMARY_TYPES.items():
559
+ if value.HasField(summary_type):
560
+ datum = getattr(value, summary_type)
561
+ tag = value.tag
562
+ if summary_type == "tensor" and not tag:
563
+ # This tensor summary was created using the old method that used
564
+ # plugin assets. We must still continue to support it.
565
+ tag = value.node_name
566
+ getattr(self, summary_func)(
567
+ tag, event.wall_time, event.step, datum
568
+ )
569
+
570
+ def Tags(self):
571
+ """Return all tags found in the value stream.
572
+
573
+ Returns:
574
+ A `{tagType: ['list', 'of', 'tags']}` dictionary.
575
+ """
576
+ return {
577
+ IMAGES: self.images.Keys(),
578
+ AUDIO: self.audios.Keys(),
579
+ HISTOGRAMS: self.histograms.Keys(),
580
+ SCALARS: self.scalars.Keys(),
581
+ COMPRESSED_HISTOGRAMS: self.compressed_histograms.Keys(),
582
+ TENSORS: self.tensors.Keys(),
583
+ # Use a heuristic: if the metagraph is available, but
584
+ # graph is not, then we assume the metagraph contains the graph.
585
+ GRAPH: self._graph is not None,
586
+ META_GRAPH: self._meta_graph is not None,
587
+ RUN_METADATA: list(self._tagged_metadata.keys()),
588
+ }
589
+
590
+ def Scalars(self, tag):
591
+ """Given a summary tag, return all associated `ScalarEvent`s.
592
+
593
+ Args:
594
+ tag: A string tag associated with the events.
595
+
596
+ Raises:
597
+ KeyError: If the tag is not found.
598
+
599
+ Returns:
600
+ An array of `ScalarEvent`s.
601
+ """
602
+ return self.scalars.Items(tag)
603
+
604
+ def Graph(self):
605
+ """Return the graph definition, if there is one.
606
+
607
+ If the graph is stored directly, return that. If no graph is stored
608
+ directly but a metagraph is stored containing a graph, return that.
609
+
610
+ Raises:
611
+ ValueError: If there is no graph for this run.
612
+
613
+ Returns:
614
+ The `graph_def` proto.
615
+ """
616
+ graph = graph_pb2.GraphDef()
617
+ if self._graph is not None:
618
+ graph.ParseFromString(self._graph)
619
+ return graph
620
+ raise ValueError("There is no graph in this EventAccumulator")
621
+
622
+ def MetaGraph(self):
623
+ """Return the metagraph definition, if there is one.
624
+
625
+ Raises:
626
+ ValueError: If there is no metagraph for this run.
627
+
628
+ Returns:
629
+ The `meta_graph_def` proto.
630
+ """
631
+ if self._meta_graph is None:
632
+ raise ValueError("There is no metagraph in this EventAccumulator")
633
+ meta_graph = meta_graph_pb2.MetaGraphDef()
634
+ meta_graph.ParseFromString(self._meta_graph)
635
+ return meta_graph
636
+
637
+ def RunMetadata(self, tag):
638
+ """Given a tag, return the associated session.run() metadata.
639
+
640
+ Args:
641
+ tag: A string tag associated with the event.
642
+
643
+ Raises:
644
+ ValueError: If the tag is not found.
645
+
646
+ Returns:
647
+ The metadata in form of `RunMetadata` proto.
648
+ """
649
+ if tag not in self._tagged_metadata:
650
+ raise ValueError("There is no run metadata with this tag name")
651
+
652
+ run_metadata = config_pb2.RunMetadata()
653
+ run_metadata.ParseFromString(self._tagged_metadata[tag])
654
+ return run_metadata
655
+
656
+ def Histograms(self, tag):
657
+ """Given a summary tag, return all associated histograms.
658
+
659
+ Args:
660
+ tag: A string tag associated with the events.
661
+
662
+ Raises:
663
+ KeyError: If the tag is not found.
664
+
665
+ Returns:
666
+ An array of `HistogramEvent`s.
667
+ """
668
+ return self.histograms.Items(tag)
669
+
670
+ def CompressedHistograms(self, tag):
671
+ """Given a summary tag, return all associated compressed histograms.
672
+
673
+ Args:
674
+ tag: A string tag associated with the events.
675
+
676
+ Raises:
677
+ KeyError: If the tag is not found.
678
+
679
+ Returns:
680
+ An array of `CompressedHistogramEvent`s.
681
+ """
682
+ return self.compressed_histograms.Items(tag)
683
+
684
+ def Images(self, tag):
685
+ """Given a summary tag, return all associated images.
686
+
687
+ Args:
688
+ tag: A string tag associated with the events.
689
+
690
+ Raises:
691
+ KeyError: If the tag is not found.
692
+
693
+ Returns:
694
+ An array of `ImageEvent`s.
695
+ """
696
+ return self.images.Items(tag)
697
+
698
+ def Audio(self, tag):
699
+ """Given a summary tag, return all associated audio.
700
+
701
+ Args:
702
+ tag: A string tag associated with the events.
703
+
704
+ Raises:
705
+ KeyError: If the tag is not found.
706
+
707
+ Returns:
708
+ An array of `AudioEvent`s.
709
+ """
710
+ return self.audios.Items(tag)
711
+
712
+ def Tensors(self, tag):
713
+ """Given a summary tag, return all associated tensors.
714
+
715
+ Args:
716
+ tag: A string tag associated with the events.
717
+
718
+ Raises:
719
+ KeyError: If the tag is not found.
720
+
721
+ Returns:
722
+ An array of `TensorEvent`s.
723
+ """
724
+ return self.tensors.Items(tag)
725
+
726
+ def _MaybePurgeOrphanedData(self, event):
727
+ """Maybe purge orphaned data due to a TensorFlow crash.
728
+
729
+ When TensorFlow crashes at step T+O and restarts at step T, any events
730
+ written after step T are now "orphaned" and will be at best misleading if
731
+ they are included in TensorBoard.
732
+
733
+ This logic attempts to determine if there is orphaned data, and purge it
734
+ if it is found.
735
+
736
+ Args:
737
+ event: The event to use as a reference, to determine if a purge is needed.
738
+ """
739
+ if not self.purge_orphaned_data:
740
+ return
741
+ ## Check if the event happened after a crash, and purge expired tags.
742
+ if self.file_version and self.file_version >= 2:
743
+ ## If the file_version is recent enough, use the SessionLog enum
744
+ ## to check for restarts.
745
+ self._CheckForRestartAndMaybePurge(event)
746
+ else:
747
+ ## If there is no file version, default to old logic of checking for
748
+ ## out of order steps.
749
+ self._CheckForOutOfOrderStepAndMaybePurge(event)
750
+
751
+ def _CheckForRestartAndMaybePurge(self, event):
752
+ """Check and discard expired events using SessionLog.START.
753
+
754
+ Check for a SessionLog.START event and purge all previously seen events
755
+ with larger steps, because they are out of date. Because of supervisor
756
+ threading, it is possible that this logic will cause the first few event
757
+ messages to be discarded since supervisor threading does not guarantee
758
+ that the START message is deterministically written first.
759
+
760
+ This method is preferred over _CheckForOutOfOrderStepAndMaybePurge which
761
+ can inadvertently discard events due to supervisor threading.
762
+
763
+ Args:
764
+ event: The event to use as reference. If the event is a START event, all
765
+ previously seen events with a greater event.step will be purged.
766
+ """
767
+ if (
768
+ event.HasField("session_log")
769
+ and event.session_log.status == event_pb2.SessionLog.START
770
+ ):
771
+ self._Purge(event, by_tags=False)
772
+
773
+ def _CheckForOutOfOrderStepAndMaybePurge(self, event):
774
+ """Check for out-of-order event.step and discard expired events for
775
+ tags.
776
+
777
+ Check if the event is out of order relative to the global most recent step.
778
+ If it is, purge outdated summaries for tags that the event contains.
779
+
780
+ Args:
781
+ event: The event to use as reference. If the event is out-of-order, all
782
+ events with the same tags, but with a greater event.step will be purged.
783
+ """
784
+ if event.step < self.most_recent_step and event.HasField("summary"):
785
+ self._Purge(event, by_tags=True)
786
+ else:
787
+ self.most_recent_step = event.step
788
+ self.most_recent_wall_time = event.wall_time
789
+
790
+ def _ConvertHistogramProtoToPopo(self, histo):
791
+ """Converts histogram proto to Python object."""
792
+ return HistogramValue(
793
+ min=histo.min,
794
+ max=histo.max,
795
+ num=histo.num,
796
+ sum=histo.sum,
797
+ sum_squares=histo.sum_squares,
798
+ bucket_limit=list(histo.bucket_limit),
799
+ bucket=list(histo.bucket),
800
+ )
801
+
802
+ def _ProcessHistogram(self, tag, wall_time, step, histo):
803
+ """Processes a proto histogram by adding it to accumulated state."""
804
+ histo = self._ConvertHistogramProtoToPopo(histo)
805
+ histo_ev = HistogramEvent(wall_time, step, histo)
806
+ self.histograms.AddItem(tag, histo_ev)
807
+ self.compressed_histograms.AddItem(
808
+ tag, histo_ev, self._CompressHistogram
809
+ )
810
+
811
+ def _CompressHistogram(self, histo_ev):
812
+ """Callback for _ProcessHistogram."""
813
+ return CompressedHistogramEvent(
814
+ histo_ev.wall_time,
815
+ histo_ev.step,
816
+ compressor.compress_histogram_proto(
817
+ histo_ev.histogram_value, self._compression_bps
818
+ ),
819
+ )
820
+
821
+ def _ProcessImage(self, tag, wall_time, step, image):
822
+ """Processes an image by adding it to accumulated state."""
823
+ event = ImageEvent(
824
+ wall_time=wall_time,
825
+ step=step,
826
+ encoded_image_string=image.encoded_image_string,
827
+ width=image.width,
828
+ height=image.height,
829
+ )
830
+ self.images.AddItem(tag, event)
831
+
832
+ def _ProcessAudio(self, tag, wall_time, step, audio):
833
+ """Processes a audio by adding it to accumulated state."""
834
+ event = AudioEvent(
835
+ wall_time=wall_time,
836
+ step=step,
837
+ encoded_audio_string=audio.encoded_audio_string,
838
+ content_type=audio.content_type,
839
+ sample_rate=audio.sample_rate,
840
+ length_frames=audio.length_frames,
841
+ )
842
+ self.audios.AddItem(tag, event)
843
+
844
+ def _ProcessScalar(self, tag, wall_time, step, scalar):
845
+ """Processes a simple value by adding it to accumulated state."""
846
+ sv = ScalarEvent(wall_time=wall_time, step=step, value=scalar)
847
+ self.scalars.AddItem(tag, sv)
848
+
849
+ def _ProcessTensor(self, tag, wall_time, step, tensor):
850
+ tv = TensorEvent(wall_time=wall_time, step=step, tensor_proto=tensor)
851
+ self.tensors.AddItem(tag, tv)
852
+
853
+ def _Purge(self, event, by_tags):
854
+ """Purge all events that have occurred after the given event.step.
855
+
856
+ If by_tags is True, purge all events that occurred after the given
857
+ event.step, but only for the tags that the event has. Non-sequential
858
+ event.steps suggest that a TensorFlow restart occurred, and we discard
859
+ the out-of-order events to display a consistent view in TensorBoard.
860
+
861
+ Discarding by tags is the safer method, when we are unsure whether a restart
862
+ has occurred, given that threading in supervisor can cause events of
863
+ different tags to arrive with unsynchronized step values.
864
+
865
+ If by_tags is False, then purge all events with event.step greater than the
866
+ given event.step. This can be used when we are certain that a TensorFlow
867
+ restart has occurred and these events can be discarded.
868
+
869
+ Args:
870
+ event: The event to use as reference for the purge. All events with
871
+ the same tags, but with a greater event.step will be purged.
872
+ by_tags: Bool to dictate whether to discard all out-of-order events or
873
+ only those that are associated with the given reference event.
874
+ """
875
+ ## Keep data in reservoirs that has a step less than event.step
876
+ _NotExpired = lambda x: x.step < event.step
877
+
878
+ if by_tags:
879
+
880
+ def _ExpiredPerTag(value):
881
+ return [
882
+ getattr(self, x).FilterItems(_NotExpired, value.tag)
883
+ for x in self.accumulated_attrs
884
+ ]
885
+
886
+ expired_per_tags = [
887
+ _ExpiredPerTag(value) for value in event.summary.value
888
+ ]
889
+ expired_per_type = [sum(x) for x in zip(*expired_per_tags)]
890
+ else:
891
+ expired_per_type = [
892
+ getattr(self, x).FilterItems(_NotExpired)
893
+ for x in self.accumulated_attrs
894
+ ]
895
+
896
+ if sum(expired_per_type) > 0:
897
+ purge_msg = _GetPurgeMessage(
898
+ self.most_recent_step,
899
+ self.most_recent_wall_time,
900
+ event.step,
901
+ event.wall_time,
902
+ *expired_per_type,
903
+ )
904
+ logger.warning(purge_msg)
905
+
906
+
907
+ def _GetPurgeMessage(
908
+ most_recent_step,
909
+ most_recent_wall_time,
910
+ event_step,
911
+ event_wall_time,
912
+ num_expired_scalars,
913
+ num_expired_histos,
914
+ num_expired_comp_histos,
915
+ num_expired_images,
916
+ num_expired_audio,
917
+ ):
918
+ """Return the string message associated with TensorBoard purges."""
919
+ return (
920
+ "Detected out of order event.step likely caused by "
921
+ "a TensorFlow restart. Purging expired events from Tensorboard"
922
+ " display between the previous step: {} (timestamp: {}) and "
923
+ "current step: {} (timestamp: {}). Removing {} scalars, {} "
924
+ "histograms, {} compressed histograms, {} images, "
925
+ "and {} audio."
926
+ ).format(
927
+ most_recent_step,
928
+ most_recent_wall_time,
929
+ event_step,
930
+ event_wall_time,
931
+ num_expired_scalars,
932
+ num_expired_histos,
933
+ num_expired_comp_histos,
934
+ num_expired_images,
935
+ num_expired_audio,
936
+ )
937
+
938
+
939
+ def _GeneratorFromPath(path):
940
+ """Create an event generator for file or directory at given path string."""
941
+ if not path:
942
+ raise ValueError("path must be a valid string")
943
+ if io_wrapper.IsSummaryEventsFile(path):
944
+ return event_file_loader.LegacyEventFileLoader(path)
945
+ else:
946
+ return directory_watcher.DirectoryWatcher(
947
+ path,
948
+ event_file_loader.LegacyEventFileLoader,
949
+ io_wrapper.IsSummaryEventsFile,
950
+ )