"models/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "a9f0785dec5dc2f07cb3613c84c02cce39740e8a"
Commit 7e88ce3e authored by Yu-hui Chen's avatar Yu-hui Chen Committed by TF Object Detection Team
Browse files

Removed the logics that uses nan/inf values in the postprocessing function in

CenterNetMetaArch. It is to make sure the model can be post-quantizable and
doesn't generate calibration errors during quantization.

PiperOrigin-RevId: 370528566
parent 6f1ddc42
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
import abc import abc
import collections import collections
import functools import functools
import numpy as np
import tensorflow.compat.v1 as tf import tensorflow.compat.v1 as tf
import tensorflow.compat.v2 as tf2 import tensorflow.compat.v2 as tf2
...@@ -945,12 +944,6 @@ def refine_keypoints(regressed_keypoints, ...@@ -945,12 +944,6 @@ def refine_keypoints(regressed_keypoints,
num_candidates_tiled = tf.tile(tf.expand_dims(num_keypoint_candidates, 1), num_candidates_tiled = tf.tile(tf.expand_dims(num_keypoint_candidates, 1),
[1, max_candidates, 1]) [1, max_candidates, 1])
invalid_candidates = range_tiled >= num_candidates_tiled invalid_candidates = range_tiled >= num_candidates_tiled
nan_mask = tf.where(
invalid_candidates,
np.nan * tf.ones_like(invalid_candidates, dtype=tf.float32),
tf.ones_like(invalid_candidates, dtype=tf.float32))
keypoint_candidates_with_nans = tf.math.multiply(
keypoint_candidates, tf.expand_dims(nan_mask, -1))
# Pairwise squared distances between regressed keypoints and candidate # Pairwise squared distances between regressed keypoints and candidate
# keypoints (for a single keypoint type). # keypoints (for a single keypoint type).
...@@ -959,7 +952,7 @@ def refine_keypoints(regressed_keypoints, ...@@ -959,7 +952,7 @@ def refine_keypoints(regressed_keypoints,
axis=2) axis=2)
# Shape [batch_size, 1, max_candidates, num_keypoints, 2]. # Shape [batch_size, 1, max_candidates, num_keypoints, 2].
keypoint_candidates_expanded = tf.expand_dims( keypoint_candidates_expanded = tf.expand_dims(
keypoint_candidates_with_nans, axis=1) keypoint_candidates, axis=1)
# Use explicit tensor shape broadcasting (since the tensor dimensions are # Use explicit tensor shape broadcasting (since the tensor dimensions are
# expanded to 5D) to make it tf.lite compatible. # expanded to 5D) to make it tf.lite compatible.
regressed_keypoint_expanded = tf.tile( regressed_keypoint_expanded = tf.tile(
...@@ -973,10 +966,16 @@ def refine_keypoints(regressed_keypoints, ...@@ -973,10 +966,16 @@ def refine_keypoints(regressed_keypoints,
sqrd_distances = tf.math.reduce_sum(tf.multiply(diff, diff), axis=-1) sqrd_distances = tf.math.reduce_sum(tf.multiply(diff, diff), axis=-1)
distances = tf.math.sqrt(sqrd_distances) distances = tf.math.sqrt(sqrd_distances)
# Replace the NaNs with Infs to make sure the following reduce_min/argmin # Replace the invalid candidated with large constant (10^5) to make sure the
# behaves properly. # following reduce_min/argmin behaves properly.
max_dist = 1e5
distances = tf.where( distances = tf.where(
tf.math.is_nan(distances), np.inf * tf.ones_like(distances), distances) tf.tile(
tf.expand_dims(invalid_candidates, axis=1),
multiples=[1, num_instances, 1, 1]),
tf.ones_like(distances) * max_dist,
distances
)
# Determine the candidates that have the minimum distance to the regressed # Determine the candidates that have the minimum distance to the regressed
# keypoints. Shape [batch_size, num_instances, num_keypoints]. # keypoints. Shape [batch_size, num_instances, num_keypoints].
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment