Эх сурвалжийг харах

changed the annotation type handling. modified display script for it

Dimitri Korsch 5 жил өмнө
parent
commit
5fdf70ae13

+ 2 - 4
cvdatasets/annotation/base.py

@@ -23,6 +23,7 @@ class BaseAnnotations(abc.ABC):
 		return dict(
 			root_or_infofile=opts.data,
 			load_strict=getattr(opts, "load_strict", False),
+			dataset_key=getattr(opts, "dataset", None)
 		)
 
 	@classmethod
@@ -79,10 +80,7 @@ class BaseAnnotations(abc.ABC):
 	@property
 	@only_with_info
 	def dataset_key(self):
-		if hasattr(self.__class__, "name"):
-			return self.__class__.name
-
-		elif self._dataset_key is not None:
+		if self._dataset_key is not None:
 			return self._dataset_key
 
 		else:

+ 11 - 9
cvdatasets/annotation/types/__init__.py

@@ -6,15 +6,9 @@ from cvdatasets.annotation.types.json_annotations import JSONAnnotations
 
 from cvargparse.utils import BaseChoiceType
 from cvargparse.utils.enumerations import MetaBaseType
+from cvdatasets.utils import read_info_file
 
-class AnnotationMetaType(MetaBaseType):
-
-	def __getitem__(cls, key):
-		res = super(AnnotationMetaType, cls).__getitem__(key)
-		res.value.name = key
-		return res
-
-class AnnotationType(BaseChoiceType, metaclass=AnnotationMetaType):
+class AnnotationType(BaseChoiceType):
 	FOLDER = FolderAnnotations
 	FILE_LIST = FileListAnnotations
 	JSON = JSONAnnotations
@@ -23,7 +17,15 @@ class AnnotationType(BaseChoiceType, metaclass=AnnotationMetaType):
 
 	@classmethod
 	def new_annotation(cls, opts):
-		annot = cls[opts.dataset].value
+		if opts.dataset in cls:
+			annot = cls[opts.dataset].value
+		else:
+			info_file = read_info_file(opts.data)
+			assert opts.dataset in info_file.DATASETS, \
+				f"No information was found about the dataset \"{args.dataset}\" in the info file \"{args.data}\""
+			ds_info = info_file.DATASETS[opts.dataset]
+			annot = cls[ds_info.annotation_type.lower()].value
+
 		return annot.new(opts)
 
 	@classmethod

+ 2 - 8
scripts/display.py

@@ -13,21 +13,15 @@ from cvdatasets.annotation import AnnotationType
 from utils import parser, plot_crops
 
 def main(args):
-	assert args.dataset in AnnotationType, \
-		f"AnnotationType is not known: \"{args.dataset}\""
+	# assert args.dataset in AnnotationType, \
+	# 	f"AnnotationType is not known: \"{args.dataset}\""
 
 	annot = AnnotationType.new_annotation(args)
-	# annotation_cls = AnnotationType[args.dataset].value
-	# logging.info(f"Loading \"{args.dataset}\" annnotations from \"{args.data}\"")
-	# annot = annotation_cls.new(args, )
-	# annot = annotation_cls(root_or_infofile=args.data, parts=args.parts, load_strict=False)
 
 	kwargs = {}
 	if annot.info is None:
-		# features = args.features[0 if args.subset == "train" else 1]
 		kwargs = dict(
 			part_rescale_size=args.rescale_size,
-			# features=features,
 			uniform_parts=args.uniform_parts,
 			ratio=args.ratio,
 		)