Skip to content
Permalink
Browse files

Advanced Auto Annotation Handling for Admins (#514)

  • Loading branch information
benhoff authored and nmanovic committed Jun 26, 2019
1 parent 0765623 commit f20698921e5355a4b13c4f90612163f56b9835d0
Showing with 33 additions and 15 deletions.
  1. +1 −0 CHANGELOG.md
  2. +30 −15 cvat/apps/auto_annotation/model_manager.py
  3. +2 −0 cvat/apps/auto_annotation/views.py
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Installation guide
- Linear interpolation for a single point
- Video frame filter
- Admins are no longer limited to a subset of python commands in the auto annotation application
- Remote data source (list of URLs to create an annotation task)

### Changed
@@ -17,6 +17,7 @@

from cvat.apps.engine.log import slogger
from cvat.apps.engine.models import Task as TaskModel
from cvat.apps.authentication.auth import has_admin_role
from cvat.apps.engine.serializers import LabeledDataSerializer
from cvat.apps.engine.annotation import put_task_data, patch_task_data

@@ -29,7 +30,7 @@ def _remove_old_file(model_file_field):
os.remove(model_file_field.name)

def _update_dl_model_thread(dl_model_id, name, is_shared, model_file, weights_file, labelmap_file,
interpretation_file, run_tests, is_local_storage, delete_if_test_fails):
interpretation_file, run_tests, is_local_storage, delete_if_test_fails, restricted=True):
def _get_file_content(filename):
return os.path.basename(filename), open(filename, "rb")

@@ -48,6 +49,7 @@ def _run_test(model_file, weights_file, labelmap_file, interpretation_file):
labels_mapping=labelmap_file,
attribute_spec={},
convertation_file=interpretation_file,
restricted=restricted
)
except Exception as e:
return False, str(e)
@@ -151,6 +153,11 @@ def save_file_as_tmp(data):
labelmap_file = save_file_as_tmp(labelmap_file)
interpretation_file = save_file_as_tmp(interpretation_file)

if owner:
restricted = not has_admin_role(owner)
else:
restricted = not has_admin_role(AnnotationModel.objects.get(pk=dl_model_id).owner)

rq_id = "auto_annotation.create.{}".format(dl_model_id)
queue = django_rq.get_queue("default")
queue.enqueue_call(
@@ -166,6 +173,7 @@ def save_file_as_tmp(data):
run_tests,
storage == "local",
is_create_request,
restricted
),
job_id=rq_id
)
@@ -256,27 +264,33 @@ def _create_polyshape(points, label, frame_number, attributes=None):
"attributes": attributes or {},
}

def _process_detections(detections, path_to_conv_script):
def _process_detections(detections, path_to_conv_script, restricted=True):
results = Results()
global_vars = {
"__builtins__": {
"str": str,
"int": int,
"float": float,
"max": max,
"min": min,
"range": range,
},
}
local_vars = {
"detections": detections,
"results": results,
}

if restricted:
global_vars = {
"__builtins__": {
"str": str,
"int": int,
"float": float,
"max": max,
"min": min,
"range": range,
},
}
else:
global_vars = globals()

exec (open(path_to_conv_script).read(), global_vars, local_vars)

return results

def _run_inference_engine_annotation(data, model_file, weights_file,
labels_mapping, attribute_spec, convertation_file, job=None, update_progress=None):
labels_mapping, attribute_spec, convertation_file, job=None, update_progress=None, restricted=True):
def process_attributes(shape_attributes, label_attr_spec):
attributes = []
for attr_text, attr_value in shape_attributes.items():
@@ -332,14 +346,14 @@ def add_shapes(shapes, target_container):
if job and update_progress and not update_progress(job, frame_counter * 100 / data_len):
return None

processed_detections = _process_detections(detections, convertation_file)
processed_detections = _process_detections(detections, convertation_file, restricted=restricted)

add_shapes(processed_detections.get_shapes(), result["shapes"])


return result

def run_inference_thread(tid, model_file, weights_file, labels_mapping, attributes, convertation_file, reset, user):
def run_inference_thread(tid, model_file, weights_file, labels_mapping, attributes, convertation_file, reset, user, restricted=True):
def update_progress(job, progress):
job.refresh()
if "cancel" in job.meta:
@@ -367,6 +381,7 @@ def update_progress(job, progress):
convertation_file= convertation_file,
job=job,
update_progress=update_progress,
restricted=restricted
)

if result is None:
@@ -188,6 +188,7 @@ def start_annotation(request, mid, tid):
weights_file_path = dl_model.weights_file.name
labelmap_file = dl_model.labelmap_file.name
convertation_file_path = dl_model.interpretation_file.name
restricted = not has_admin_role(dl_model.owner)

db_labels = db_task.label_set.prefetch_related("attributespec_set").all()
db_attributes = {db_label.id:
@@ -215,6 +216,7 @@ def start_annotation(request, mid, tid):
convertation_file_path,
should_reset,
request.user,
restricted,
),
job_id = rq_id,
timeout=604800) # 7 days

0 comments on commit f206989

Please sign in to comment.
You can’t perform that action at this time.