Skip to content

Commit

Permalink
fix: Fix removal of batch items from batch
Browse files Browse the repository at this point in the history
Previously, if batch items were supposed to be deleted from the batch, the process tried to pop() items from a Numpy array. Fixed now.
  • Loading branch information
pierluigiferrari committed Jan 18, 2018
1 parent 9293cf3 commit 9509bb9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ssd_batch_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,22 +1177,22 @@ def generate(self,
else:
batch_X[i] = np.expand_dims(batch_X[i], axis=-1)

# CAUTION: Converting `batch_X` into an array will result in an empty batch if the images have varying sizes.
# At this point, all images must have the same size, otherwise you will get an error during training.
batch_X = np.array(batch_X)

if not keep_images_without_gt:
# If any batch items need to be removed because of failed random cropping, remove them now.
batch_inverse_coord_transform = np.delete(batch_inverse_coord_transform, batch_items_to_remove, axis=0)
batch_X = np.delete(batch_X, batch_items_to_remove, axis=0)
for j in sorted(batch_items_to_remove, reverse=True):
# This isn't efficient, but it hopefully should not need to be done often anyway.
batch_X.pop(j)
batch_filenames.pop(j)
batch_inverse_coord_transform.pop(j)
if not batch_y is None: batch_y.pop(j)
if not batch_imgage_ids is None: batch_image_ids.pop(j)
if 'original_images' in returns: batch_original_images.pop(j)
if 'original_labels' in returns and not batch_y is None: batch_original_labels.pop(j)

# CAUTION: Converting `batch_X` into an array will result in an empty batch if the images have varying sizes.
# At this point, all images must have the same size, otherwise you will get an error during training.
batch_X = np.array(batch_X)

# Perform image transformations that can be bulk-applied to the whole batch.
if not (subtract_mean is None):
batch_X = batch_X.astype(np.int16) - np.array(subtract_mean)
Expand Down

0 comments on commit 9509bb9

Please sign in to comment.