Skip to content

Commit 915d485

Browse files
chihuahuanfelt
authored andcommitted
Make pr_curves_demo manually implement clip (#1132)
TensorFlow commits tensorflow/tensorflow@083cf6b and tensorflow/tensorflow@daf0b20 have made their way into `tf-nightly` build 254. The commits modified the behavior of the `tf.clip_by_value` op in an attempt to resolve tensorflow/tensorflow#7225 in a way that minimizes memory usage by taking different pathways of logic based on characteristics of the system running TensorFlow. Unfortunately, our python 2 and python 3 setups on travis differ along those characteristics, causing the `tf-nightly` build to break `:pr_curves_test` (which relies on the demo to generate test data) for python 2 only. This PR fixes the test by removing usages of `tf.clip_by_value` from the demo and instead uses `tf.maximum(minValue, tf.minimum(maxValue, value))`. The most fulfilling solution for this bug would be to resolve the mismatch in behavior of `tf.clip_by_value` on the TensorFlow side. However, this PR unblocks development of TensorBoard immediately.
1 parent 88e4677 commit 915d485

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

tensorboard/plugins/pr_curve/pr_curve_demo.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,51 @@ def start_runs(
7070
# Sample the distribution to generate colors. Lets generate different numbers
7171
# of each color. The first dimension is the count of examples.
7272

73+
def clip(value, minValue, maxValue):
74+
"""Clips an op to the range [minValue, maxValue].
75+
76+
For now, we intentionally avoid using tf.clip_by_value because it
77+
apparently exhibits slightly different behavior based on system
78+
characteristics. See tensorflow/tensorflow#18527. Tests rely on this demo,
79+
so behavior must be consistent.
80+
81+
Args:
82+
value: The value to clip.
83+
minValue: The min value to clip by.
84+
maxValue: The max value to clip by.
85+
86+
Returns:
87+
A TensorFlow op that outputs the clipped value.
88+
"""
89+
return tf.maximum(minValue, tf.minimum(maxValue, value))
90+
7391
# Generate reds.
7492
number_of_reds = 100
75-
true_reds = tf.clip_by_value(
93+
true_reds = clip(
7694
tf.concat([
77-
255 - tf.abs(channel_distribution.sample([number_of_reds, 1])),
95+
255. - tf.abs(channel_distribution.sample([number_of_reds, 1])),
7896
tf.abs(channel_distribution.sample([number_of_reds, 2]))
7997
], axis=1),
80-
0, 255)
98+
0., 255.)
8199

82100
# Generate greens.
83101
number_of_greens = 200
84-
true_greens = tf.clip_by_value(
102+
true_greens = clip(
85103
tf.concat([
86104
tf.abs(channel_distribution.sample([number_of_greens, 1])),
87-
255 - tf.abs(channel_distribution.sample([number_of_greens, 1])),
105+
255. - tf.abs(channel_distribution.sample([number_of_greens, 1])),
88106
tf.abs(channel_distribution.sample([number_of_greens, 1]))
89107
], axis=1),
90-
0, 255)
108+
0., 255.)
91109

92110
# Generate blues.
93111
number_of_blues = 150
94-
true_blues = tf.clip_by_value(
112+
true_blues = clip(
95113
tf.concat([
96114
tf.abs(channel_distribution.sample([number_of_blues, 2])),
97-
255 - tf.abs(channel_distribution.sample([number_of_blues, 1]))
115+
255. - tf.abs(channel_distribution.sample([number_of_blues, 1]))
98116
], axis=1),
99-
0, 255)
117+
0., 255.)
100118

101119
# Assign each color a vector of 3 booleans based on its true label.
102120
labels = tf.concat([

0 commit comments

Comments
 (0)