|
|
|
@ -258,13 +258,32 @@ def create_thread(tid, labels_mapping):
|
|
|
|
# Modify data format and save
|
|
|
|
# Modify data format and save
|
|
|
|
result = convert_to_cvat_format(result)
|
|
|
|
result = convert_to_cvat_format(result)
|
|
|
|
annotation.save_task(tid, result)
|
|
|
|
annotation.save_task(tid, result)
|
|
|
|
db_task.status = "Annotation"
|
|
|
|
|
|
|
|
db_task.save()
|
|
|
|
|
|
|
|
slogger.glob.info('tf annotation for task {} done'.format(tid))
|
|
|
|
slogger.glob.info('tf annotation for task {} done'.format(tid))
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
slogger.task[tid].exception('exception was occured during tf annotation of the task', exc_info=True)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
slogger.glob.exception('exception was occured during tf annotation of the task {}'.format(tid), exc_into=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def get_meta_info(request):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
queue = django_rq.get_queue('low')
|
|
|
|
|
|
|
|
tids = json.loads(request.body.decode('utf-8'))
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
|
|
|
for tid in tids:
|
|
|
|
|
|
|
|
job = queue.fetch_job('tf_annotation.create/{}'.format(tid))
|
|
|
|
|
|
|
|
if job is not None:
|
|
|
|
|
|
|
|
result[tid] = {
|
|
|
|
|
|
|
|
"active": job.is_queued or job.is_started,
|
|
|
|
|
|
|
|
"success": not job.is_failed
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JsonResponse(result)
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
slogger.glob.exception('exception was occured during tf annotation of the task {}: {}'.format(tid, ex))
|
|
|
|
slogger.glob.exception('exception was occured during tf meta request', exc_into=True)
|
|
|
|
db_task.status = "TF Annotation Fault"
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
db_task.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@permission_required(perm=['engine.view_task', 'engine.change_annotation'], raise_exception=True)
|
|
|
|
@permission_required(perm=['engine.view_task', 'engine.change_annotation'], raise_exception=True)
|
|
|
|
@ -272,19 +291,14 @@ def create(request, tid):
|
|
|
|
slogger.glob.info('tf annotation create request for task {}'.format(tid))
|
|
|
|
slogger.glob.info('tf annotation create request for task {}'.format(tid))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db_task = TaskModel.objects.get(pk=tid)
|
|
|
|
db_task = TaskModel.objects.get(pk=tid)
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
|
|
|
|
slogger.glob.exception('task with id {} not found'.format(tid))
|
|
|
|
|
|
|
|
return HttpResponseBadRequest("A task with this ID was not found")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not task.is_task_owner(request.user, tid):
|
|
|
|
if not task.is_task_owner(request.user, tid):
|
|
|
|
slogger.glob.error('not enought of permissions for tf annotation of the task {}'.format(tid))
|
|
|
|
raise Exception('Not enought of permissions for tf annotation')
|
|
|
|
return HttpResponseBadRequest("You don't have permissions to tf annotation of the task.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queue = django_rq.get_queue('low')
|
|
|
|
queue = django_rq.get_queue('low')
|
|
|
|
job = queue.fetch_job('tf_annotation.create/{}'.format(tid))
|
|
|
|
job = queue.fetch_job('tf_annotation.create/{}'.format(tid))
|
|
|
|
if job is not None and (job.is_started or job.is_queued):
|
|
|
|
if job is not None and (job.is_started or job.is_queued):
|
|
|
|
slogger.glob.error('tf annotation for task {} already running'.format(tid))
|
|
|
|
raise Exception("The process is already running")
|
|
|
|
return HttpResponseBadRequest("The process is already running")
|
|
|
|
|
|
|
|
db_labels = db_task.label_set.prefetch_related('attributespec_set').all()
|
|
|
|
db_labels = db_task.label_set.prefetch_related('attributespec_set').all()
|
|
|
|
db_labels = {db_label.id:db_label.name for db_label in db_labels}
|
|
|
|
db_labels = {db_label.id:db_label.name for db_label in db_labels}
|
|
|
|
|
|
|
|
|
|
|
|
@ -313,30 +327,34 @@ def create(request, tid):
|
|
|
|
labels_mapping[tf_annotation_labels[labels]] = key
|
|
|
|
labels_mapping[tf_annotation_labels[labels]] = key
|
|
|
|
|
|
|
|
|
|
|
|
if not len(labels_mapping.values()):
|
|
|
|
if not len(labels_mapping.values()):
|
|
|
|
slogger.glob.error('no labels found for task {} tf annotation'.format(tid))
|
|
|
|
raise Exception('No labels found for tf annotation')
|
|
|
|
return HttpResponseBadRequest("No labels found for tf annotation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db_task.status = "TF Annotation"
|
|
|
|
|
|
|
|
db_task.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Run tf annotation job
|
|
|
|
# Run tf annotation job
|
|
|
|
queue.enqueue_call(func=create_thread,
|
|
|
|
queue.enqueue_call(func=create_thread,
|
|
|
|
args=(tid, labels_mapping),
|
|
|
|
args=(tid, labels_mapping),
|
|
|
|
job_id='tf_annotation.create/{}'.format(tid),
|
|
|
|
job_id='tf_annotation.create/{}'.format(tid),
|
|
|
|
timeout=604800) # 7 days
|
|
|
|
timeout=604800) # 7 days
|
|
|
|
slogger.glob.info('tf annotation job enqueued for task {} with labels {}'.format(tid, labels_mapping))
|
|
|
|
|
|
|
|
|
|
|
|
slogger.task[tid].info('tensorflow annotation job enqueued with labels {}'.format(labels_mapping))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as ex:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
slogger.task[tid].exception("exception was occured during tensorflow annotation request", exc_info=True)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse()
|
|
|
|
return HttpResponse()
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@permission_required(perm='engine.view_task', raise_exception=True)
|
|
|
|
@permission_required(perm='engine.view_task', raise_exception=True)
|
|
|
|
def check(request, tid):
|
|
|
|
def check(request, tid):
|
|
|
|
|
|
|
|
try:
|
|
|
|
queue = django_rq.get_queue('low')
|
|
|
|
queue = django_rq.get_queue('low')
|
|
|
|
job = queue.fetch_job('tf_annotation.create/{}'.format(tid))
|
|
|
|
job = queue.fetch_job('tf_annotation.create/{}'.format(tid))
|
|
|
|
if job is not None and 'cancel' in job.meta:
|
|
|
|
if job is not None and 'cancel' in job.meta:
|
|
|
|
return JsonResponse({'status': 'finished'})
|
|
|
|
return JsonResponse({'status': 'finished'})
|
|
|
|
data = {}
|
|
|
|
data = {}
|
|
|
|
try:
|
|
|
|
|
|
|
|
if job is None:
|
|
|
|
if job is None:
|
|
|
|
data['status'] = 'unknown'
|
|
|
|
data['status'] = 'unknown'
|
|
|
|
elif job.is_queued:
|
|
|
|
elif job.is_queued:
|
|
|
|
@ -350,6 +368,7 @@ def check(request, tid):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
data['status'] = 'failed'
|
|
|
|
data['status'] = 'failed'
|
|
|
|
job.delete()
|
|
|
|
job.delete()
|
|
|
|
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
data['status'] = 'unknown'
|
|
|
|
data['status'] = 'unknown'
|
|
|
|
|
|
|
|
|
|
|
|
@ -363,14 +382,16 @@ def cancel(request, tid):
|
|
|
|
queue = django_rq.get_queue('low')
|
|
|
|
queue = django_rq.get_queue('low')
|
|
|
|
job = queue.fetch_job('tf_annotation.create/{}'.format(tid))
|
|
|
|
job = queue.fetch_job('tf_annotation.create/{}'.format(tid))
|
|
|
|
if job is None or job.is_finished or job.is_failed:
|
|
|
|
if job is None or job.is_finished or job.is_failed:
|
|
|
|
raise Exception('Task is not in tf annotation process')
|
|
|
|
raise Exception('Task is not being annotated currently')
|
|
|
|
elif 'cancel' not in job.meta:
|
|
|
|
elif 'cancel' not in job.meta:
|
|
|
|
job.meta['cancel'] = True
|
|
|
|
job.meta['cancel'] = True
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
db_task = TaskModel.objects.get(pk=tid)
|
|
|
|
|
|
|
|
db_task.status = "Annotation"
|
|
|
|
|
|
|
|
db_task.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
return HttpResponseBadRequest("TF annotation cancel error: {}".format(str(ex)))
|
|
|
|
try:
|
|
|
|
|
|
|
|
slogger.task[tid].exception("cannot cancel tensorflow annotation for task #{}".format(tid), exc_info=True)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse()
|
|
|
|
return HttpResponse()
|
|
|
|
|