From e3c334e57fba9afc0b0a3aa5f7787ee35e17ddf6 Mon Sep 17 00:00:00 2001 From: "Yan Facai (颜发才)" Date: Wed, 12 Sep 2018 14:59:44 +0800 Subject: CLN: remove unnecessary math_ops.maximum --- tensorflow/contrib/losses/python/losses/loss_ops.py | 11 ++++------- tensorflow/contrib/metrics/python/ops/metric_ops.py | 8 ++++---- tensorflow/python/keras/engine/training_utils.py | 3 +-- tensorflow/python/keras/metrics.py | 2 +- tensorflow/python/ops/losses/losses_impl.py | 4 +--- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/tensorflow/contrib/losses/python/losses/loss_ops.py b/tensorflow/contrib/losses/python/losses/loss_ops.py index 66322140cb..7e5ab05987 100644 --- a/tensorflow/contrib/losses/python/losses/loss_ops.py +++ b/tensorflow/contrib/losses/python/losses/loss_ops.py @@ -78,9 +78,7 @@ def _safe_mean(losses, num_present): then zero is returned. """ total_loss = math_ops.reduce_sum(losses) - return math_ops.div_no_nan(total_loss, - math_ops.maximum(num_present, 0), - name="value") + return math_ops.div_no_nan(total_loss, num_present, name="value") @deprecated("2016-12-30", "Use tf.losses.compute_weighted_loss instead.") @@ -585,10 +583,9 @@ def mean_pairwise_squared_error(predictions, math_ops.square(diffs), reduction_indices=reduction_indices) num_present_per_batch = _num_present(diffs, weights, per_batch=True) - term1 = 2.0 * math_ops.div_no_nan( - sum_squares_diff_per_batch, - math_ops.maximum(num_present_per_batch, 0), - name="value") + term1 = 2.0 * math_ops.div_no_nan(sum_squares_diff_per_batch, + num_present_per_batch, + name="value") sum_diff = math_ops.reduce_sum(diffs, reduction_indices=reduction_indices) term2 = 2.0 * math_ops.div_no_nan(math_ops.square(sum_diff), diff --git a/tensorflow/contrib/metrics/python/ops/metric_ops.py b/tensorflow/contrib/metrics/python/ops/metric_ops.py index d7c73c8f99..91939b5bf2 100644 --- a/tensorflow/contrib/metrics/python/ops/metric_ops.py +++ b/tensorflow/contrib/metrics/python/ops/metric_ops.py @@ -3222,11 +3222,11 @@ def streaming_covariance(predictions, # batch_mean_prediction is E[x_B] in the update equation batch_mean_prediction = math_ops.div_no_nan( math_ops.reduce_sum(weighted_predictions), - math_ops.maximum(batch_count, 0), + batch_count, name='batch_mean_prediction') delta_mean_prediction = math_ops.div_no_nan( (batch_mean_prediction - mean_prediction) * batch_count, - math_ops.maximum(update_count, 0), + update_count, name='delta_mean_prediction') update_mean_prediction = state_ops.assign_add(mean_prediction, delta_mean_prediction) @@ -3236,11 +3236,11 @@ def streaming_covariance(predictions, # batch_mean_label is E[y_B] in the update equation batch_mean_label = math_ops.div_no_nan( math_ops.reduce_sum(weighted_labels), - math_ops.maximum(batch_count, 0), + batch_count, name='batch_mean_label') delta_mean_label = math_ops.div_no_nan( (batch_mean_label - mean_label) * batch_count, - math_ops.maximum(update_count, 0), + update_count, name='delta_mean_label') update_mean_label = state_ops.assign_add(mean_label, delta_mean_label) # prev_mean_label is E[y_A] in the update equation diff --git a/tensorflow/python/keras/engine/training_utils.py b/tensorflow/python/keras/engine/training_utils.py index 9082b9f0fa..c23168ccef 100644 --- a/tensorflow/python/keras/engine/training_utils.py +++ b/tensorflow/python/keras/engine/training_utils.py @@ -613,8 +613,7 @@ def weighted_masked_objective(fn): score_array = math_ops.multiply(score_array, weights) score_array = math_ops.reduce_sum(score_array) weights = math_ops.reduce_sum(weights) - score_array = math_ops.div_no_nan(score_array, - math_ops.maximum(weights, 0)) + score_array = math_ops.div_no_nan(score_array, weights) return K.mean(score_array) return weighted diff --git a/tensorflow/python/keras/metrics.py b/tensorflow/python/keras/metrics.py index 4050eb95a4..f85b6554bd 100644 --- a/tensorflow/python/keras/metrics.py +++ b/tensorflow/python/keras/metrics.py @@ -488,7 +488,7 @@ class Mean(Metric): state_ops.assign_add(self.count, num_values) def result(self): - return math_ops.div_no_nan(self.total, math_ops.maximum(self.count, 0)) + return math_ops.div_no_nan(self.total, self.count) class MeanMetricWrapper(Mean): diff --git a/tensorflow/python/ops/losses/losses_impl.py b/tensorflow/python/ops/losses/losses_impl.py index 2035aaf9fe..fe4950a475 100644 --- a/tensorflow/python/ops/losses/losses_impl.py +++ b/tensorflow/python/ops/losses/losses_impl.py @@ -86,9 +86,7 @@ def _safe_mean(losses, num_present): then zero is returned. """ total_loss = math_ops.reduce_sum(losses) - return math_ops.div_no_nan(total_loss, - math_ops.maximum(num_present, 0), - name="value") + return math_ops.div_no_nan(total_loss, num_present, name="value") def _num_present(losses, weights, per_batch=False): -- cgit v1.2.3