def detect(cls, context: FormatDetectionContext) -> None:
        annot_paths = context.require_files('**/*.xml')

        for annot_path in annot_paths:
            with context.probe_text_file(
                annot_path, "must be a LabelMe annotation file",
            ) as f:
                elem_parents = []

                for event, elem in ElementTree.iterparse(f, events=('start', 'end')):
                    if event == 'start':
                        if elem_parents == [] and elem.tag != 'annotation':
                            raise Exception

                        if elem_parents == ['annotation', 'object'] \
                                and elem.tag in {'polygon', 'segm'}:
                            return

                        elem_parents.append(elem.tag)
                    elif event == 'end':
                        elem_parents.pop()

                        if elem_parents == ['annotation'] and elem.tag == 'object':
                            # If we got here, then we found an object with no
                            # polygon and no mask, so it's probably the wrong
                            # format.
                            raise Exception
 def detect(cls, context: FormatDetectionContext) -> None:
     with context.require_any():
         for prefix in (VggFace2Path.BBOXES_FILE,
                        VggFace2Path.LANDMARKS_FILE):
             with context.alternative():
                 context.require_file(
                     f'{VggFace2Path.ANNOTATION_DIR}/{prefix}*.csv')
    def detect(
        cls,
        context: FormatDetectionContext,
    ) -> Optional[FormatDetectionConfidence]:
        if not cls.find_sources_with_params(context.root_path):
            context.fail("specific requirement information unavailable")

        return FormatDetectionConfidence.LOW
Exemple #4
0
 def detect(cls, context: FormatDetectionContext):
     with context.require_any():
         for image_dir in MarsPath.IMAGE_DIR_PATTERNS:
             with context.alternative():
                 context.require_file('/'.join([
                     MarsPath.SUBSET_DIR_PATTERN, image_dir,
                     image_dir + MarsPath.IMAGE_NAME_POSTFIX
                 ]))
Exemple #5
0
 def detect(cls, context: FormatDetectionContext) -> None:
     try:
         next(
             find_files(context.root_path, VIDEO_EXTENSIONS,
                        recursive=True))
         return FormatDetectionConfidence.LOW
     except StopIteration:
         context.fail("No video files found in '%s'. "
                      "Checked extensions: %s" %
                      (context.root_path, ', '.join(VIDEO_EXTENSIONS)))
    def detect(cls, context: FormatDetectionContext) -> None:
        annot_file = context.require_file('*.xml')

        with context.probe_text_file(
                annot_file,
                "must be an XML file with an \"annotations\" root element",
        ) as f:
            _, root_elem = next(ElementTree.iterparse(f, events=('start', )))
            if root_elem.tag != 'annotations':
                raise Exception
Exemple #7
0
    def detect(cls, context: FormatDetectionContext) -> None:
        annot_file = context.require_file('annotations/*.json')

        with context.probe_text_file(
                annot_file,
                "must be a JSON object with \"categories\" "
                "and \"items\" keys",
        ) as f:
            contents = parse_json(f.read())
            if not {'categories', 'items'} <= contents.keys():
                raise Exception
Exemple #8
0
    def detect(cls, context: FormatDetectionContext) -> None:
        annot_path = context.require_file('*/**/*.json')

        with context.probe_text_file(
                annot_path,
                "must be a JSON object with an \"annotation\" key",
        ) as f:
            contents = parse_json(f.read())
            if not isinstance(contents, dict):
                raise Exception
            if 'annotation' not in contents:
                raise Exception
Exemple #9
0
    def detect(cls, context: FormatDetectionContext) -> None:
        annot_path = context.require_file('*/gt.txt')

        with context.probe_text_file(
            annot_path, 'must be a ICDAR-like annotation file',
        ) as f:
            reader = csv.reader(f,
                doublequote=False, escapechar='\\', skipinitialspace=True)
            fields = next(reader)
            if len(fields) != 2: raise Exception
            if osp.splitext(fields[0])[1] not in IMAGE_EXTENSIONS:
                raise Exception
Exemple #10
0
    def detect(cls, context: FormatDetectionContext) -> None:
        annot_file = context.require_file('*.xml')

        with context.probe_text_file(
            annot_file, "must be a KITTI-like annotation file",
        ) as f:
            parser = ET.iterparse(f, events=('start',))

            _, elem = next(parser)
            if elem.tag != 'boost_serialization':
                raise Exception

            _, elem = next(parser)
            if elem.tag != 'tracklets':
                raise Exception
    def detect(cls, context: FormatDetectionContext) -> None:
        annot_path = context.require_file('*.txt',
            exclude_fnames=ImagenetTxtPath.LABELS_FILE)

        with context.probe_text_file(
            annot_path,
            "must be an ImageNet-like annotation file",
        ) as f:
            for line in f:
                _, _, label_ids = _parse_annotation_line(line)
                if label_ids: break
            else:
                # If there are no labels in the entire file, it's probably
                # not actually an ImageNet file.
                raise Exception
Exemple #12
0
    def detect(cls, context: FormatDetectionContext) -> None:
        annot_path = context.require_file(
            '*.txt', exclude_fnames=CamvidPath.LABELMAP_FILE)

        with context.probe_text_file(
                annot_path,
                'must be a CamVid-like annotation file',
        ) as f:
            for line in f:
                _, mask_path = _parse_annotation_line(line)
                if mask_path is not None:
                    break
            else:
                # If there are no masks in the entire file, it's probably
                # not actually a CamVid file.
                raise Exception

        context.require_file(glob.escape(mask_path))
Exemple #13
0
    def detect(cls, context: FormatDetectionContext) -> None:
        # The `voc` format is inherently ambiguous with `voc_classification`,
        # `voc_detection`, etc. To remove the ambiguity (and thus make it
        # possible to use autodetection with the VOC datasets), disable
        # autodetection for the single-task formats.
        if len(cls._TASKS) == 1:
            context.raise_unsupported()

        with context.require_any():
            task_dirs = {task_dir for _, task_dir in cls._TASKS.values()}
            for task_dir in sorted(task_dirs):
                with context.alternative():
                    context.require_file(
                        osp.join(VocPath.SUBSETS_DIR, task_dir, '*.txt'))
Exemple #14
0
    def detect(
        cls,
        context: FormatDetectionContext,
    ) -> FormatDetectionConfidence:
        # The `coco` format is inherently ambiguous with `coco_instances`,
        # `coco_stuff`, etc. To remove the ambiguity (and thus make it possible
        # to use autodetection with the COCO dataset), disable autodetection
        # for the single-task formats.
        if len(cls._TASKS) == 1:
            context.raise_unsupported()

        with context.require_any():
            for task in cls._TASKS.keys():
                with context.alternative():
                    context.require_file(f'annotations/{task.name}_*.json')
Exemple #15
0
 def detect(cls, context: FormatDetectionContext) -> None:
     context.require_file(MpiiJsonPath.ANNOTATION_FILE)
 def detect(cls, context: FormatDetectionContext) -> None:
     context.require_file('*' + VottJsonPath.ANNO_FILE_SUFFIX)
 def detect(cls, context: FormatDetectionContext) -> None:
     with context.require_any():
         for prefix in (SynthiaPath.IMAGES_DIR, SynthiaPath.LABELS_SEGM_DIR,
                        SynthiaPath.SEMANTIC_SEGM_DIR):
             with context.alternative():
                 context.require_file(f'{prefix}/**/*.png')
Exemple #18
0
 def detect(cls, context: FormatDetectionContext) -> None:
     context.require_file(
         f'*/{LfwPath.ANNOTATION_DIR}/{LfwPath.PAIRS_FILE}')
Exemple #19
0
 def detect(cls, context: FormatDetectionContext) -> None:
     context.require_file('obj.data')
Exemple #20
0
 def detect(cls, context: FormatDetectionContext) -> None:
     gt_txt_path = context.require_file('**/*_GT.txt')
     gt_bmp_path = osp.splitext(gt_txt_path)[0] + '.bmp'
     context.require_file(glob.escape(gt_bmp_path))
Exemple #21
0
 def detect(cls, context: FormatDetectionContext) -> None:
     context.require_file('**/gt_*.txt')
 def detect(cls, context: FormatDetectionContext) -> None:
     context.require_file(f'{WiderFacePath.ANNOTATIONS_DIR}/*.txt')
Exemple #23
0
 def detect(cls, context: FormatDetectionContext) -> None:
     with context.require_any():
         for pattern in cls.POSSIBLE_ANNOTATION_PATTERNS:
             with context.alternative():
                 context.require_file(
                     f'{OpenImagesPath.ANNOTATIONS_DIR}/{pattern}')