18 from __future__
import annotations
20 from typing
import Optional, List, Dict, Set
26 from ....codable
import Codable, KeyDescriptor
32 Image Dataset class metadata
37 list of all uuids connected to this class
48 def __init__(self, label: Optional[str] =
None, color: Optional[str] =
None):
55 self.
classIdsclassIds = [uuid.uuid4()]
56 self.
labellabel = label
57 self.
colorcolor = color
60 def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
61 descriptors = super()._keyDescriptors()
69 def generate(cls, labels: Set[str]) -> ImageDatasetClasses:
71 Generates list of Coretex classes based on provided
77 list of labels (class names)
81 ImageDatasetClasses -> list of ImageDatasetClass (Coretex class metadata) objects
85 >>> from coretex import ImageDatasetClass
87 >>> labels = {"car", "bicycle"}
88 >>> imgDatasetClasses = ImageDatasetClass.generate(labels)
92 classIds = [UUID("81add001-1c9c-4949-8b73-3599f1d0de9d")],
97 classIds = [UUID("d710019b-f28f-40ab-aa65-e13df949beff")],
104 colors: Set[str] = set()
106 while len(colors) != len(labels):
107 color = f
'#{"%06x" % random.randint(0, 0xFFFFFF)}'
111 [cls(label, color)
for label, color
in zip(labels, colors)]
118 List of Image Dataset class metadata
123 list of the classes names
127 def labels(self) -> List[str]:
128 labels = [element.label
for element
in self]
133 def classById(self, classId: UUID) -> Optional[ImageDatasetClass]:
135 Retrieves a Image dataset class based on provided ID
144 Optional[ImageDatasetClasses] -> fetched class if provided ID
145 is found in list of class IDs, None otherwise
149 >>> from coretex import ImageDataset
151 >>> dataset = ImageDataset.fetchById(1023)
152 >>> classObj = dataset.classes.classById(UUID("d710019b-f28f-40ab-aa65-e13df949beff"))
154 >>> if classObj is not None:
155 print(classObj.classIds)
156 print(classObj.label)
157 print(classObj.color)
158 UUID("d710019b-f28f-40ab-aa65-e13df949beff")
164 for other
in element.classIds:
165 if str(classId) == str(other):
172 Retrieves a Image dataset class based on provided label
181 Optional[ImageDatasetClasses] -> fetched class if provided label
182 is found in list of class labels, None otherwise
186 if element.label == label:
193 Retrieves a label ID based on provided class ID
202 Optional[int] -> label ID if provided class ID
203 is found in list of class IDs, None otherwise
207 >>> from coretex import ImageDataset
209 >>> dataset = ImageDataset.fetchById(1023)
210 >>> labelId = dataset.classes.labelIdForClassId(UUID("d710019b-f28f-40ab-aa65-e13df949beff"))
221 return self.
labelslabels.index(clazz.label)
227 Retrieves a label ID based on provided ImageDatasetClass object
231 clazz : ImageDatasetClass
232 Image Dataset class metadata object
236 Optional[int] -> label ID if provided class exists
237 in a list of ImageDataset classes otherwise None
241 >>> from coretex import ImageDatasetClass
243 >>> dataset = ImageDataset.fetchById(1023)
244 >>> labelId = dataset.classes.labelIdForClass(dataset.classes[0])
251 def exclude(self, excludedClasses: List[str]) ->
None:
253 Excludes classes that are provided in excludedClasses list
257 excludedClasses : List[str]
258 list of classes that will be excluded
262 element
for element
in self
263 if element.label
not in excludedClasses