Skip to content

Commit 42ee591

Browse files
committed
Enhance automatic annotation BE logic
The code in lambda_manager didn't account for attributes mappings that had different names thus returning an empty set of attributes because it couldn't find the correct match. Fix this by getting proper mapping from `attrMapping` property of the input data.
1 parent c5f86af commit 42ee591

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

cvat/apps/lambda_manager/views.py

+44-22
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,15 @@ def invoke(self, db_task, data):
170170
})
171171
quality = data.get("quality")
172172
mapping = data.get("mapping", {})
173+
attr_mapping = data.get("attrMapping", {})
173174
mapping_by_default = {}
174175
task_attributes = {}
175176
for db_label in (db_task.project.label_set if db_task.project_id else db_task.label_set).prefetch_related("attributespec_set").all():
176177
mapping_by_default[db_label.name] = db_label.name
177178
task_attributes[db_label.name] = {}
178179
for attribute in db_label.attributespec_set.all():
179180
task_attributes[db_label.name][attribute.name] = {
180-
'input_rype': attribute.input_type,
181+
'input_type': attribute.input_type,
181182
'values': attribute.values.split('\n')
182183
}
183184
if not mapping:
@@ -189,12 +190,19 @@ def invoke(self, db_task, data):
189190
mapping = {k:v for k,v in mapping.items() if v in mapping_by_default}
190191
supported_attrs = {}
191192
for func_label, func_attrs in self.func_attributes.items():
192-
if func_label in mapping:
193-
supported_attrs[func_label] = {}
194-
task_attr_names = [task_attr for task_attr in task_attributes[mapping[func_label]]]
195-
for attr in func_attrs:
196-
if attr['name'] in task_attr_names:
197-
supported_attrs[func_label].update({attr["name"] : attr})
193+
if func_label not in mapping:
194+
continue
195+
196+
mapped_label = mapping[func_label]
197+
mapped_attributes = attr_mapping[func_label].get("attributes")
198+
supported_attrs[func_label] = { }
199+
task_attr_names = [task_attr for task_attr in task_attributes[mapped_label]]
200+
201+
for attr in func_attrs:
202+
mapped_attr = mapped_attributes.get(attr["name"])
203+
if mapped_attr in task_attr_names:
204+
supported_attrs[func_label].update({ attr["name"]: task_attributes[mapped_label][mapped_attr] })
205+
198206
if self.kind == LambdaType.DETECTOR:
199207
payload.update({
200208
"image": self._get_image(db_task, data["frame"], quality)
@@ -259,28 +267,42 @@ def check_attr_value(value, func_attr, db_attr):
259267
return db_attr_type == "text" or \
260268
(db_attr_type in ["select", "radio"] and len(value.split(" ")) == 1)
261269
elif func_attr_type == "select":
262-
return db_attr["input_type"] in ["radio", "text"]
270+
return db_attr_type in ["radio", "text"]
263271
elif func_attr_type == "radio":
264-
return db_attr["input_type"] in ["select", "text"]
272+
return db_attr_type in ["select", "text"]
265273
elif func_attr_type == "checkbox":
266274
return value in ["true", "false"]
267275
else:
268276
return False
269277
if self.kind == LambdaType.DETECTOR:
270278
for item in response:
271-
if item['label'] in mapping:
272-
attributes = deepcopy(item.get("attributes", []))
273-
item["attributes"] = []
274-
for attr in attributes:
275-
db_attr = supported_attrs.get(item['label'], {}).get(attr["name"])
276-
func_attr = [func_attr for func_attr in self.func_attributes.get(item['label'], []) if func_attr['name'] == attr["name"]]
277-
# Skip current attribute if it was not declared as supportd in function config
278-
if not func_attr:
279-
continue
280-
if attr["name"] in supported_attrs.get(item['label'], {}) and check_attr_value(attr["value"], func_attr[0], db_attr):
281-
item["attributes"].append(attr)
282-
item['label'] = mapping[item['label']]
283-
response_filtered.append(item)
279+
item_label = item['label']
280+
281+
if item_label not in mapping:
282+
continue
283+
284+
attributes = deepcopy(item.get("attributes", []))
285+
item["attributes"] = []
286+
supported_label = supported_attrs.get(item_label, {})
287+
mapped_attributes = attr_mapping[item_label]['attributes']
288+
289+
for attr in attributes:
290+
if attr['name'] not in mapped_attributes:
291+
continue
292+
293+
func_attr = [func_attr for func_attr in self.func_attributes.get(item_label, []) if func_attr['name'] == attr["name"]]
294+
# Skip current attribute if it was not declared as supported in function config
295+
if not func_attr:
296+
continue
297+
298+
db_attr = supported_label.get(attr["name"])
299+
300+
if check_attr_value(attr["value"], func_attr[0], db_attr):
301+
attr["name"] = mapped_attributes[attr['name']]
302+
item["attributes"].append(attr)
303+
304+
item['label'] = mapping[item['label']]
305+
response_filtered.append(item)
284306

285307
return response_filtered
286308

0 commit comments

Comments
 (0)