Skip to content

Commit

Permalink
fix(torch): data augmentation handle dummy bboxes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Bycob authored and mergify[bot] committed Jan 31, 2023
1 parent 041b649 commit 53d0c39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/backends/torch/torchdataset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,24 @@ namespace dd
std::vector<torch::Tensor> t_sample = t;
if (_segmentation)
bw_target_sample = bw_target.clone();
bool no_bbox = false;
if (_bbox)
{
auto &cls_bbox = t_sample.at(1);
no_bbox = cls_bbox.numel() == 1 && cls_bbox.item<int>() == 0;
}

// data augmentation can apply here, with OpenCV
if (!_test)
{
if (_bbox)
_img_rand_aug_cv.augment_with_bbox(bgr_sample, t_sample);
{
// don't augment dummy bbox
if (no_bbox)
_img_rand_aug_cv.augment(bgr_sample);
else
_img_rand_aug_cv.augment_with_bbox(bgr_sample, t_sample);
}
else if (_segmentation)
_img_rand_aug_cv.augment_with_segmap(bgr_sample,
bw_target_sample);
Expand All @@ -412,7 +424,12 @@ namespace dd
// cropping requires test set 'augmentation'
if (_bbox)
{
_img_rand_aug_cv.augment_test_with_bbox(bgr_sample, t_sample);
// don't augment dummy bbox
if (no_bbox)
_img_rand_aug_cv.augment_test(bgr_sample);
else
_img_rand_aug_cv.augment_test_with_bbox(bgr_sample,
t_sample);
}
else if (_segmentation)
_img_rand_aug_cv.augment_test_with_segmap(bgr_sample,
Expand Down
2 changes: 1 addition & 1 deletion tools/torch/trace_yolox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
- Export dd-trained yolox model to onnx for trt inference:
python3 trace_yolox.py -v yolox[-s|-m|-l|...] --yolox_path [YOLOX_PATH] --output_dir [OUTPUT_DIR] --from_repo [DD_REPO] --to_onnx
"""
""", formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("model", type=str, help="Model to export")
parser.add_argument(
Expand Down

0 comments on commit 53d0c39

Please sign in to comment.