MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / bbox_flip

Function bbox_flip

detrsmpl/core/post_processing/bbox/transforms.py:22–48  ·  view source on GitHub ↗

Flip bboxes horizontally or vertically. Args: bboxes (Tensor): Shape (..., 4*k) img_shape (tuple): Image shape. direction (str): Flip direction, options are "horizontal", "vertical", "diagonal". Default: "horizontal" Returns: Tensor: Flipped bbox

(bboxes, img_shape, direction='horizontal')

Source from the content-addressed store, hash-verified

20
21
22def bbox_flip(bboxes, img_shape, direction='horizontal'):
23 """Flip bboxes horizontally or vertically.
24
25 Args:
26 bboxes (Tensor): Shape (..., 4*k)
27 img_shape (tuple): Image shape.
28 direction (str): Flip direction, options are "horizontal", "vertical",
29 "diagonal". Default: "horizontal"
30
31 Returns:
32 Tensor: Flipped bboxes.
33 """
34 assert bboxes.shape[-1] % 4 == 0
35 assert direction in ['horizontal', 'vertical', 'diagonal']
36 flipped = bboxes.clone()
37 if direction == 'horizontal':
38 flipped[..., 0::4] = img_shape[1] - bboxes[..., 2::4]
39 flipped[..., 2::4] = img_shape[1] - bboxes[..., 0::4]
40 elif direction == 'vertical':
41 flipped[..., 1::4] = img_shape[0] - bboxes[..., 3::4]
42 flipped[..., 3::4] = img_shape[0] - bboxes[..., 1::4]
43 else:
44 flipped[..., 0::4] = img_shape[1] - bboxes[..., 2::4]
45 flipped[..., 1::4] = img_shape[0] - bboxes[..., 3::4]
46 flipped[..., 2::4] = img_shape[1] - bboxes[..., 0::4]
47 flipped[..., 3::4] = img_shape[0] - bboxes[..., 1::4]
48 return flipped
49
50
51def bbox_mapping(bboxes,

Callers 2

bbox_mappingFunction · 0.85
bbox_mapping_backFunction · 0.85

Calls 1

cloneMethod · 0.80

Tested by

no test coverage detected