Browse Source

added new classmethod for annotation instantiation. fixed cars dataset

Dimitri Korsch 5 years ago
parent
commit
66e06b75cf

+ 1 - 1
cvdatasets/_version.py

@@ -1 +1 @@
-__version__ = "0.5.1"
+__version__ = "0.5.2"

+ 14 - 0
cvdatasets/annotations/base/__init__.py

@@ -18,6 +18,20 @@ class BaseAnnotations(abc.ABC):
 
 	FEATURE_PHONY = dict(train=["train"], test=["test", "val"])
 
+	@classmethod
+	def new(cls, opts, **additional_kwargs):
+		kwargs = dict(
+			root_or_infofile=opts.data,
+			parts=getattr(opts, "parts", None),
+			load_strict=getattr(opts, "load_strict", False),
+			feature_model=getattr(opts, "feature_model", False),
+		)
+
+		kwargs.update(additional_kwargs)
+
+		return cls(**kwargs)
+
+
 	def __init__(self, *, root_or_infofile, feature_model=None, load_strict=True, **kwargs):
 		super(BaseAnnotations, self).__init__(**kwargs)
 		self.feature_model = feature_model

+ 2 - 1
cvdatasets/annotations/impl/cars.py

@@ -4,11 +4,12 @@ from os.path import join
 
 from cvdatasets.annotations.base import BaseAnnotations
 from cvdatasets.annotations.base.bbox_mixin import BBoxMixin
+from cvdatasets.annotations.base.parts_mixin import PartsMixin
 from cvdatasets.utils import _MetaInfo
 
 
 
-class CARS_Annotations(BBoxMixin, BaseAnnotations):
+class CARS_Annotations(BBoxMixin, PartsMixin, BaseAnnotations):
 	name="CARS"
 
 	@property

+ 1 - 5
scripts/display.py

@@ -19,11 +19,7 @@ def main(args):
 	annotation_cls = AnnotationType[args.dataset].value
 
 	logging.info(f"Loading \"{args.dataset}\" annnotations from \"{args.data}\"")
-	annot = annotation_cls(
-		root_or_infofile=args.data,
-		feature_model=args.feature_model,
-		load_strict=False,
-		parts=args.parts)
+	annot = annotation_cls.new(args)
 
 	kwargs = {}
 	if annot.info is None: