Skip to content

Commit

Permalink
fix(data): fix a potential bug when mosaic_prob!=1 (#660)
Browse files Browse the repository at this point in the history
Co-authored-by: Songtao Liu <ruinmessi@gmail.com>
  • Loading branch information
Joker316701882 and GOATmessi7 committed Sep 7, 2021
1 parent a0cef73 commit 146d1ee
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions yolox/data/datasets/mosaicdetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __getitem__(self, idx):
indices = [idx] + [random.randint(0, len(self._dataset) - 1) for _ in range(3)]

for i_mosaic, index in enumerate(indices):
img, _labels, _, _ = self._dataset.pull_item(index)
img, _labels, _, img_id = self._dataset.pull_item(index)
h0, w0 = img.shape[:2] # orig hw
scale = min(1. * input_h / h0, 1. * input_w / w0)
img = cv2.resize(
Expand Down Expand Up @@ -150,13 +150,17 @@ def __getitem__(self, idx):
mix_img, padded_labels = self.preproc(mosaic_img, mosaic_labels, self.input_dim)
img_info = (mix_img.shape[1], mix_img.shape[0])

return mix_img, padded_labels, img_info, np.array([idx])
# -----------------------------------------------------------------
# img_info and img_id are not used for training.
# They are also hard to be specified on a mosaic image.
# -----------------------------------------------------------------
return mix_img, padded_labels, img_info, img_id

else:
self._dataset._input_dim = self.input_dim
img, label, img_info, idx = self._dataset.pull_item(idx)
img, label, img_info, img_id = self._dataset.pull_item(idx)
img, label = self.preproc(img, label, self.input_dim)
return img, label, img_info, np.array([idx])
return img, label, img_info, img_id

def mixup(self, origin_img, origin_labels, input_dim):
jit_factor = random.uniform(*self.mixup_scale)
Expand Down

0 comments on commit 146d1ee

Please sign in to comment.