Kaynağa Gözat

updated folder loading further

Dimitri Korsch 4 yıl önce
ebeveyn
işleme
743ef50b01

+ 1 - 1
cvdatasets/_version.py

@@ -1 +1 @@
-__version__ = "0.8.1"
+__version__ = "0.8.2"

+ 3 - 3
cvdatasets/annotation/base.py

@@ -19,7 +19,7 @@ from cvdatasets.utils.decorators import only_with_info
 class BaseAnnotations(abc.ABC):
 
 	@classmethod
-	def extract_kwargs(cls, opts):
+	def extract_kwargs(cls, opts, *args, **kwargs):
 		return dict(
 			root_or_infofile=opts.data,
 			load_strict=getattr(opts, "load_strict", False),
@@ -27,8 +27,8 @@ class BaseAnnotations(abc.ABC):
 		)
 
 	@classmethod
-	def new(cls, opts, **_kwargs):
-		kwargs = cls.extract_kwargs(opts)
+	def new(cls, opts,  *, ds_info=None, **_kwargs):
+		kwargs = cls.extract_kwargs(opts, ds_info)
 		kwargs.update(_kwargs)
 		kwargs_str = pretty_print_dict(kwargs)
 		try:

+ 2 - 2
cvdatasets/annotation/mixins/features_mixin.py

@@ -6,8 +6,8 @@ class FeaturesMixin(abc.ABC):
 	FEATURE_PHONY = dict(train=["train"], test=["test", "val"])
 
 	@classmethod
-	def extract_kwargs(cls, opts):
-		kwargs = super(FeaturesMixin, cls).extract_kwargs(opts)
+	def extract_kwargs(cls, opts, *args, **kwargs):
+		kwargs = super(FeaturesMixin, cls).extract_kwargs(opts, *args, **kwargs)
 		kwargs.update(dict(
 			feature_model=getattr(opts, "feature_model", None),
 		))

+ 2 - 2
cvdatasets/annotation/mixins/parts_mixin.py

@@ -13,8 +13,8 @@ from cvdatasets.utils.decorators import only_with_info
 class PartsMixin(abc.ABC):
 
 	@classmethod
-	def extract_kwargs(cls, opts):
-		kwargs = super(PartsMixin, cls).extract_kwargs(opts)
+	def extract_kwargs(cls, opts, *args, **kwargs):
+		kwargs = super(PartsMixin, cls).extract_kwargs(opts, *args, **kwargs)
 		kwargs.update(dict(
 			parts=getattr(opts, "parts", None),
 		))

+ 5 - 3
cvdatasets/annotation/types/__init__.py

@@ -17,16 +17,18 @@ class AnnotationType(BaseChoiceType):
 
 	@classmethod
 	def new_annotation(cls, opts, **kwargs):
+		info_file = read_info_file(opts.data)
+		ds_info = info_file.DATASETS[opts.dataset]
+
 		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 \"{opts.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, **kwargs)
+		return annot.new(opts, ds_info=ds_info, **kwargs)
 
 	@classmethod
 	def as_choices(cls, add_phony=True):

+ 23 - 3
cvdatasets/annotation/types/folder_annotations.py

@@ -5,11 +5,31 @@ from cvdatasets.annotation.files import AnnotationFiles
 
 class FolderAnnotations(Annotations):
 	_default_folders = dict(
-		train_images="ILSVRC2012_img_train",
-		val_images="ILSVRC2012_img_val",
-		test_images=("ILSVRC2012_img_test", True)
+		train_images="train",
+		val_images="val",
+		test_images=("test", True)
 	)
 
+	@classmethod
+	def extract_kwargs(cls, opts, ds_info=None, *args, **kwargs):
+		kwargs = super(FolderAnnotations, cls).extract_kwargs(opts, ds_info=ds_info, *args, **kwargs)
+		if ds_info is None:
+			return kwargs
+
+		folders = dict(cls._default_folders)
+
+		for key in ["train", "val", "test"]:
+			key = f"{key}_images"
+
+			value = ds_info.get(key)
+			if value is None:
+				continue
+
+			folders[key] = value
+
+		kwargs["folders"] = folders
+		return kwargs
+
 	def __init__(self, *args, folders=_default_folders, **kwargs):
 		self._folders = folders
 		super(FolderAnnotations, self).__init__(*args, **kwargs)

+ 16 - 0
scripts/info_files/info.yml

@@ -54,6 +54,8 @@ DATASETS:
     folder: ImageNet
     annotations: "BJOERN"
     annotation_type: FOLDER
+    train_images: ILSVRC2012_img_train
+    val_images: ILSVRC2012_img_val
     n_classes: 1000
 
   IMAGENET_TOP_INAT20: &inet_top_inat20
@@ -67,6 +69,11 @@ DATASETS:
     annotation_type: FILE_LIST
     n_classes: 200
 
+  CUB10:         &cub10
+    <<: *cub200
+    annotations: "cub10"
+    n_classes: 10
+
   CUB200_2FOLD:   &cub200_2fold
     <<: *cub200
     folder: birds/cub200_2fold
@@ -110,6 +117,15 @@ DATASETS:
     annotation_type: FILE_LIST
     n_classes: 102
 
+  HERBA19:         &herba19
+    folder: herbarium
+    annotations: "2019"
+    annotation_type: FOLDER
+    train_images: small-train
+    val_images: small-validation
+    test_images: small-test
+    n_classes: 683
+
   INAT20:         &inat20
     folder: inat
     annotations: "2020/PLAIN"