Skip to content

Commit

Permalink
fix(data): training bug for rectangle input (#620)
Browse files Browse the repository at this point in the history
This PR fixes the performance degradation when training with rectangle image shapes.
  • Loading branch information
GOATmessi7 committed Aug 31, 2021
1 parent d17bef8 commit 69f1173
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/manipulate_training_image_size.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This tutorial explains how to control your image size when training on your own

There are 3 hyperparamters control the training size:

- self.input_size = (640, 640)
- self.input_size = (640, 640)   #(height, width)
- self.multiscale_range = 5
- self.random_size = (14, 26)

Expand Down
10 changes: 6 additions & 4 deletions yolox/exp/yolox_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self):
# ---------------- dataloader config ---------------- #
# set worker to 4 for shorter dataloader init time
self.data_num_workers = 4
self.input_size = (640, 640)
self.input_size = (640, 640) # (height, width)
# Actual multiscale ranges: [640-5*32, 640+5*32].
# To disable multiscale training, set the
# self.multiscale_range to 0.
Expand Down Expand Up @@ -185,12 +185,14 @@ def random_resize(self, data_loader, epoch, rank, is_distributed):
return input_size

def preprocess(self, inputs, targets, tsize):
scale = tsize[0] / self.input_size[0]
if scale != 1:
scale_y = tsize[0] / self.input_size[0]
scale_x = tsize[1] / self.input_size[1]
if scale_x != 1 or scale_y != 1:
inputs = nn.functional.interpolate(
inputs, size=tsize, mode="bilinear", align_corners=False
)
targets[..., 1:] = targets[..., 1:] * scale
targets[..., 1::2] = targets[..., 1::2] * scale_x
targets[..., 2::2] = targets[..., 2::2] * scale_y
return inputs, targets

def get_optimizer(self, batch_size):
Expand Down

0 comments on commit 69f1173

Please sign in to comment.