Ejemplo n.º 1
0
async def upload_images(cvat_project_id, training_id, api):
    project = Project.objects.get(pk=cvat_project_id)
    tasks: List[Task] = project.tasks.all()
    for task in tasks:
        frame_provider = FrameProvider(task)
        frames = frame_provider.get_frames()
        for i, (buffer, _) in enumerate(frames):
            training_image_id = api.upload_image(training_id=training_id,
                                                 buffer=buffer)
            if training_image_id:
                TrainingProjectImage.objects.create(
                    project=project,
                    task=task,
                    idx=i,
                    training_image_id=training_image_id)
Ejemplo n.º 2
0
def dump_media_files(task_data: TaskData,
                     img_dir: str,
                     project_data: ProjectData = None):
    ext = ''
    if task_data.meta['task']['mode'] == 'interpolation':
        ext = FrameProvider.VIDEO_FRAME_EXT

    frame_provider = FrameProvider(task_data.db_task.data)
    frames = frame_provider.get_frames(frame_provider.Quality.ORIGINAL,
                                       frame_provider.Type.BUFFER)
    for frame_id, (frame_data, _) in enumerate(frames):
        frame_name = task_data.frame_info[frame_id]['path'] if project_data is None \
            else project_data.frame_info[(task_data.db_task.id, frame_id)]['path']
        img_path = osp.join(img_dir, frame_name + ext)
        os.makedirs(osp.dirname(img_path), exist_ok=True)
        with open(img_path, 'wb') as f:
            f.write(frame_data.getvalue())
Ejemplo n.º 3
0
def upload_images_job(task_id: int):
    if TrainingProjectImage.objects.filter(task_id=task_id).count() is 0:
        task = Task.objects.get(pk=task_id)
        frame_provider = FrameProvider(task.data)
        frames = frame_provider.get_frames()
        api = TrainingServerAPI(
            host=task.project.training_project.host,
            username=task.project.training_project.username,
            password=task.project.training_project.password,
        )

        for i, (buffer, _) in enumerate(frames):
            training_image_id = api.upload_image(
                training_id=task.project.training_project.training_id,
                buffer=buffer)
            if training_image_id:
                TrainingProjectImage.objects.create(
                    task=task, idx=i, training_image_id=training_image_id)
Ejemplo n.º 4
0
def _export(dst_file, task_data, anno_callback, save_images=False):
    with TemporaryDirectory() as temp_dir:
        with open(osp.join(temp_dir, 'annotations.xml'), 'wb') as f:
            anno_callback(f, task_data)

        if save_images:
            img_dir = osp.join(temp_dir, 'images')
            frame_provider = FrameProvider(task_data.db_task.data)
            frames = frame_provider.get_frames(
                frame_provider.Quality.ORIGINAL,
                frame_provider.Type.NUMPY_ARRAY)
            for frame_id, (frame_data, _) in enumerate(frames):
                frame_name = task_data.frame_info[frame_id]['path']
                if '.' in frame_name:
                    save_image(osp.join(img_dir, frame_name),
                        frame_data, jpeg_quality=100, create_dir=True)
                else:
                    save_image(osp.join(img_dir, frame_name + '.png'),
                        frame_data, create_dir=True)

        make_zip_archive(temp_dir, dst_file)
Ejemplo n.º 5
0
def _export(dst_file, task_data, anno_callback, save_images=False):
    with TemporaryDirectory() as temp_dir:
        with open(osp.join(temp_dir, 'annotations.xml'), 'wb') as f:
            anno_callback(f, task_data)

        if save_images:
            ext = ''
            if task_data.meta['task']['mode'] == 'interpolation':
                ext = FrameProvider.VIDEO_FRAME_EXT

            img_dir = osp.join(temp_dir, 'images')
            frame_provider = FrameProvider(task_data.db_task.data)
            frames = frame_provider.get_frames(frame_provider.Quality.ORIGINAL,
                                               frame_provider.Type.BUFFER)
            for frame_id, (frame_data, _) in enumerate(frames):
                frame_name = task_data.frame_info[frame_id]['path']
                img_path = osp.join(img_dir, frame_name + ext)
                os.makedirs(osp.dirname(img_path), exist_ok=True)
                with open(img_path, 'wb') as f:
                    f.write(frame_data.getvalue())

        make_zip_archive(temp_dir, dst_file)