def generate_label_schema(not_empty_labels, multilabel=False): assert len(not_empty_labels) > 1 label_schema = LabelSchemaEntity() if multilabel: emptylabel = LabelEntity(name="Empty label", is_empty=True, domain=Domain.CLASSIFICATION) empty_group = LabelGroup(name="empty", labels=[emptylabel], group_type=LabelGroupType.EMPTY_LABEL) single_groups = [] for label in not_empty_labels: single_groups.append( LabelGroup(name=label.name, labels=[label], group_type=LabelGroupType.EXCLUSIVE)) label_schema.add_group(single_groups[-1]) label_schema.add_group(empty_group, exclusive_with=single_groups) else: main_group = LabelGroup(name="labels", labels=not_empty_labels, group_type=LabelGroupType.EXCLUSIVE) label_schema.add_group(main_group) return label_schema
def add_hierarchy( self, label_schema: LabelSchemaEntity ) -> Tuple[LabelEntity, LabelEntity, LabelEntity]: """Adds children to flowering, no_plant and vegetative""" label_schema.add_group( LabelGroup( "plant_state", [self.flowering, self.no_plant, self.vegetative], LabelGroupType.EXCLUSIVE, )) flower_partial_visible = self.new_label_by_name( "flower_partial_visible") flower_fully_visible = self.new_label_by_name("flower_fully_visible") label_schema.add_group( LabelGroup( "flowering_state", [flower_fully_visible, flower_partial_visible], LabelGroupType.EXCLUSIVE, )) label_schema.add_child(self.flowering, flower_partial_visible) label_schema.add_child(self.flowering, flower_fully_visible) assert self.flowering == label_schema.get_parent( flower_partial_visible) assert label_schema.get_parent(self.no_plant) is None few_leaves = self.new_label_by_name("few_leaves") label_schema.add_group( LabelGroup("leaf_state", [few_leaves], LabelGroupType.EXCLUSIVE)) label_schema.add_child(self.vegetative, few_leaves) return few_leaves, flower_fully_visible, flower_partial_visible
def generate_label_schema(dataset, task_type): """ Generates label schema depending on task type. """ if task_type == TaskType.CLASSIFICATION and dataset.is_multilabel(): not_empty_labels = dataset.get_labels() assert len(not_empty_labels) > 1 label_schema = LabelSchemaEntity() empty_label = LabelEntity( name="Empty label", is_empty=True, domain=Domain.CLASSIFICATION ) empty_group = LabelGroup( name="empty", labels=[empty_label], group_type=LabelGroupType.EMPTY_LABEL ) single_groups = [] for label in not_empty_labels: single_groups.append( LabelGroup( name=label.name, labels=[label], group_type=LabelGroupType.EXCLUSIVE ) ) label_schema.add_group(single_groups[-1]) label_schema.add_group(empty_group, exclusive_with=single_groups) return label_schema if task_type == TaskType.ANOMALY_CLASSIFICATION: return LabelSchemaEntity.from_labels( [ LabelEntity( name="Normal", domain=Domain.ANOMALY_CLASSIFICATION, id=ID(0) ), LabelEntity( name="Anomalous", domain=Domain.ANOMALY_CLASSIFICATION, id=ID(1) ), ] ) return LabelSchemaEntity.from_labels(dataset.get_labels())