Skip to content

Commit dba3eec

Browse files
ppwwyyxxfacebook-github-bot
authored andcommitted
avoid list[ndarray] -> tensor conversion in Boxes
Summary: avoid wanings like: ``` detectron2/structures/boxes.py:158: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at torch/csrc/utils/tensor_new.cpp:201.) ``` Reviewed By: wat3rBro Differential Revision: D30172338 fbshipit-source-id: fbe044fead72722b3c6eb9916faa2a7dca3e6eae
1 parent 7825f07 commit dba3eec

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

detectron2/data/detection_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ def annotations_to_instances(annos, image_size, mask_format="polygon"):
376376
"gt_masks", "gt_keypoints", if they can be obtained from `annos`.
377377
This is the format that builtin models expect.
378378
"""
379-
boxes = [BoxMode.convert(obj["bbox"], obj["bbox_mode"], BoxMode.XYXY_ABS) for obj in annos]
379+
boxes = np.stack(
380+
[BoxMode.convert(obj["bbox"], obj["bbox_mode"], BoxMode.XYXY_ABS) for obj in annos]
381+
)
380382
target = Instances(image_size)
381383
target.gt_boxes = Boxes(boxes)
382384

0 commit comments

Comments
 (0)