def test_supervisely_convert_object(tmpdir): input_dir = Path( 'tests' ) / 'converter_test' / 'Supervisely' / 'input' / 'toSuperAnnotate' / 'vector' out_dir = Path(tmpdir) / 'object_detection_desktop' sa.import_annotation_format(input_dir, out_dir, 'Supervisely', '', 'Vector', 'object_detection', 'Desktop')
def test_coco_vector_object_instance(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "COCO" / "input" / "toSuperAnnotate" / "instance_segmentation" out_dir = Path(tmpdir) / "object_vector_instance_desktop" sa.import_annotation_format(input_dir, out_dir, "COCO", "instances_test", "Vector", "instance_segmentation", "Desktop")
def coco_desktop_object(tmpdir): out_dir = tmpdir / "coco_from_desktop" final_dir = tmpdir / "coco_to_Web" sa.export_annotation_format( "tests/converter_test/COCO/input/fromSuperAnnotate/cats_dogs_desktop", str(out_dir), "COCO", "object_test", "Vector", "object_detection", "Desktop") image_list = glob(str(out_dir / 'train_set' / '*.jpg')) for image in image_list: shutil.copy(image, out_dir / Path(image).name) shutil.rmtree(out_dir / 'train_set') sa.import_annotation_format(str(out_dir), str(final_dir), "COCO", "object_test_train", "Vector", "object_detection", "Web") project_name = "coco2sa_object_pipline" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, final_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, final_dir) sa.upload_annotations_from_folder_to_project(project, final_dir) return 0
def test_voc_vector_object(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "VOC" / "input" / "fromPascalVOCToSuperAnnotate" / "VOC2012" out_dir = Path(tmpdir) / "object_vector" sa.import_annotation_format(input_dir, out_dir, "VOC", "", "Vector", "object_detection", "Desktop")
def test_sagemaker_object_detection(tmpdir): input_dir = Path( 'tests' ) / 'converter_test' / 'SageMaker' / 'input' / 'toSuperAnnotate' / 'object_detection' out_dir = Path(tmpdir) / "object_detection" sa.import_annotation_format(input_dir, out_dir, 'SageMaker', 'test-obj-detect', 'Vector', 'object_detection', 'Desktop')
def yolo_object_detection_desktop(tmpdir): out_dir = tmpdir / "vector_annotation_desktop" sa.import_annotation_format( 'tests/converter_test/YOLO/input/toSuperAnnotate', str(out_dir), 'YOLO', '', 'Vector', 'object_detection', 'Desktop' ) return 0
def test_googlecloud_convert_desktop(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "GoogleCloud" / "input" / "toSuperAnnotate" out_dir = Path(tmpdir) / "output_desktop" sa.import_annotation_format( input_dir, out_dir, "GoogleCloud", "image_object_detection", "Vector", "object_detection", "Desktop" )
def test_dataloop_convert_object(tmpdir): input_dir = Path( 'tests' ) / 'converter_test' / 'DataLoop' / 'input' / 'toSuperAnnotate' out_dir = Path(tmpdir) / 'output_object' sa.import_annotation_format( input_dir, out_dir, 'DataLoop', '', 'Vector', 'object_detection', 'Desktop' )
def test_keypoint_detection_coco2sa(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "COCO" / "input" / "toSuperAnnotate" / "keypoint_detection" out_path = Path(tmpdir) / "toSuperAnnotate" / "keypoint_test" sa.import_annotation_format( input_dir, out_path, "COCO", "person_keypoints_test", "Vector", "keypoint_detection" )
def test_vott_convert_instance(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "VoTT" / "input" / "toSuperAnnotate" out_dir = Path(tmpdir) / "instance_segmentation" sa.import_annotation_format( input_dir, out_dir, "VoTT", "", "Vector", "instance_segmentation", "Desktop" )
def test_panoptic_segmentation_coco2sa(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "COCO" / "input" / "toSuperAnnotate" / "panoptic_segmentation" out_path = Path(tmpdir) / "toSuperAnnotate" / "panoptic_test" sa.import_annotation_format( input_dir, out_path, "COCO", "panoptic_test", "Pixel", "panoptic_segmentation" )
def test_instance_segmentation_coco2sa(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "COCO" / "input" / "toSuperAnnotate" / "instance_segmentation" out_path = Path(tmpdir) / "toSuperAnnotate" / "instances_test" sa.import_annotation_format( input_dir, out_path, "COCO", "instances_test", "Vector", "instance_segmentation" )
def preannotations_upload(args, annotations=False): parser = argparse.ArgumentParser() parser.add_argument('--project', required=True, help='Project name to upload') parser.add_argument( '--folder', required=True, help= 'Folder (SuperAnnotate format) or JSON path (COCO format) from which to upload' ) parser.add_argument('--format', required=False, default="SuperAnnotate", help='Input preannotations format.') parser.add_argument( '--dataset-name', required=False, help='Input annotations dataset name for COCO projects') parser.add_argument( '--task', required=False, help= 'Task type for COCO projects can be panoptic_segmentation (Pixel), instance_segmentation (Pixel), instance_segmentation (Vector), keypoint_detection (Vector)' ) args = parser.parse_args(args) if args.format != "SuperAnnotate": if args.format != "COCO": raise sa.SABaseException( 0, "Not supported annotations format " + args.format) if args.dataset_name is None: raise sa.SABaseException( 0, "Dataset name should be present for COCO format upload.") if args.task is None: raise sa.SABaseException( 0, "Task name should be present for COCO format upload.") logger.info("Annotations in format %s.", args.format) project_type = sa.project_type_int_to_str( sa.get_project_metadata(args.project)["type"]) tempdir = tempfile.TemporaryDirectory() tempdir_path = Path(tempdir.name) sa.import_annotation_format(args.folder, tempdir_path, "COCO", args.dataset_name, project_type, args.task) args.folder = tempdir_path sa.create_annotation_classes_from_classes_json( args.project, Path(args.folder) / "classes" / "classes.json") if annotations: sa.upload_annotations_from_folder_to_project(project=args.project, folder_path=args.folder) else: sa.upload_preannotations_from_folder_to_project( project=args.project, folder_path=args.folder)
def instance_segmentation_coco2sa(tmpdir): out_path = tmpdir / "toSuperAnnotate/instances_test" try: sa.import_annotation_format( "tests/converter_test/COCO/input/toSuperAnnotate/instance_segmentation", str(out_path), "COCO", "instances_test", "Vector", "instance_segmentation") except Exception as e: return 1 return 0
def panoptic_segmentation_coco2sa(tmpdir): out_path = tmpdir / "toSuperAnnotate/panoptic_test" try: sa.import_annotation_format( "tests/converter_test/COCO/input/toSuperAnnotate/panoptic_segmentation", str(out_path), "COCO", "panoptic_test", "Pixel", "panoptic_segmentation") except Exception as e: return 1 return 0
def keypoint_detection_coco2sa(tmpdir): out_path = tmpdir / "toSuperAnnotate/keypoint_test" try: sa.import_annotation_format( "tests/converter_test/COCO/input/toSuperAnnotate/keypoint_detection", str(out_path), "COCO", "person_keypoints_test", "Vector", "keypoint_detection") except Exception as e: return 1 return 0
def test_coco_pixel_instance_desktop(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "COCO" / "input" / "toSuperAnnotate" / "instance_segmentation" out_dir = Path(tmpdir) / "instance_pixel_desktop" with pytest.raises(sa.SABaseException) as e: sa.import_annotation_format(input_dir, out_dir, "COCO", "instances_test", "Pixel", "instance_segmentation", "Desktop") assert e.value.message == "Sorry, but Desktop Application doesn't support 'Pixel' projects."
def labelbox_convert_instance(tmpdir): out_dir = tmpdir / "output_insance" dataset_name = 'labelbox_example' sa.import_annotation_format( 'tests/converter_test/LabelBox/input/toSuperAnnotate', str(out_dir), 'LabelBox', dataset_name, 'Vector', 'instance_segmentation', 'Desktop') all_files = os.listdir(out_dir) json_files = set([ file.replace('___objects.json', '') for file in all_files if os.path.splitext(file) == '.json' ]) image_files = set( [file for file in all_files if os.path.splitext(file) == '.jpg']) if json_files != image_files: return 1 return 0
def test_vgg_convert_object(tmpdir): input_dir = Path( "tests") / "converter_test" / "VGG" / "input" / "toSuperAnnotate" out_dir = Path(tmpdir) / "object_detection" sa.import_annotation_format(input_dir, out_dir, "VGG", "vgg_test", "Vector", "object_detection", "Web") project_name = "vgg_test_object" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir)
def test_supervisely_convert_instance(tmpdir): input_dir = Path( 'tests' ) / 'converter_test' / 'Supervisely' / 'input' / 'toSuperAnnotate' / 'vector' out_dir = Path(tmpdir) / 'instance_segmentation' sa.import_annotation_format(input_dir, out_dir, 'Supervisely', '', 'Vector', 'instance_segmentation', 'Web') project_name = "supervisely_test_vector_convert_instance" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir)
def test_yolo_object_detection_web(tmpdir): input_dir = Path( 'tests') / 'converter_test' / 'YOLO' / 'input' / 'toSuperAnnotate' out_dir = Path(tmpdir) / "vector_annotation_web" sa.import_annotation_format(input_dir, out_dir, 'YOLO', '', 'Vector', 'object_detection', 'Web') project_name = "yolo_object_detection" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir)
def dataloop_convert_vector(tmpdir): out_dir = tmpdir / 'output_vector' sa.import_annotation_format( 'tests/converter_test/DataLoop/input/toSuperAnnotate', str(out_dir), 'DataLoop', '', 'Vector', 'vector_annotation', 'Web') # project_name = "dataloop_test" # projects = sa.search_projects(project_name, True) # if projects: # sa.delete_project(projects[0]) # project = sa.create_project(project_name, "converter vector", "Vector") # sa.create_annotation_classes_from_classes_json( # project, out_dir + "/classes/classes.json" # ) # sa.upload_images_from_folder_to_project(project, out_dir) # sa.upload_annotations_from_folder_to_project(project, out_dir) return 0
def supervisely_convert_keypoint(tmpdir): out_dir = tmpdir / 'keypoint_detection' sa.import_annotation_format( 'tests/converter_test/Supervisely/input/toSuperAnnotate/keypoints', str(out_dir), 'Supervisely', '', 'Vector', 'keypoint_detection', 'Web') project_name = "supervisely_test_keypoint" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir) return 0
def test_coco_vector_instance(tmpdir): input_dir = Path( "tests" ) / "converter_test" / "COCO" / "input" / "toSuperAnnotate" / "instance_segmentation" out_dir = Path(tmpdir) / "instance_vector" sa.import_annotation_format(input_dir, out_dir, "COCO", "instances_test", "Vector", "instance_segmentation", "Web") project_name = "coco2sa_vector_instance" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir)
def vott_convert_vector(tmpdir): out_dir = tmpdir / "vector_annotation" sa.import_annotation_format( "tests/converter_test/VoTT/input/toSuperAnnotate", str(out_dir), "VoTT", "", "Vector", "vector_annotation", "Web") project_name = "vott_vector" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir) return 0
def test_sagemaker_instance_segmentation(tmpdir): input_dir = Path( 'tests' ) / 'converter_test' / 'SageMaker' / 'input' / 'toSuperAnnotate' / 'instance_segmentation' out_dir = Path(tmpdir) / "instance_segmentation" sa.import_annotation_format(input_dir, out_dir, 'SageMaker', 'test-obj-detect', 'Pixel', 'instance_segmentation', 'Web') project_name = "sagemaker_instance_segmentation" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Pixel") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir)
def sagemaker_object_detection(tmpdir): out_dir = tmpdir / "object_detection" sa.import_annotation_format( 'tests/converter_test/SageMaker/input/toSuperAnnotate/object_detection', str(out_dir), 'SageMaker', 'test-obj-detect', 'Vector', 'object_detection', 'Web') project_name = "sagemaker_object_detection" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir + "/classes/classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir) return 0
def coco_vector_object(tmpdir): out_dir = tmpdir / "object_vector" sa.import_annotation_format( "tests/converter_test/COCO/input/toSuperAnnotate/instance_segmentation/", str(out_dir), "COCO", "instances_test", "Vector", "object_detection", "Desktop") # project_name = "coco2sa_vector_object" # projects = sa.search_projects(project_name, True) # if projects: # sa.delete_project(projects[0]) # project = sa.create_project(project_name, "converter vector", "Vector") # sa.create_annotation_classes_from_classes_json( # project, out_dir / "classes" / "classes.json" # ) # sa.upload_images_from_folder_to_project(project, out_dir) # sa.upload_annotations_from_folder_to_project(project, out_dir) return 0
def coco_vector_keypoint(tmpdir): out_dir = tmpdir / "vector_keypoint" sa.import_annotation_format( "tests/converter_test/COCO/input/toSuperAnnotate/keypoint_detection/", str(out_dir), "COCO", "person_keypoints_test", "Vector", "keypoint_detection", "Web") project_name = "coco2sa_keypoint" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Vector") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir) return 0
def coco_pixel_instance(tmpdir): out_dir = tmpdir / "instance_pixel" sa.import_annotation_format( "tests/converter_test/COCO/input/toSuperAnnotate/instance_segmentation/", str(out_dir), "COCO", "instances_test", "Pixel", "instance_segmentation", "Web") project_name = "coco2sa_pixel_instance" projects = sa.search_projects(project_name, True) if projects: sa.delete_project(projects[0]) project = sa.create_project(project_name, "converter vector", "Pixel") sa.create_annotation_classes_from_classes_json( project, out_dir / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, out_dir) sa.upload_annotations_from_folder_to_project(project, out_dir) return 0