Explorar el Código

added possibility to set part annotations

Dimitri Korsch hace 2 años
padre
commit
c265c45396
Se han modificado 1 ficheros con 14 adiciones y 1 borrados
  1. 14 1
      cvdatasets/annotation/mixins/parts_mixin.py

+ 14 - 1
cvdatasets/annotation/mixins/parts_mixin.py

@@ -95,7 +95,7 @@ class PartsMixin(abc.ABC):
 
 		uuid_to_parts = dict(uuid_to_parts)
 		self.part_locs = np.stack([
-			uuid_to_parts[uuid] for uuid in self.uuids]).astype(int)
+			uuid_to_parts[uuid] for uuid in self.uuids]).astype(np.int32)
 
 		if self.has_part_names:
 			self._parse_part_names()
@@ -114,3 +114,16 @@ class PartsMixin(abc.ABC):
 			return self.part_locs[self.uuid_to_idx[uuid]].copy()
 
 		return None
+
+	def set_parts(self, uuid, parts):
+		if not self.has_parts:
+			shape = (len(self.uuids),) + parts.shape
+			n_parts, _ = parts.shape
+			self.part_locs = np.full(shape, -1, dtype=np.int32)
+
+			for locs in self.part_locs:
+				locs[:, 0] = np.arange(len(locs))
+			self.files.part_locs = True
+
+		self.part_locs[self.uuid_to_idx[uuid]] = parts
+