From fd53d1329e675d91403e8f779f0582462e7effa0 Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov Date: Mon, 15 Jul 2019 16:27:00 +0300 Subject: [PATCH 1/5] handle invalid json labelmap file case correctly on create/update DL model stage --- cvat/apps/auto_annotation/admin.py | 11 +++++++++++ cvat/apps/auto_annotation/model_loader.py | 4 ++-- cvat/apps/auto_annotation/model_manager.py | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cvat/apps/auto_annotation/admin.py b/cvat/apps/auto_annotation/admin.py index a59acdef3783..da1eabb4cbb3 100644 --- a/cvat/apps/auto_annotation/admin.py +++ b/cvat/apps/auto_annotation/admin.py @@ -2,3 +2,14 @@ # Copyright (C) 2018 Intel Corporation # # SPDX-License-Identifier: MIT + +from django.contrib import admin +from .models import AnnotationModel + +@admin.register(AnnotationModel) +class AnnotationModelAdmin(admin.ModelAdmin): + list_display = ('name', 'owner', 'created_date', 'updated_date', + 'shared', 'primary', 'framework') + + def has_add_permission(self, request): + return False diff --git a/cvat/apps/auto_annotation/model_loader.py b/cvat/apps/auto_annotation/model_loader.py index 09b67f417f0b..fc8fda531055 100644 --- a/cvat/apps/auto_annotation/model_loader.py +++ b/cvat/apps/auto_annotation/model_loader.py @@ -66,5 +66,5 @@ def infer(self, image): def load_label_map(labels_path): - with open(labels_path, "r") as f: - return json.load(f)["label_map"] + with open(labels_path, "r") as f: + return json.load(f)["label_map"] diff --git a/cvat/apps/auto_annotation/model_manager.py b/cvat/apps/auto_annotation/model_manager.py index b3c03d6e68c2..54a4111c173d 100644 --- a/cvat/apps/auto_annotation/model_manager.py +++ b/cvat/apps/auto_annotation/model_manager.py @@ -10,6 +10,8 @@ import shutil import tempfile import itertools +import sys +import traceback from django.db import transaction from django.utils import timezone @@ -22,7 +24,7 @@ from cvat.apps.engine.annotation import put_task_data, patch_task_data from .models import AnnotationModel, FrameworkChoice -from .model_loader import ModelLoader +from .model_loader import ModelLoader, load_label_map from .image_loader import ImageLoader from .import_modules import import_modules @@ -44,11 +46,12 @@ def _delete_source_files(): def _run_test(model_file, weights_file, labelmap_file, interpretation_file): test_image = np.ones((1024, 1980, 3), np.uint8) * 255 try: + dummy_label_map = {key: key for key in load_label_map(labelmap_file).keys()} run_inference_engine_annotation( data=[test_image,], model_file=model_file, weights_file=weights_file, - labels_mapping=labelmap_file, + labels_mapping=dummy_label_map, attribute_spec={}, convertation_file=interpretation_file, restricted=restricted @@ -370,7 +373,6 @@ def add_shapes(shapes, target_container): 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, restricted=True): From 0be1df67d39340630bb474d6365da6e8cafc0564 Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov Date: Tue, 16 Jul 2019 09:48:33 +0300 Subject: [PATCH 2/5] dummy_label_map -> dummy_labelmap --- cvat/apps/auto_annotation/model_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cvat/apps/auto_annotation/model_manager.py b/cvat/apps/auto_annotation/model_manager.py index 54a4111c173d..0ee3039bf580 100644 --- a/cvat/apps/auto_annotation/model_manager.py +++ b/cvat/apps/auto_annotation/model_manager.py @@ -46,12 +46,12 @@ def _delete_source_files(): def _run_test(model_file, weights_file, labelmap_file, interpretation_file): test_image = np.ones((1024, 1980, 3), np.uint8) * 255 try: - dummy_label_map = {key: key for key in load_label_map(labelmap_file).keys()} + dummy_labelmap = {key: key for key in load_label_map(labelmap_file).keys()} run_inference_engine_annotation( data=[test_image,], model_file=model_file, weights_file=weights_file, - labels_mapping=dummy_label_map, + labels_mapping=dummy_labelmap, attribute_spec={}, convertation_file=interpretation_file, restricted=restricted From 150ac8e3811c1c79110b725484b0329f5e7c2542 Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov Date: Tue, 16 Jul 2019 09:58:21 +0300 Subject: [PATCH 3/5] renamed load_label_map function --- cvat/apps/auto_annotation/model_loader.py | 2 +- cvat/apps/auto_annotation/model_manager.py | 4 ++-- cvat/apps/auto_annotation/views.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cvat/apps/auto_annotation/model_loader.py b/cvat/apps/auto_annotation/model_loader.py index fc8fda531055..73d33d81b4fd 100644 --- a/cvat/apps/auto_annotation/model_loader.py +++ b/cvat/apps/auto_annotation/model_loader.py @@ -65,6 +65,6 @@ def infer(self, image): return results.copy() -def load_label_map(labels_path): +def load_labelmap(labels_path): with open(labels_path, "r") as f: return json.load(f)["label_map"] diff --git a/cvat/apps/auto_annotation/model_manager.py b/cvat/apps/auto_annotation/model_manager.py index 0ee3039bf580..5d0b9f8b9fa9 100644 --- a/cvat/apps/auto_annotation/model_manager.py +++ b/cvat/apps/auto_annotation/model_manager.py @@ -24,7 +24,7 @@ from cvat.apps.engine.annotation import put_task_data, patch_task_data from .models import AnnotationModel, FrameworkChoice -from .model_loader import ModelLoader, load_label_map +from .model_loader import ModelLoader, load_labelmap from .image_loader import ImageLoader from .import_modules import import_modules @@ -46,7 +46,7 @@ def _delete_source_files(): def _run_test(model_file, weights_file, labelmap_file, interpretation_file): test_image = np.ones((1024, 1980, 3), np.uint8) * 255 try: - dummy_labelmap = {key: key for key in load_label_map(labelmap_file).keys()} + dummy_labelmap = {key: key for key in load_labelmap(labelmap_file).keys()} run_inference_engine_annotation( data=[test_image,], model_file=model_file, diff --git a/cvat/apps/auto_annotation/views.py b/cvat/apps/auto_annotation/views.py index d12a1c0bb745..e13ed2c0766f 100644 --- a/cvat/apps/auto_annotation/views.py +++ b/cvat/apps/auto_annotation/views.py @@ -15,7 +15,7 @@ from cvat.apps.authentication.auth import has_admin_role from cvat.apps.engine.log import slogger -from .model_loader import load_label_map +from .model_loader import load_labelmap from . import model_manager from .models import AnnotationModel @@ -195,7 +195,7 @@ def start_annotation(request, mid, tid): {db_attr.name: db_attr.id for db_attr in db_label.attributespec_set.all()} for db_label in db_labels} db_labels = {db_label.name:db_label.id for db_label in db_labels} - model_labels = {value: key for key, value in load_label_map(labelmap_file).items()} + model_labels = {value: key for key, value in load_labelmap(labelmap_file).items()} labels_mapping = {} for user_model_label, user_db_label in user_defined_labels_mapping.items(): From 9cc7a82d10ad07d5a8bdb05a01fc7bd159537bdc Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov Date: Tue, 16 Jul 2019 10:17:29 +0300 Subject: [PATCH 4/5] changelog note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54089c822c4a..39085240c265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Auto annotation fail for multijob tasks - Installation of CVAT with OpenVINO on the Windows platform - Background color was always black in utils/mask/converter.py +- Handling of wrong labelamp json file in auto annotation ### Security - From f9fee9d683629e20aca3b12d9681a31d892aee0e Mon Sep 17 00:00:00 2001 From: Nikita Manovich <40690625+nmanovic@users.noreply.github.com> Date: Tue, 16 Jul 2019 10:20:26 +0300 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39085240c265..5d7c591c11f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Auto annotation fail for multijob tasks - Installation of CVAT with OpenVINO on the Windows platform - Background color was always black in utils/mask/converter.py -- Handling of wrong labelamp json file in auto annotation +- Handling of wrong labelamp json file in auto annotation (https://github.com/opencv/cvat/issues/554) ### Security -