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

added a HED dataset. Added meta info about NAB with parts

Dimitri Korsch 6 жил өмнө
parent
commit
384050368a

+ 2 - 0
nabirds/annotations/__init__.py

@@ -3,6 +3,7 @@ from .nab import NAB_Annotations
 from .cars import CARS_Annotations
 from .inat import INAT19_Annotations
 from .flowers import FLOWERS_Annotations
+from .hed import HED_Annotations
 
 from .base import BaseAnnotations
 
@@ -14,6 +15,7 @@ class AnnotationType(BaseChoiceType):
 	NAB = NAB_Annotations
 	CARS = CARS_Annotations
 	FLOWERS = FLOWERS_Annotations
+	HED = HED_Annotations
 
 	INAT19 = INAT19_Annotations
 	INAT19_MINI = partial(INAT19_Annotations)

+ 56 - 0
nabirds/annotations/hed.py

@@ -0,0 +1,56 @@
+import numpy as np
+import simplejson as json
+
+from os.path import join
+
+from nabirds.utils import _MetaInfo
+
+from .base import BaseAnnotations, BBoxMixin
+
+class HED_Annotations(BaseAnnotations, BBoxMixin):
+
+	name="HED"
+
+	@property
+	def meta(self):
+		info = _MetaInfo(
+			images_folder="images",
+
+			images_file="images.txt",
+			labels_file="labels.txt",
+			split_file="tr_ID.txt",
+			# 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.images_file, "_images"],
+			[info.labels_file, "labels"],
+			[info.split_file, "_split"],
+		]
+		return info
+
+	def parts(self, *args, **kwargs):
+		if self.has_parts:
+			return super(HED_Annotations, self).parts(*args, **kwargs)
+		return None
+
+	def _load_bounding_boxes(self):
+		self.bounding_boxes = np.zeros(len(self.uuids),
+			dtype=self.meta.bounding_box_dtype)
+
+		for i in range(len(self.uuids)):
+			self.bounding_boxes[i]["w"] = 224
+			self.bounding_boxes[i]["h"] = 224
+
+	def _load_parts(self):
+		self.part_names = {}
+
+		# load only if present
+		if self.has_parts:
+			super(HED_Annotations, self)._load_parts()
+
+		self._load_bounding_boxes()

+ 2 - 2
scripts/display.py

@@ -59,8 +59,8 @@ def main(args):
 		axs[0].axis("off")
 		axs[0].set_title("Visible Parts")
 		axs[0].imshow(im)
-		if not args.crop_to_bb:
-			data.plot_bounding_box(i, axs[0])
+		# if not args.crop_to_bb:
+		# 	data.plot_bounding_box(i, axs[0])
 		parts.plot(im=im, ax=axs[0], ratio=data.ratio)
 
 		axs[1].axis("off")

+ 22 - 0
scripts/info_files/info.yml

@@ -83,6 +83,12 @@ DATASETS:
     <<: *inat19
     annotations: "2019_test"
 
+
+  HED:         &hed
+    folder: medical/HED
+    annotations: "patches224x224"
+    n_classes: 2
+
 ############ Existing Part Annotations and Part Features
 ### feature file name composition:
 # ${BASE_DIR}/${DATA_DIR}/${DATASETS:folder}/${PART_TYPES:annotations}/features
@@ -163,6 +169,10 @@ PARTS:
     <<: *parts_global
     feature_suffix: .test
 
+  HED_GLOBAL:
+    <<: *hed
+    <<: *parts_global
+
   #### With Parts Annotations
 
 
@@ -206,6 +216,18 @@ PARTS:
     <<: *nabirds
     <<: *parts_gt
 
+  NAB_L1_pred:
+    <<: *nabirds
+    <<: *parts_l1p
+    annotations: L1_pred
+    rescale_size: !!int 427
+
+  NAB_L1_full:
+    <<: *nabirds
+    <<: *parts_l1f
+    annotations: L1_full
+    rescale_size: !!int 427
+
 
   ####################################
   # Stanford Cars