Skip to content

Commit

Permalink
fix: Check for degenerate boxes outside transformations loop
Browse files Browse the repository at this point in the history
Previously, the data generator only checked for degenerate boxes when any transformations were given. Now the check is always being performed, even if no transformations were given.
  • Loading branch information
pierluigiferrari committed Apr 12, 2018
1 parent a8b9310 commit cd5de00
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions object_detection_2d_data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,27 +732,27 @@ def generate(self,

batch_inverse_transforms.append(inverse_transforms[::-1])

#########################################################################################
# Check for degenerate boxes in this batch item.
#########################################################################################

xmin = self.labels_format['xmin']
ymin = self.labels_format['ymin']
xmax = self.labels_format['xmax']
ymax = self.labels_format['ymax']

# Check for degenerate ground truth bounding boxes before attempting any computations.
if np.any(batch_y[i][:,xmax] - batch_y[i][:,xmin] <= 0) or np.any(batch_y[i][:,ymax] - batch_y[i][:,ymin] <= 0):
if degenerate_box_handling == 'warn':
warnings.warn("Detected degenerate ground truth bounding boxes for batch item {} with bounding boxes {}, ".format(i, batch_y[i]) +
"i.e. bounding boxes where xmax <= xmin and/or ymax <= ymin. " +
"This could mean that your dataset contains degenerate ground truth boxes, or that any image transformations you may apply might " +
"result in degenerate ground truth boxes, or that you are parsing the ground truth in the wrong coordinate format." +
"Degenerate ground truth bounding boxes may lead to NaN errors during the training.")
elif degenerate_box_handling == 'remove':
batch_y[i] = box_filter(batch_y[i])
if (batch_y[i].size == 0) and not keep_images_without_gt:
batch_items_to_remove.append(i)
#########################################################################################
# Check for degenerate boxes in this batch item.
#########################################################################################

xmin = self.labels_format['xmin']
ymin = self.labels_format['ymin']
xmax = self.labels_format['xmax']
ymax = self.labels_format['ymax']

# Check for degenerate ground truth bounding boxes before attempting any computations.
if np.any(batch_y[i][:,xmax] - batch_y[i][:,xmin] <= 0) or np.any(batch_y[i][:,ymax] - batch_y[i][:,ymin] <= 0):
if degenerate_box_handling == 'warn':
warnings.warn("Detected degenerate ground truth bounding boxes for batch item {} with bounding boxes {}, ".format(i, batch_y[i]) +
"i.e. bounding boxes where xmax <= xmin and/or ymax <= ymin. " +
"This could mean that your dataset contains degenerate ground truth boxes, or that any image transformations you may apply might " +
"result in degenerate ground truth boxes, or that you are parsing the ground truth in the wrong coordinate format." +
"Degenerate ground truth bounding boxes may lead to NaN errors during the training.")
elif degenerate_box_handling == 'remove':
batch_y[i] = box_filter(batch_y[i])
if (batch_y[i].size == 0) and not keep_images_without_gt:
batch_items_to_remove.append(i)

#########################################################################################
# Remove any items we might not want to keep from the batch.
Expand Down

0 comments on commit cd5de00

Please sign in to comment.