Skip to content

Commit

Permalink
feat: allow pure negative samples for training object detectors with …
Browse files Browse the repository at this point in the history
…torch
  • Loading branch information
beniz authored and mergify[bot] committed Feb 11, 2022
1 parent 9bc840f commit cd23bad
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/backends/torch/torchdataset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,16 @@ namespace dd
bboxes.push_back(target_to_tensor(bbox));
}

// allow for no bbox (pure negative sample) with an empty tensor
// XXX: yolox only, that discards 0 boxes internally
if (bboxes.empty())
{
std::vector<double> empty_bbox = { 0.0, 0.0, 0.0, 0.0 };
bboxes.push_back(target_to_tensor(empty_bbox));
int cls = 0;
classes.push_back(target_to_tensor(cls));
}

// add image
add_image_batch(dimg._imgs[0], height, width,
{ torch::stack(bboxes), torch::cat(classes) });
Expand Down

0 comments on commit cd23bad

Please sign in to comment.