Skip to content

Commit 4b25417

Browse files
chihuahuanfelt
authored andcommitted
Use tf.clip_by_value again in PR curves demo (#1150)
Previously, #1132 had circumvented the use of `tf.clip_by_value` within the PR curves demo because it was buggy. However, that behavior seems to have been fixed.
1 parent 70ef986 commit 4b25417

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

tensorboard/plugins/pr_curve/pr_curve_demo.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,51 +70,33 @@ 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-
9173
# Generate reds.
9274
number_of_reds = 100
93-
true_reds = clip(
75+
true_reds = tf.clip_by_value(
9476
tf.concat([
95-
255. - tf.abs(channel_distribution.sample([number_of_reds, 1])),
77+
255 - tf.abs(channel_distribution.sample([number_of_reds, 1])),
9678
tf.abs(channel_distribution.sample([number_of_reds, 2]))
9779
], axis=1),
98-
0., 255.)
80+
0, 255)
9981

10082
# Generate greens.
10183
number_of_greens = 200
102-
true_greens = clip(
84+
true_greens = tf.clip_by_value(
10385
tf.concat([
10486
tf.abs(channel_distribution.sample([number_of_greens, 1])),
105-
255. - tf.abs(channel_distribution.sample([number_of_greens, 1])),
87+
255 - tf.abs(channel_distribution.sample([number_of_greens, 1])),
10688
tf.abs(channel_distribution.sample([number_of_greens, 1]))
10789
], axis=1),
108-
0., 255.)
90+
0, 255)
10991

11092
# Generate blues.
11193
number_of_blues = 150
112-
true_blues = clip(
94+
true_blues = tf.clip_by_value(
11395
tf.concat([
11496
tf.abs(channel_distribution.sample([number_of_blues, 2])),
115-
255. - tf.abs(channel_distribution.sample([number_of_blues, 1]))
97+
255 - tf.abs(channel_distribution.sample([number_of_blues, 1]))
11698
], axis=1),
117-
0., 255.)
99+
0, 255)
118100

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

0 commit comments

Comments
 (0)