Kaynağa Gözat

added iNaturalist 2018 annotation class

Dimitri Korsch 5 yıl önce
ebeveyn
işleme
21f92570ad

+ 3 - 0
cvdatasets/annotations/__init__.py

@@ -2,6 +2,7 @@ from cvdatasets.annotations.impl.cub import CUB_Annotations
 from cvdatasets.annotations.impl.nab import NAB_Annotations
 from cvdatasets.annotations.impl.cars import CARS_Annotations
 from cvdatasets.annotations.impl.inat import INAT19_Annotations
+from cvdatasets.annotations.impl.inat import INAT18_Annotations
 from cvdatasets.annotations.impl.flowers import FLOWERS_Annotations
 from cvdatasets.annotations.impl.dogs import DOGS_Annotations
 from cvdatasets.annotations.impl.hed import HED_Annotations
@@ -27,6 +28,8 @@ class AnnotationType(BaseChoiceType):
 	TIGERS = TIGERS_Annotations
 	TIGERS_TEST = partial(TIGERS_Annotations)
 
+	INAT18 = INAT18_Annotations
+
 	INAT19 = INAT19_Annotations
 	INAT19_MINI = partial(INAT19_Annotations)
 	INAT19_TEST = partial(INAT19_Annotations)

+ 60 - 27
cvdatasets/annotations/impl/inat.py

@@ -9,36 +9,11 @@ from cvdatasets.annotations.base.parts_mixin import PartsMixin
 from cvdatasets.utils import _MetaInfo
 
 
-class INAT19_Annotations(BBoxMixin, PartsMixin, BaseAnnotations):
-
-	name="INAT19"
-
-	@property
-	def meta(self):
-		info = _MetaInfo(
-			images_folder="images",
-			content="trainval2019.json",
-			val_content="val2019.json",
-			# train_content="train2019.json",
-
-			# fake bounding boxes: the whole image
-			bounding_box_dtype=np.dtype([(v, np.int32) for v in "xywh"]),
-
-			parts_file=join("parts", "part_locs.txt"),
-			part_names_file=join("parts", "parts.txt"),
-		)
-
-		info.structure = [
-			[info.content, "_content"],
-			[info.val_content, "_val_content"],
-			[info.parts_file, "_part_locs"],
-			[info.part_names_file, "_part_names"],
-		]
-		return info
+class BaseINAT_Annotations(BBoxMixin, PartsMixin, BaseAnnotations):
 
 	def read_content(self, json_file, attr):
 		if not json_file.endswith(".json"):
-			return super(INAT19_Annotations, self).read_content(json_file, attr)
+			return super(BaseINAT_Annotations, self).read_content(json_file, attr)
 		with self._open(json_file) as f:
 			content = json.load(f)
 			setattr(self, attr, content)
@@ -69,3 +44,61 @@ class INAT19_Annotations(BBoxMixin, PartsMixin, BaseAnnotations):
 		uuid_fnames = [(str(im["id"]), im["file_name"]) for im in self._content["images"]]
 		self.uuids, self.images = map(np.array, zip(*uuid_fnames))
 		self.uuid_to_idx = {uuid: i for i, uuid in enumerate(self.uuids)}
+
+	@property
+	def meta(self):
+		raise NotImplementedError
+
+class INAT19_Annotations(BaseINAT_Annotations):
+
+	name="INAT19"
+
+	@property
+	def meta(self):
+		info = _MetaInfo(
+			images_folder="images",
+			content="trainval2019.json",
+			val_content="val2019.json",
+			# train_content="train2019.json",
+
+			# fake bounding boxes: the whole image
+			bounding_box_dtype=np.dtype([(v, np.int32) for v in "xywh"]),
+
+			parts_file=join("parts", "part_locs.txt"),
+			part_names_file=join("parts", "parts.txt"),
+		)
+
+		info.structure = [
+			[info.content, "_content"],
+			[info.val_content, "_val_content"],
+			[info.parts_file, "_part_locs"],
+			[info.part_names_file, "_part_names"],
+		]
+		return info
+
+class INAT18_Annotations(BaseINAT_Annotations):
+
+	name="INAT18"
+
+	@property
+	def meta(self):
+		info = _MetaInfo(
+			images_folder="images",
+			content="trainval2018.json",
+			# content="train2018.json",
+			val_content="val2018.json",
+
+			# fake bounding boxes: the whole image
+			bounding_box_dtype=np.dtype([(v, np.int32) for v in "xywh"]),
+
+			parts_file=join("parts", "part_locs.txt"),
+			part_names_file=join("parts", "parts.txt"),
+		)
+
+		info.structure = [
+			[info.content, "_content"],
+			[info.val_content, "_val_content"],
+			[info.parts_file, "_part_locs"],
+			[info.part_names_file, "_part_names"],
+		]
+		return info

+ 9 - 0
scripts/info_files/info.yml

@@ -96,6 +96,11 @@ DATASETS:
     annotations: "2019"
     n_classes: 1010
 
+  INAT18:         &inat18
+    folder: inat
+    annotations: "2018"
+    n_classes: 8142
+
   INAT19_MINI:    &inat19_mini
     <<: *inat19
     annotations: "2019_small"
@@ -202,6 +207,10 @@ PARTS:
     <<: *flowers
     <<: *parts_global
 
+  INAT18_GLOBAL:
+    <<: *inat18
+    <<: *parts_global
+
   INAT19_GLOBAL:
     <<: *inat19
     <<: *parts_global