Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Synthia data format and Add Synthia AL and SF formats #987

Merged
merged 13 commits into from
May 8, 2023
Prev Previous commit
Next Next commit
fix format detector
  • Loading branch information
wonjuleee committed May 4, 2023
commit 7a976554018726b5cb6f97bca7170a24820f8d8b
7 changes: 1 addition & 6 deletions datumaro/plugins/data_formats/synthia/base.py
Original file line number Diff line number Diff line change
@@ -67,12 +67,7 @@ def _make_categories(self, label_map=None):
def _load_categories(self, path):
if has_meta_file(path):
return self._make_categories(parse_meta_file(path))
label_map_path = osp.join(path, self._path_format.LABELMAP_FILE)
if osp.isfile(label_map_path):
label_map = self._parse_label_map(label_map_path)
else:
label_map = self._label_map
return self._make_categories(label_map)
return self._make_categories(self._label_map)

def _load_items(self, root_dir):
image_dir = osp.join(root_dir, self._path_format.IMAGES_DIR)
3 changes: 0 additions & 3 deletions datumaro/plugins/data_formats/synthia/format.py
Original file line number Diff line number Diff line change
@@ -16,21 +16,18 @@ class SynthiaRandPath:
IMAGES_DIR = "RGB"
LABELS_SEGM_DIR = "GTTXT"
SEMANTIC_SEGM_DIR = "GT"
LABELMAP_FILE = "label_colors.txt"


class SynthiaSfPath:
IMAGES_DIR = "RGBLeft"
SEMANTIC_SEGM_DIR = "GTLeft"
DEPTH_DIR = "DepthLeft"
LABELMAP_FILE = "label_colors.txt"


class SynthiaAlPath:
IMAGES_DIR = "RGB"
SEMANTIC_SEGM_DIR = "SemSeg"
DEPTH_DIR = "Depth"
LABELMAP_FILE = "label_colors.txt"


SynthiaRandLabelMap = OrderedDict(
34 changes: 20 additions & 14 deletions datumaro/plugins/data_formats/synthia/importer.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: MIT

import os.path as osp

from datumaro.components.format_detection import FormatDetectionConfidence, FormatDetectionContext
from datumaro.components.importer import Importer

@@ -10,14 +12,18 @@

class _SynthiaImporter(Importer):
FORMAT = None
META_FILES = []
META_FOLDERS = []

@classmethod
def detect(cls, context: FormatDetectionContext) -> FormatDetectionConfidence:
with context.require_any():
for prefix in cls.META_FILES:
with context.alternative():
context.require_file(f"{prefix}/*.png")
for folder in cls.META_FOLDERS:
if not osp.isdir(osp.join(context.root_path, folder)):
context.fail("Any Synthia format is not detected.")

# with context.require_any():
# for prefix in cls.META_FOLDERS:
# with context.alternative():
# context.require_file(f"{prefix}/*.png")

return FormatDetectionConfidence.MEDIUM

@@ -28,23 +34,23 @@ def find_sources(cls, path):

class SynthiaRandImporter(_SynthiaImporter):
FORMAT = SynthiaFormatType.synthia_rand.name
META_FILES = []
META_FOLDERS = []
for prefix in vars(SynthiaRandPath).values():
if isinstance(prefix, str):
META_FILES.append(prefix)
if isinstance(prefix, str) and "datumaro" not in prefix:
META_FOLDERS.append(prefix)


class SynthiaSfImporter(_SynthiaImporter):
FORMAT = SynthiaFormatType.synthia_sf.name
META_FILES = []
META_FOLDERS = []
for prefix in vars(SynthiaSfPath).values():
if isinstance(prefix, str):
META_FILES.append(prefix)
if isinstance(prefix, str) and "datumaro" not in prefix:
META_FOLDERS.append(prefix)


class SynthiaAlImporter(_SynthiaImporter):
FORMAT = SynthiaFormatType.synthia_al.name
META_FILES = []
META_FOLDERS = []
for prefix in vars(SynthiaAlPath).values():
if isinstance(prefix, str):
META_FILES.append(prefix)
if isinstance(prefix, str) and "datumaro" not in prefix:
META_FOLDERS.append(prefix)