Skip to content

Commit

Permalink
test what fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Eldies committed Nov 17, 2024
1 parent 3a5a26d commit 9e2f4f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ def match_frame_fuzzy(self, path: str, *, path_has_ext: bool = True) -> Optional

class JobData(CommonData):
META_FIELD = "job"
def __init__(self, annotation_ir: AnnotationIR, db_job: Job, **kwargs):
def __init__(self, annotation_ir: AnnotationIR, db_job: Job, _PREFETCH_IMAGES = False, **kwargs):
self._PREFETCH_IMAGES = _PREFETCH_IMAGES
self._db_job = db_job
self._db_task = db_job.segment.task

Expand Down Expand Up @@ -823,6 +824,8 @@ def __len__(self):
return segment.stop_frame - segment.start_frame + 1

def _get_db_images(self):
if not self._PREFETCH_IMAGES:
raise NotImplementedError()
return (image for image in self._db_data.images.all() if image.frame in self.abs_range)

@property
Expand Down
14 changes: 9 additions & 5 deletions cvat/apps/dataset_manager/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def add_prefetch_info(cls, queryset: QuerySet, prefetch_images: bool = True):
Prefetch('segment__task__project__label_set', queryset=label_qs),
)

def __init__(self, pk, *, is_prefetched: bool = False, queryset: QuerySet = None, prefetch_images: bool = True):
def __init__(self, pk, *, is_prefetched: bool = False, queryset: QuerySet = None, prefetch_images: bool = False):
self._PREFETCH_IMAGES = prefetch_images
if queryset is None:
queryset = self.add_prefetch_info(models.Job.objects, prefetch_images=prefetch_images)

Expand Down Expand Up @@ -756,6 +757,7 @@ def export(self, dst_file, exporter, host='', **options):
annotation_ir=self.ir_data,
db_job=self.db_job,
host=host,
_PREFETCH_IMAGES=self._PREFETCH_IMAGES,
)

temp_dir_base = self.db_job.get_tmp_dirname()
Expand All @@ -768,6 +770,7 @@ def import_annotations(self, src_file, importer, **options):
annotation_ir=AnnotationIR(self.db_job.segment.task.dimension),
db_job=self.db_job,
create_callback=self.create,
_PREFETCH_IMAGES=self._PREFETCH_IMAGES,
)
self.delete()

Expand Down Expand Up @@ -1022,7 +1025,7 @@ def put_job_data(pk, data):
@plugin_decorator
@transaction.atomic
def patch_job_data(pk, data, action):
annotation = JobAnnotation(pk, prefetch_images=False)
annotation = JobAnnotation(pk)
if action == PatchAction.CREATE:
annotation.create(data)
elif action == PatchAction.UPDATE:
Expand All @@ -1035,7 +1038,7 @@ def patch_job_data(pk, data, action):
@silk_profile(name="DELETE job data")
@transaction.atomic
def delete_job_data(pk):
annotation = JobAnnotation(pk, prefetch_images=False)
annotation = JobAnnotation(pk)
annotation.delete()

def export_job(job_id, dst_file, format_name, server_url=None, save_images=False):
Expand All @@ -1045,7 +1048,7 @@ def export_job(job_id, dst_file, format_name, server_url=None, save_images=False
# more dump request received at the same time:
# https://github.com/cvat-ai/cvat/issues/217
with transaction.atomic():
job = JobAnnotation(job_id)
job = JobAnnotation(job_id, prefetch_images=True)
job.init_from_db()

exporter = make_exporter(format_name)
Expand Down Expand Up @@ -1112,9 +1115,10 @@ def import_task_annotations(src_file, task_id, format_name, conv_mask_to_poly):
except (DatasetError, DatasetImportError, DatasetNotFoundError) as ex:
raise CvatImportError(str(ex))


@transaction.atomic
def import_job_annotations(src_file, job_id, format_name, conv_mask_to_poly):
job = JobAnnotation(job_id)
job = JobAnnotation(job_id, prefetch_images=True)

importer = make_importer(format_name)
with open(src_file, 'rb') as f:
Expand Down

0 comments on commit 9e2f4f0

Please sign in to comment.