MCPcopy Create free account
hub / github.com/tensorflow/tensorboard / _migrate_histogram_value

Function _migrate_histogram_value

tensorboard/data_compat.py:83–123  ·  view source on GitHub ↗

Convert `old-style` histogram value to `new-style`. The "old-style" format can have outermost bucket limits of -DBL_MAX and DBL_MAX, which are problematic for visualization. We replace those here with the actual min and max values seen in the input data, but then in order to avoid i

(value)

Source from the content-addressed store, hash-verified

81
82
83def _migrate_histogram_value(value):
84 """Convert `old-style` histogram value to `new-style`.
85
86 The "old-style" format can have outermost bucket limits of -DBL_MAX and
87 DBL_MAX, which are problematic for visualization. We replace those here
88 with the actual min and max values seen in the input data, but then in
89 order to avoid introducing "backwards" buckets (where left edge > right
90 edge), we first must drop all empty buckets on the left and right ends.
91 """
92 histogram_value = value.histo
93 bucket_counts = histogram_value.bucket
94 # Find the indices of the leftmost and rightmost non-empty buckets.
95 n = len(bucket_counts)
96 start = next((i for i in range(n) if bucket_counts[i] > 0), n)
97 end = next((i for i in reversed(range(n)) if bucket_counts[i] > 0), -1)
98 if start > end:
99 # If all input buckets were empty, treat it as a zero-bucket
100 # new-style histogram.
101 buckets = np.zeros([0, 3], dtype=np.float32)
102 else:
103 # Discard empty buckets on both ends, and keep only the "inner"
104 # edges from the remaining buckets. Note that bucket indices range
105 # from `start` to `end` inclusive, but bucket_limit indices are
106 # exclusive of `end` - this is because bucket_limit[i] is the
107 # right-hand edge for bucket[i].
108 bucket_counts = bucket_counts[start : end + 1]
109 inner_edges = histogram_value.bucket_limit[start:end]
110 # Use min as the left-hand limit for the first non-empty bucket.
111 bucket_lefts = [histogram_value.min] + inner_edges
112 # Use max as the right-hand limit for the last non-empty bucket.
113 bucket_rights = inner_edges + [histogram_value.max]
114 buckets = np.array(
115 [bucket_lefts, bucket_rights, bucket_counts], dtype=np.float32
116 ).transpose()
117
118 summary_metadata = histogram_metadata.create_summary_metadata(
119 display_name=value.metadata.display_name or value.tag,
120 description=value.metadata.summary_description,
121 )
122
123 return make_summary(value.tag, summary_metadata, buckets)
124
125
126def _migrate_image_value(value):

Callers

nothing calls this directly

Calls 2

rangeFunction · 0.85
make_summaryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…