test_coco_annotations_to_detections result matrices defined in place

This commit is contained in:
magda skoczen 2024-05-15 08:55:47 +02:00
parent cccacab621
commit aab861c2db
1 changed files with 79 additions and 137 deletions

View File

@ -233,186 +233,128 @@ def test_group_coco_annotations_by_image_id(
[
mock_cock_coco_annotation(
category_id=0,
bbox=(0, 0, 10, 10),
area=10 * 10,
segmentation=[[0, 0, 4, 0, 4, 5, 9, 5, 9, 9, 0, 9]],
bbox=(0, 0, 5, 5),
area= 5 * 5,
segmentation=[[0, 0, 2, 0, 2, 2, 4, 2, 4, 4, 0, 4]],
)
],
(20, 20),
(5, 5),
True,
Detections(
xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),
xyxy=np.array([[0, 0, 5, 5]], dtype=np.float32),
class_id=np.array([0], dtype=int),
mask=np.array(
[
0 if i >= 10 or j >= 10 or (i < 5 and j >= 5) else 1
for i in range(0, 20)
for j in range(0, 20)
]
).reshape((1, 20, 20)),
mask=np.array([[[1, 1, 1, 0, 0],
[1, 1, 1, 0, 0],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]]]),
),
DoesNotRaise(),
), # single image annotations with mask, segmentation mask in L-like shape,
# like below:
# 1 0 0 0
# 1 1 0 0
# 0 0 0 0
# 0 0 0 0
), # single image annotations with mask as polygon
(
[
mock_cock_coco_annotation(
category_id=0,
bbox=(0, 0, 10, 10),
area=10 * 10,
segmentation={
"size": [20, 20],
"counts": [
0,
10,
10,
10,
10,
10,
10,
10,
10,
10,
15,
5,
15,
5,
15,
5,
15,
5,
15,
5,
210,
],
},
iscrowd=True,
)
],
(20, 20),
True,
Detections(
xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),
class_id=np.array([0], dtype=int),
mask=np.array(
[
0 if i >= 10 or j >= 10 or (i < 5 and j >= 5) else 1
for i in range(0, 20)
for j in range(0, 20)
]
).reshape((1, 20, 20)),
),
DoesNotRaise(),
), # single image annotations with mask, RLE segmentation mask in L-like shape,
# like below:
# 1 0 0 0
# 1 1 0 0
# 0 0 0 0
# 0 0 0 0
(
[
mock_cock_coco_annotation(
category_id=0,
bbox=(0, 0, 10, 10),
area=10 * 10,
segmentation=[[0, 0, 4, 0, 4, 5, 9, 5, 9, 9, 0, 9]],
),
mock_cock_coco_annotation(
category_id=0,
bbox=(5, 0, 5, 5),
bbox=(0, 0, 5, 5),
area=5 * 5,
segmentation={
"size": [20, 20],
"counts": [100, 5, 15, 5, 15, 5, 15, 5, 15, 5, 215],
"size": [5, 5],
"counts": [0, 15, 2, 3, 2, 3],
},
iscrowd=True,
)
],
(5, 5),
True,
Detections(
xyxy=np.array([[0, 0, 5, 5]], dtype=np.float32),
class_id=np.array([0], dtype=int),
mask=np.array([[[1, 1, 1, 0, 0],
[1, 1, 1, 0, 0],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]]]),
),
DoesNotRaise(),
), # single image annotations with mask, RLE segmentation mask
(
[
mock_cock_coco_annotation(
category_id=0,
bbox=(0, 0, 5, 5),
area= 5 * 5,
segmentation=[[0, 0, 2, 0, 2, 2, 4, 2, 4, 4, 0, 4]],
),
mock_cock_coco_annotation(
category_id=0,
bbox=(3, 0, 2, 2),
area=2 * 2,
segmentation={
"size": [5, 5],
"counts": [15, 2, 3, 2, 3],
},
iscrowd=True,
),
],
(20, 20),
(5, 5),
True,
Detections(
xyxy=np.array([[0, 0, 10, 10], [5, 0, 10, 5]], dtype=np.float32),
xyxy=np.array([[0, 0, 5, 5], [3, 0, 5, 2]], dtype=np.float32),
class_id=np.array([0, 0], dtype=int),
mask=np.array(
[
np.array(
[
0 if i >= 10 or j >= 10 or (i < 5 and j >= 5) else 1
for i in range(0, 20)
for j in range(0, 20)
]
).reshape((20, 20)),
np.array(
[
1 if j > 4 and j < 10 and i < 5 else 0
for i in range(0, 20)
for j in range(0, 20)
]
).reshape((20, 20)),
]
),
mask=np.array([ [[1, 1, 1, 0, 0],
[1, 1, 1, 0, 0],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]],
[[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]])
),
DoesNotRaise(),
), # two image annotations with mask, one mask as polygon in in L-like shape,
# second as RLE in shape of square, like below (P = polygon, R = RLE):
# P R 0 0
# P P 0 0
# 0 0 0 0
# 0 0 0 0
), # two image annotations with mask, one mask as polygon ans second as RLE
(
[
mock_cock_coco_annotation(
category_id=0,
bbox=(5, 0, 5, 5),
area=5 * 5,
bbox=(3, 0, 2, 2),
area=2 * 2,
segmentation={
"size": [20, 20],
"counts": [100, 5, 15, 5, 15, 5, 15, 5, 15, 5, 215],
"size": [5, 5],
"counts": [15, 2, 3, 2, 3],
},
iscrowd=True,
),
mock_cock_coco_annotation(
category_id=1,
bbox=(0, 0, 10, 10),
area=10 * 10,
segmentation=[[0, 0, 4, 0, 4, 5, 9, 5, 9, 9, 0, 9]],
bbox=(0, 0, 5, 5),
area= 5 * 5,
segmentation=[[0, 0, 2, 0, 2, 2, 4, 2, 4, 4, 0, 4]],
),
],
(20, 20),
(5, 5),
True,
Detections(
xyxy=np.array([[5, 0, 10, 5], [0, 0, 10, 10]], dtype=np.float32),
xyxy=np.array([[3, 0, 5, 2], [0, 0, 5, 5]], dtype=np.float32),
class_id=np.array([0, 1], dtype=int),
mask=np.array(
[
np.array(
[
1 if j > 4 and j < 10 and i < 5 else 0
for i in range(0, 20)
for j in range(0, 20)
]
).reshape((20, 20)),
np.array(
[
0 if i >= 10 or j >= 10 or (i < 5 and j >= 5) else 1
for i in range(0, 20)
for j in range(0, 20)
]
).reshape((20, 20)),
[[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[1, 1, 1, 0, 0],
[1, 1, 1, 0, 0],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]]
]
),
),
DoesNotRaise(),
), # two image annotations with mask, first mask as RLE in shape of square,
# second as polygon in in L-like shape, like below (P = polygon, R = RLE):
# P R 0 0
# P P 0 0
# 0 0 0 0
# 0 0 0 0
), # two image annotations with mask, first mask as RLE and second as polygon
],
)
def test_coco_annotations_to_detections(