Browse Source

added part handling for inat annotations

Dimitri Korsch 6 years ago
parent
commit
42c0d718d5
3 changed files with 16 additions and 6 deletions
  1. 4 0
      nabirds/annotations/base.py
  2. 0 4
      nabirds/annotations/cars.py
  3. 12 2
      nabirds/annotations/inat.py

+ 4 - 0
nabirds/annotations/base.py

@@ -102,6 +102,10 @@ class BaseAnnotations(abc.ABC):
 		logging.debug("Final kwargs: {}".format(new_opts))
 		return new_opts
 
+	@property
+	def has_parts(self):
+		return hasattr(self, "_part_locs") and self._part_locs is not None
+
 	@property
 	@abc.abstractmethod
 	def meta(self):

+ 0 - 4
nabirds/annotations/cars.py

@@ -43,10 +43,6 @@ 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 = {}
 

+ 12 - 2
nabirds/annotations/inat.py

@@ -20,21 +20,27 @@ class INAT19_Annotations(BaseAnnotations):
 			# 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"),
+			bounding_box_dtype=np.dtype([(v, np.int32) for v in "xywh"]),
 		)
 
 		info.structure = [
 			[info.content, "_content"],
 			[info.val_content, "_val_content"],
+			[info.parts_file, "_part_locs"],
 		]
 		return info
 
 	def read_content(self, json_file, attr):
+		if not json_file.endswith(".json"):
+			return super(INAT19_Annotations, self).read_content(json_file, attr)
 		with self._open(json_file) as f:
 			content = json.load(f)
 			setattr(self, attr, content)
 
-	def parts(self, uuids):
+	def parts(self, *args, **kwargs):
+		if self.has_parts:
+			return super(INAT19_Annotations, self).parts(*args, **kwargs)
 		return None
 
 	def bounding_box(self, uuid):
@@ -49,6 +55,10 @@ class INAT19_Annotations(BaseAnnotations):
 
 	def _load_parts(self):
 		self.part_names = {}
+
+		# load only if present
+		if self.has_parts:
+			super(INAT19_Annotations, self)._load_parts()
 		self._load_bounding_boxes()
 
 	def _load_split(self):