Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit afaf374

Browse files
yasakova-anastasiamikhail-treskin
authored andcommitted
Add a test for mask conversion in lambda functions (cvat-ai#5950)
Added test for cvat-ai#5877
1 parent a8345af commit afaf374

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

cvat/apps/lambda_manager/tests/test_lambda.py

+53-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,30 @@ def __invoke_function(self, func, payload):
126126
]
127127
elif type_function == "detector":
128128
data = [
129-
{'confidence': '0.9959098', 'label': 'car', 'points': [3, 3, 15, 15], 'type': 'rectangle'},
130-
{'confidence': '0.89535173', 'label': 'car', 'points': [20, 25, 30, 35], 'type': 'rectangle'},
131-
{'confidence': '0.59464583', 'label': 'car', 'points': [12.17, 45.0, 69.80, 18.99], 'type': 'polygon'},
129+
{
130+
"confidence": "0.9959098",
131+
"label": "car",
132+
"points": [3, 3, 15, 15],
133+
"type": "rectangle",
134+
},
135+
{
136+
"confidence": "0.89535173",
137+
"label": "car",
138+
"points": [20, 25, 30, 35],
139+
"type": "rectangle",
140+
},
141+
{
142+
"confidence": "0.59464583",
143+
"label": "car",
144+
"points": [12.17, 45.0, 69.80, 18.99],
145+
"type": "polygon",
146+
},
147+
{
148+
"confidence": "0.59464583",
149+
"label": "car",
150+
"mask": [255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 0, 0, 2, 3],
151+
"type": "mask",
152+
},
132153
]
133154

134155
return data
@@ -857,6 +878,35 @@ def test_api_v2_lambda_functions_create_quality(self):
857878
response = self._post_request(f"{LAMBDA_FUNCTIONS_PATH}/{id_function_detector}", self.admin, data)
858879
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
859880

881+
def test_api_v2_lambda_functions_convert_mask_to_rle(self):
882+
data_main_task = {
883+
"function": id_function_detector,
884+
"task": self.main_task["id"],
885+
"cleanup": True,
886+
"quality": "original",
887+
"mapping": {
888+
"car": { "name": "car" },
889+
},
890+
}
891+
response = self._post_request(LAMBDA_REQUESTS_PATH, self.admin, data_main_task)
892+
self.assertEqual(response.status_code, status.HTTP_200_OK)
893+
id_request = response.data["id"]
894+
895+
request_status = "started"
896+
while request_status != "finished" and request_status != "failed":
897+
response = self._get_request(f'{LAMBDA_REQUESTS_PATH}/{id_request}', self.admin)
898+
self.assertEqual(response.status_code, status.HTTP_200_OK)
899+
request_status = response.json().get("status")
900+
self.assertEqual(request_status, "finished")
901+
902+
response = self._get_request(f'/api/tasks/{self.main_task["id"]}/annotations', self.admin)
903+
self.assertEqual(response.status_code, status.HTTP_200_OK)
904+
905+
masks = [shape for shape in response.json().get("shapes", []) if shape["type"] == "mask"]
906+
907+
# [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0] -> [0, 2, 2, 2, 2, 2, 2]
908+
self.assertEqual(masks[0].get("points"), [0, 2, 2, 2, 2, 2, 2, 0, 0, 2, 3])
909+
860910

861911
def test_api_v2_lambda_functions_create_empty_data(self):
862912
data = {}

0 commit comments

Comments
 (0)