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

Refactor quality reports #9026

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
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
21 changes: 15 additions & 6 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
from types import SimpleNamespace
from typing import Any, Callable, Literal, NamedTuple, Optional, Union

import datumaro as dm
# We use both full names for internal datumaro symbols and dm.-aliased for external ones
import datumaro
import datumaro as dm # pylint: disable=reimported
import datumaro.util
import defusedxml.ElementTree as ET
import rq
from attr import attrib, attrs
Expand Down Expand Up @@ -2128,9 +2131,9 @@ def match_dm_item(
if frame_number is None:
frame_number = instance_data.match_frame(item.id, root_hint, path_has_ext=False)
if frame_number is None:
frame_number = dm.util.cast(item.attributes.get('frame', item.id), int)
frame_number = datumaro.util.cast(item.attributes.get('frame', item.id), int)
if frame_number is None and is_video:
frame_number = dm.util.cast(osp.basename(item.id)[len('frame_'):], int)
frame_number = datumaro.util.cast(osp.basename(item.id)[len('frame_'):], int)

if not frame_number in instance_data.frame_info:
raise CvatImportError("Could not match item id: "
Expand Down Expand Up @@ -2254,9 +2257,15 @@ def import_dm_annotations(dm_dataset: dm.Dataset, instance_data: Union[ProjectDa
# because in some formats return type can be different
# from bool / None
# https://github.com/openvinotoolkit/datumaro/issues/719
occluded = dm.util.cast(ann.attributes.pop('occluded', None), to_bool) is True
keyframe = dm.util.cast(ann.attributes.get('keyframe', None), to_bool) is True
outside = dm.util.cast(ann.attributes.pop('outside', None), to_bool) is True
occluded = datumaro.util.cast(
ann.attributes.pop('occluded', None), to_bool
) is True
keyframe = datumaro.util.cast(
ann.attributes.get('keyframe', None), to_bool
) is True
outside = datumaro.util.cast(
ann.attributes.pop('outside', None), to_bool
) is True

track_id = ann.attributes.pop('track_id', None)
source = ann.attributes.pop('source').lower() \
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from collections.abc import Collection, Sequence
from enum import Enum
from functools import cached_property
from typing import Any, ClassVar, Optional
from typing import Any, ClassVar, Iterable, Iterator, Optional

from django.conf import settings
from django.contrib.auth.models import User
Expand Down Expand Up @@ -453,7 +453,7 @@ def get_tmp_dirname(self) -> str:


@transaction.atomic(savepoint=False)
def clear_annotations_in_jobs(job_ids):
def clear_annotations_in_jobs(job_ids: Iterable[int] | Iterator[int]):
for job_ids_chunk in take_by(job_ids, chunk_size=1000):
TrackedShapeAttributeVal.objects.filter(shape__track__job_id__in=job_ids_chunk).delete()
TrackedShape.objects.filter(track__job_id__in=job_ids_chunk).delete()
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def parse_specific_attributes(specific_attributes):
} if parsed_specific_attributes else dict()


def parse_exception_message(msg):
def parse_exception_message(msg: str) -> str:
parsed_msg = msg
try:
if 'ErrorDetail' in msg:
Expand Down
6 changes: 3 additions & 3 deletions cvat/apps/quality_control/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class QualityReportPermission(OpenPolicyAgentPermission):
obj: Optional[QualityReport]
job_owner_id: Optional[int]
rq_job_owner_id: Optional[int]
task_id: Optional[int]

class Scopes(StrEnum):
Expand Down Expand Up @@ -103,7 +103,7 @@ def create(cls, request, view, obj, iam_context):

def __init__(self, **kwargs):
if "job_owner_id" in kwargs:
self.job_owner_id = int(kwargs.pop("job_owner_id"))
self.rq_job_owner_id = int(kwargs.pop("job_owner_id"))

super().__init__(**kwargs)
self.url = settings.IAM_OPA_DATA_URL + "/quality_reports/allow"
Expand Down Expand Up @@ -164,7 +164,7 @@ def get_resource(self):
),
}
elif self.scope == self.Scopes.VIEW_STATUS:
data = {"owner": {"id": self.job_owner_id}}
data = {"owner": {"id": self.rq_job_owner_id}}

return data

Expand Down
Loading
Loading