def create_thread(tid, labels_mapping, user): try: # If detected object accuracy bigger than threshold it will returend TRESHOLD = 0.5 # Init rq job job = rq.get_current_job() job.meta['progress'] = 0 job.save_meta() # Get job indexes and segment length db_task = TaskModel.objects.get(pk=tid) # Get image list image_list = make_image_list(db_task.get_data_dirname()) # Run auto segmentation by tf result = None slogger.glob.info("auto segmentation with tensorflow framework for task {}".format(tid)) result = run_tensorflow_auto_segmentation(image_list, labels_mapping, TRESHOLD) if result is None: slogger.glob.info('auto segmentation for task {} canceled by user'.format(tid)) return # Modify data format and save result = convert_to_cvat_format(result) serializer = LabeledDataSerializer(data = result) if serializer.is_valid(raise_exception=True): put_task_data(tid, user, result) slogger.glob.info('auto segmentation for task {} done'.format(tid)) except Exception as ex: try: slogger.task[tid].exception('exception was occured during auto segmentation of the task', exc_info=True) except Exception: slogger.glob.exception('exception was occured during auto segmentation of the task {}'.format(tid), exc_info=True) raise ex
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: del job.meta["cancel"] job.save() return False job.meta["progress"] = progress job.save_meta() return True try: job = rq.get_current_job() job.meta["progress"] = 0 job.save_meta() db_task = TaskModel.objects.get(pk=tid) result = None slogger.glob.info("auto annotation with openvino toolkit for task {}".format(tid)) result = run_inference_engine_annotation( data=get_image_data(db_task.get_data_dirname()), model_file=model_file, weights_file=weights_file, labels_mapping=labels_mapping, attribute_spec=attributes, convertation_file= convertation_file, job=job, update_progress=update_progress, restricted=restricted ) if result is None: slogger.glob.info("auto annotation for task {} canceled by user".format(tid)) return serializer = LabeledDataSerializer(data = result) if serializer.is_valid(raise_exception=True): if reset: put_task_data(tid, user, result) else: patch_task_data(tid, user, result, "create") slogger.glob.info("auto annotation for task {} done".format(tid)) except Exception as e: try: slogger.task[tid].exception("exception was occurred during auto annotation of the task", exc_info=True) except Exception as ex: slogger.glob.exception("exception was occurred during auto annotation of the task {}: {}".format(tid, str(ex)), exc_info=True) raise ex raise e