浏览代码

added birdsnap annotation class

Dimitri Korsch 5 年之前
父节点
当前提交
f507db70c9
共有 3 个文件被更改,包括 57 次插入0 次删除
  1. 2 0
      cvdatasets/annotations/__init__.py
  2. 46 0
      cvdatasets/annotations/impl/birdsnap.py
  3. 9 0
      scripts/info_files/info.yml

+ 2 - 0
cvdatasets/annotations/__init__.py

@@ -1,4 +1,5 @@
 from cvdatasets.annotations.impl.cub import CUB_Annotations
+from cvdatasets.annotations.impl.birdsnap import BSNAP_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
@@ -20,6 +21,7 @@ class AnnotationType(BaseChoiceType):
 	CUB200_2FOLD = partial(CUB_Annotations)
 	CUB200_GOOGLE = partial(CUB_Annotations)
 	CUB200_GOOGLE_SEM = partial(CUB_Annotations)
+	BIRDSNAP = BSNAP_Annotations
 	NAB = NAB_Annotations
 	CARS = CARS_Annotations
 	DOGS = DOGS_Annotations

+ 46 - 0
cvdatasets/annotations/impl/birdsnap.py

@@ -0,0 +1,46 @@
+import numpy as np
+
+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 BSNAP_Annotations(BBoxMixin, PartsMixin, BaseAnnotations):
+	name="BSNAP"
+
+	@property
+	def meta(self):
+		info = _MetaInfo(
+			images_folder="images",
+			images_file="images.txt",
+			labels_file="labels.txt",
+			split_file="tr_ID.txt",
+			# bounding_boxes="bounding_boxes.txt",
+			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.images_file, "_images"],
+			[info.labels_file, "labels"],
+			[info.split_file, "_split"],
+			# [info.parts_file, "_part_locs"],
+			# [info.part_names_file, "_part_names"],
+			# [info.bounding_boxes, "_bounding_boxes"],
+		]
+		return info
+
+	def load(self):
+		super(BSNAP_Annotations, self).load()
+		# set labels from [1..N] to [0..N-1]
+		self.labels -= 1
+
+		if self.has_parts:
+			# set part idxs from 1-idxs to 0-idxs
+			self.part_locs[..., 0] -= 1

+ 9 - 0
scripts/info_files/info.yml

@@ -76,6 +76,11 @@ DATASETS:
     annotations: "ORIGINAL"
     n_classes: 555
 
+  BIRDSNAP:         &birdsnap
+    folder: birds/birdsnap
+    annotations: "RESIZED"
+    n_classes: 500
+
   CARS:         &cars
     folder: cars
     annotations: "ORIGINAL"
@@ -203,6 +208,10 @@ PARTS:
     <<: *nabirds
     <<: *parts_global
 
+  BIRDSNAP_GLOBAL:
+    <<: *birdsnap
+    <<: *parts_global
+
   FLOWERS_GLOBAL:
     <<: *flowers
     <<: *parts_global