def _export(dst_file, task_data, save_images=False): dataset = Dataset.from_extractors(CvatTaskDataExtractor( task_data, include_images=save_images), env=dm_env) with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'yolo', save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data, include_images=save_images), env=dm_env) with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'tf_detection_api', save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, task_data, save_images=False): extractor = CvatTaskDataExtractor(task_data, include_images=save_images) extractor = Dataset.from_extractors(extractor) # apply lazy transforms with TemporaryDirectory() as temp_dir: dm_env.converters.get('coco_instances').convert( extractor, save_dir=temp_dir, save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export_images(dst_file, task_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( task_data, include_images=save_images, format_type='sly_pointcloud', dimension=DimensionType.DIM_3D), env=dm_env) with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'sly_pointcloud', save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export_task(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: dump_task_anno(f, task_data, anno_callback) if save_images: dump_media_files(task_data, osp.join(temp_dir, 'images')) make_zip_archive(temp_dir, dst_file)
def dump(file_object, annotations): from cvat.apps.dataset_manager.bindings import CvatAnnotationsExtractor from cvat.apps.dataset_manager.util import make_zip_archive from tempfile import TemporaryDirectory extractor = CvatAnnotationsExtractor('', annotations) converter = CvatYoloConverter() with TemporaryDirectory() as temp_dir: converter(extractor, save_dir=temp_dir) make_zip_archive(temp_dir, file_object)
def _export(dst_file, task_data, save_images=False): extractor = CvatTaskDataExtractor(task_data, include_images=save_images) extractor = Dataset.from_extractors(extractor) # apply lazy transforms with TemporaryDirectory() as temp_dir: converter = dm_env.make_converter('mot_seq_gt', save_images=save_images) converter(extractor, save_dir=temp_dir) make_zip_archive(temp_dir, dst_file)
def _export_segmentation(dst_file, task_data, save_images=False): dataset = Dataset.from_extractors(CvatTaskDataExtractor( task_data, include_images=save_images), env=dm_env) with TemporaryDirectory() as temp_dir: dataset.transform('polygons_to_masks') dataset.transform('boxes_to_masks') dataset.transform('merge_instance_segments') dataset.export(temp_dir, 'icdar_text_segmentation', save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data=instance_data, include_images=save_images), env=dm_env) if not save_images: dataset.transform(DeleteImagePath) with TemporaryDirectory() as tmp_dir: dataset.export(tmp_dir, 'datumaro', save_images=save_images) make_zip_archive(tmp_dir, dst_file)
def _export_recognition(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data, include_images=save_images), env=dm_env) dataset.transform(LabelToCaption) with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'icdar_word_recognition', save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, task_data, save_images=False): extractor = CvatTaskDataExtractor(task_data, include_images=save_images) envt = dm_env.transforms extractor = extractor.transform(envt.get('id_from_image_name')) extractor = Dataset.from_extractors(extractor) # apply lazy transforms with TemporaryDirectory() as temp_dir: converter = dm_env.make_converter('label_me', save_images=save_images) converter(extractor, save_dir=temp_dir) make_zip_archive(temp_dir, dst_file)
def dump(file_object, annotations): from cvat.apps.dataset_manager.bindings import CvatAnnotationsExtractor from cvat.apps.dataset_manager.util import make_zip_archive from datumaro.components.project import Environment from tempfile import TemporaryDirectory extractor = CvatAnnotationsExtractor('', annotations) converter = Environment().make_converter('yolo') with TemporaryDirectory() as temp_dir: converter(extractor, save_dir=temp_dir) make_zip_archive(temp_dir, file_object)
def _export(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data, include_images=save_images), env=dm_env) with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'voc', save_images=save_images, label_map='source') make_zip_archive(temp_dir, dst_file)
def _export(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data, include_images=save_images), env=dm_env) dataset.transform(KeepTracks) # can only export tracks dataset.transform('polygons_to_masks') dataset.transform('boxes_to_masks') dataset.transform('merge_instance_segments') with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'mots_png', save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, task_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( task_data, include_images=save_images), env=dm_env) dataset.transform(RotatedBoxesToPolygons) dataset.transform('polygons_to_masks') dataset.transform('merge_instance_segments') with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'open_images', save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data, include_images=save_images), env=dm_env) dataset.transform(RotatedBoxesToPolygons) dataset.transform('polygons_to_masks') dataset.transform('boxes_to_masks') dataset.transform('merge_instance_segments') with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'voc_segmentation', save_images=save_images, apply_colormap=True, label_map=make_colormap(instance_data)) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, task_data, save_images=False): extractor = CvatTaskDataExtractor(task_data, include_images=save_images) envt = dm_env.transforms extractor = extractor.transform(KeepTracks) # can only export tracks extractor = extractor.transform(envt.get('polygons_to_masks')) extractor = extractor.transform(envt.get('boxes_to_masks')) extractor = extractor.transform(envt.get('merge_instance_segments')) extractor = Dataset.from_extractors(extractor) # apply lazy transforms with TemporaryDirectory() as temp_dir: dm_env.converters.get('mots_png').convert(extractor, save_dir=temp_dir, save_images=save_images) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, task_data, save_images=False): extractor = CvatTaskDataExtractor(task_data, include_images=save_images) envt = dm_env.transforms extractor = extractor.transform(envt.get('polygons_to_masks')) extractor = extractor.transform(envt.get('boxes_to_masks')) extractor = extractor.transform(envt.get('merge_instance_segments')) extractor = Dataset.from_extractors(extractor) # apply lazy transforms with TemporaryDirectory() as temp_dir: converter = dm_env.make_converter('voc_segmentation', apply_colormap=True, label_map=make_colormap(task_data), save_images=save_images) converter(extractor, save_dir=temp_dir) make_zip_archive(temp_dir, dst_file)
def dump(file_object, annotations): from cvat.apps.dataset_manager.bindings import CvatAnnotationsExtractor from cvat.apps.dataset_manager.util import make_zip_archive from datumaro.components.project import Environment, Dataset from tempfile import TemporaryDirectory env = Environment() id_from_image = env.transforms.get('id_from_image_name') extractor = CvatAnnotationsExtractor('', annotations) extractor = extractor.transform(id_from_image) extractor = Dataset.from_extractors(extractor) # apply lazy transforms converter = env.make_converter('voc', label_map='source') with TemporaryDirectory() as temp_dir: converter(extractor, save_dir=temp_dir) make_zip_archive(temp_dir, file_object)
def _export_images(dst_file, task_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( task_data, include_images=save_images, format_type="kitti_raw", dimension=DimensionType.DIM_3D), env=dm_env) with TemporaryDirectory() as temp_dir: dataset.export(temp_dir, 'kitti_raw', save_images=save_images, reindex=True) make_zip_archive(temp_dir, dst_file)
def _export_project(dst_file: str, project_data: ProjectData, anno_callback: Callable, save_images: bool = False): with TemporaryDirectory() as temp_dir: with open(osp.join(temp_dir, 'annotations.xml'), 'wb') as f: dump_project_anno(f, project_data, anno_callback) if save_images: for task_data in project_data.task_data: subset = get_defaulted_subset(task_data.db_task.subset, project_data.subsets) subset_dir = osp.join(temp_dir, 'images', subset) os.makedirs(subset_dir, exist_ok=True) dump_media_files(task_data, subset_dir, project_data) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, task_data, save_images=False): extractor = CvatTaskDataExtractor(task_data, include_images=save_images) envt = dm_env.transforms extractor = extractor.transform(envt.get('polygons_to_masks')) extractor = extractor.transform(envt.get('boxes_to_masks')) extractor = extractor.transform(envt.get('merge_instance_segments')) extractor = Dataset.from_extractors(extractor) # apply lazy transforms label_map = make_colormap(task_data) with TemporaryDirectory() as temp_dir: dm_env.converters.get('camvid').convert( extractor, save_dir=temp_dir, save_images=save_images, apply_colormap=True, label_map={label: label_map[label][0] for label in label_map}) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data, include_images=save_images), env=dm_env) dataset.transform('polygons_to_masks') dataset.transform('boxes_to_masks') dataset.transform('merge_instance_segments') label_map = make_colormap(instance_data) with TemporaryDirectory() as temp_dir: dataset.export( temp_dir, 'camvid', save_images=save_images, apply_colormap=True, label_map={label: label_map[label][0] for label in label_map}) make_zip_archive(temp_dir, dst_file)
def _export(dst_file, instance_data, save_images=False): dataset = Dataset.from_extractors(GetCVATDataExtractor( instance_data, include_images=save_images), env=dm_env) with TemporaryDirectory() as tmp_dir: dataset.transform(RotatedBoxesToPolygons) dataset.transform('polygons_to_masks') dataset.transform('merge_instance_segments') dataset.export(tmp_dir, format='kitti', label_map={ k: v[0] for k, v in make_colormap(instance_data).items() }, apply_colormap=True, save_images=save_images) make_zip_archive(tmp_dir, dst_file)
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)
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)
def __call__(self, dst_file, task_data, save_images=False): with TemporaryDirectory() as temp_dir: self._export(task_data, save_dir=temp_dir, save_images=save_images) make_zip_archive(temp_dir, dst_file)