|
@@ -86,10 +86,10 @@ class BaseAnnotations(abc.ABC):
|
|
|
return self.image_path(fname)
|
|
|
|
|
|
def label(self, uuid):
|
|
|
- return self.labels[self.uuid_to_idx[uuid]]
|
|
|
+ return self.labels[self.uuid_to_idx[uuid]].copy()
|
|
|
|
|
|
def parts(self, uuid):
|
|
|
- return self.part_locs[self.uuid_to_idx[uuid]]
|
|
|
+ return self.part_locs[self.uuid_to_idx[uuid]].copy()
|
|
|
|
|
|
|
|
|
def _uuids(self, split):
|
|
@@ -134,8 +134,11 @@ class CUB_Annotations(BaseAnnotations):
|
|
|
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 = [
|
|
@@ -144,6 +147,7 @@ class CUB_Annotations(BaseAnnotations):
|
|
|
[info.split_file, "_split"],
|
|
|
[info.parts_file, "_part_locs"],
|
|
|
[info.part_names_file, "_part_names"],
|
|
|
+ [info.bounding_boxes, "_bounding_boxes"],
|
|
|
]
|
|
|
return info
|
|
|
|
|
@@ -163,4 +167,20 @@ class CUB_Annotations(BaseAnnotations):
|
|
|
# set part idxs from 1-idxs to 0-idxs
|
|
|
self.part_locs[..., 0] -= 1
|
|
|
|
|
|
+ self._load_bounding_boxes()
|
|
|
+
|
|
|
+ def _load_bounding_boxes(self):
|
|
|
+ assert self._bounding_boxes is not None, "Bouding boxes were not loaded!"
|
|
|
+
|
|
|
+ uuid_to_bbox = {}
|
|
|
+ for content in [i.split() for i in self._bounding_boxes]:
|
|
|
+ uuid, bbox = content[0], content[1:]
|
|
|
+ uuid_to_bbox[uuid] = [float(i) for i in bbox]
|
|
|
+
|
|
|
+ self.bounding_boxes = np.array(
|
|
|
+ [tuple(uuid_to_bbox[uuid]) for uuid in self.uuids],
|
|
|
+ dtype=self.meta.bounding_box_dtype)
|
|
|
+
|
|
|
|
|
|
+ def bounding_box(self, uuid):
|
|
|
+ return self.bounding_boxes[self.uuid_to_idx[uuid]].copy()
|