Browse Source

some changes in annotation reading

Dimitri Korsch 6 years ago
parent
commit
ca15d76693

+ 2 - 0
nabirds/annotations/__init__.py

@@ -4,11 +4,13 @@ from .cars import CARS_Annotations
 from .inat import INAT19_Annotations
 
 from cvargparse.utils import BaseChoiceType
+from functools import partial
 
 class AnnotationType(BaseChoiceType):
 	CUB200 = CUB_Annotations
 	NAB = NAB_Annotations
 	CARS = CARS_Annotations
 	INAT19 = INAT19_Annotations
+	INAT19_MINI = partial(INAT19_Annotations)
 
 	Default = CUB200

+ 1 - 0
nabirds/annotations/base.py

@@ -141,6 +141,7 @@ class BaseAnnotations(abc.ABC):
 		for content in [i.split() for i in self._part_locs]:
 			uuid_to_parts[content[0]].append([float(i) for i in content[1:]])
 
+		uuid_to_parts = dict(uuid_to_parts)
 		self.part_locs = np.stack([uuid_to_parts[uuid] for uuid in self.uuids]).astype(int)
 
 		if hasattr(self, "_part_names") and self._part_names is not None:

+ 15 - 0
nabirds/annotations/cars.py

@@ -18,12 +18,16 @@ class CARS_Annotations(BaseAnnotations):
 			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
@@ -39,8 +43,17 @@ class CARS_Annotations(BaseAnnotations):
 		self.train_split = np.array([uuid_to_split[uuid] for uuid in self.uuids], dtype=bool)
 		self.test_split = np.logical_not(self.train_split)
 
+	@property
+	def has_parts(self):
+		return self._part_locs is not None
+
 	def _load_parts(self):
 		self.part_names = {}
+
+		# load only if present
+		if self.has_parts:
+			super(CARS_Annotations, self)._load_parts()
+
 		self._load_bounding_boxes()
 
 	def _load_bounding_boxes(self):
@@ -56,6 +69,8 @@ class CARS_Annotations(BaseAnnotations):
 			dtype=self.meta.bounding_box_dtype)
 
 	def parts(self, *args, **kwargs):
+		if self.has_parts:
+			return super(CARS_Annotations, self).parts(*args, **kwargs)
 		return None
 
 	def bounding_box(self, uuid):

+ 1 - 1
scripts/display.py

@@ -49,7 +49,7 @@ def main(args):
 
 	start = max(args.start, 0)
 	n_images = min(args.n_images, len(data) - start)
-	idxs = range(start, max(start, start + n_images)
+	idxs = range(start, max(start, start + n_images))
 
 	for i in idxs:
 		im, parts, label = data[i]

+ 31 - 0
scripts/info_files/info.yml

@@ -65,6 +65,10 @@ DATASETS:
     annotations: "2019"
     n_classes: 1010
 
+  INAT19_MINI:    &inat19_mini
+    <<: *inat19
+    annotations: "2019_small"
+
 ############ Existing Part Annotations and Part Features
 ### feature file name composition:
 # ${BASE_DIR}/${DATA_DIR}/${DATASETS:folder}/${PART_TYPES:annotations}/features
@@ -127,6 +131,11 @@ PARTS:
     <<: *inat19
     <<: *parts_global
 
+  INAT19_MINI_GLOBAL:
+    <<: *inat19_mini
+    <<: *parts_global
+    feature_suffix: .mini
+
   #### No Parts Annotations
   CUB200_GLOBAL:
     <<: *cub200
@@ -162,3 +171,25 @@ PARTS:
     <<: *parts_l1f
 
 
+  CARS_L1_pred:
+    <<: *cars
+    <<: *parts_l1p
+    annotations: L1_pred
+
+  CARS_L1_full:
+    <<: *cars
+    <<: *parts_l1f
+    annotations: L1_full
+
+  INAT19_MINI_L1_pred:
+    <<: *inat19_mini
+    <<: *parts_l1p
+    annotations: 2019_small_L1_pred
+    feature_suffix: _5parts_L1_pred.mini
+
+  INAT19_MINI_L1_full:
+    <<: *inat19_mini
+    <<: *parts_l1f
+    feature_suffix: _5parts_L1_full.mini
+    annotations: 2019_small_L1_full
+