Unverified Commit 7e2f7a35 authored by srihari-humbarwadi's avatar srihari-humbarwadi
Browse files

check `valid_indices` shape

parent 603d702d
...@@ -163,46 +163,52 @@ class PanopticSegmentationGenerator(tf.keras.layers.Layer): ...@@ -163,46 +163,52 @@ class PanopticSegmentationGenerator(tf.keras.layers.Layer):
# filter instances with low confidence # filter instances with low confidence
sorted_scores = tf.sort(scores, direction='DESCENDING') sorted_scores = tf.sort(scores, direction='DESCENDING')
loop_end_idx = tf.where(sorted_scores > self._score_threshold)[-1, 0] + 1
loop_end_idx = tf.minimum( valid_indices = tf.where(sorted_scores > self._score_threshold)
tf.cast(loop_end_idx, dtype=tf.int32),
self._max_num_detections) # if no instance has sufficient confidence score, skip merging
# instance segmentation masks
# add things segmentation to panoptic masks if tf.shape(valid_indices)[0] > 0:
for i in range(loop_end_idx): loop_end_idx = valid_indices[-1, 0] + 1
# we process instances in decending order, which will make sure loop_end_idx = tf.minimum(
# the overlaps are resolved based on confidence score tf.cast(loop_end_idx, dtype=tf.int32),
instance_idx = sorted_indices[i] self._max_num_detections)
pasted_mask = self._paste_mask( # add things segmentation to panoptic masks
box=boxes[instance_idx], for i in range(loop_end_idx):
mask=detections_masks[instance_idx]) # we process instances in decending order, which will make sure
# the overlaps are resolved based on confidence score
class_id = tf.cast(classes[instance_idx], dtype=tf.float32) instance_idx = sorted_indices[i]
# convert sigmoid scores to binary values pasted_mask = self._paste_mask(
binary_mask = tf.greater( box=boxes[instance_idx],
pasted_mask, self._mask_binarize_threshold) mask=detections_masks[instance_idx])
# filter empty instance masks class_id = tf.cast(classes[instance_idx], dtype=tf.float32)
if not tf.reduce_sum(tf.cast(binary_mask, tf.float32)) > 0:
continue # convert sigmoid scores to binary values
binary_mask = tf.greater(
# fill empty regions in category_mask represented by pasted_mask, self._mask_binarize_threshold)
# void_class_label with class_id of the instance.
category_mask = tf.where( # filter empty instance masks
tf.logical_and( if not tf.reduce_sum(tf.cast(binary_mask, tf.float32)) > 0:
binary_mask, tf.equal(category_mask, self._void_class_label)), continue
tf.ones_like(category_mask) * class_id, category_mask)
# fill empty regions in category_mask represented by
# fill empty regions in the instance_mask represented by # void_class_label with class_id of the instance.
# void_instance_id with the id of the instance, starting from 1 category_mask = tf.where(
instance_mask = tf.where( tf.logical_and(
tf.logical_and( binary_mask, tf.equal(category_mask, self._void_class_label)),
binary_mask, tf.ones_like(category_mask) * class_id, category_mask)
tf.equal(instance_mask, self._void_instance_id)),
tf.ones_like(instance_mask) * # fill empty regions in the instance_mask represented by
tf.cast(instance_idx + 1, tf.float32), instance_mask) # void_instance_id with the id of the instance, starting from 1
instance_mask = tf.where(
tf.logical_and(
binary_mask,
tf.equal(instance_mask, self._void_instance_id)),
tf.ones_like(instance_mask) *
tf.cast(instance_idx + 1, tf.float32), instance_mask)
# add stuff segmentation labels to empty regions of category_mask. # add stuff segmentation labels to empty regions of category_mask.
# we ignore the pixels labelled as "things", since we get them from # we ignore the pixels labelled as "things", since we get them from
......
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