pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
16.25k stars 6.96k forks source link

conversion to coco format changes bboxes in dataset #4943

Closed noreen-walker closed 11 months ago

noreen-walker commented 3 years ago

🐛 Describe the bug

I'm following the object detection tutorial here which uses the coco evaluation metrics.

It uses convert_to_coco_api in https://github.com/pytorch/vision/blob/main/references/detection/coco_utils.py to convert a dataset to coco format.

But when the bounding boxes are preloaded into memory in a dataset (i.e. not generated on the fly like in the tutorial) this conversion changes them in place. So the dataset gets modified unexpectedly. I think it happens here : bboxes[:, 2:] -= bboxes[:, :2] and could be fixed by doing a copy first.

Versions

not applicable

Marentor commented 11 months ago

Thanks for the fix. Can confirm after copy code works perfectly.

vfdev-5 commented 11 months ago

Inplace bboxes update was fixed in the method convert_to_coco_api by https://github.com/pytorch/vision/pull/5289 Now it does: https://github.com/pytorch/vision/blob/c35d3855ccbfa6a36e6ae6337a1f2c721c1f1e78/references/detection/coco_utils.py#L138-L139 so, technically there is no need to copy boxes in the user code.

vfdev-5 commented 11 months ago

Let's close this issue as solved, feel free to open a new issue if any related problem appear.