Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid json labelmap file case correctly during create/update DL model stage. #573

Merged
merged 5 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (https://github.com/opencv/cvat/issues/554)

### Security
-
Expand Down
11 changes: 11 additions & 0 deletions cvat/apps/auto_annotation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions cvat/apps/auto_annotation/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def infer(self, image):
return results.copy()


def load_label_map(labels_path):
with open(labels_path, "r") as f:
return json.load(f)["label_map"]
def load_labelmap(labels_path):
with open(labels_path, "r") as f:
return json.load(f)["label_map"]
8 changes: 5 additions & 3 deletions cvat/apps/auto_annotation/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import shutil
import tempfile
import itertools
import sys
import traceback

from django.db import transaction
from django.utils import timezone
Expand All @@ -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_labelmap
from .image_loader import ImageLoader
from .import_modules import import_modules

Expand All @@ -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_labelmap = {key: key for key in load_labelmap(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_labelmap,
attribute_spec={},
convertation_file=interpretation_file,
restricted=restricted
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/auto_annotation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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():
Expand Down