tensorbay.label.label_classification
Classification.
ClassificationSubcatalog
defines the subcatalog for classification type of labels.
Classification
defines the concept of classification label,
which can apply to different types of data, such as images and texts.
- class tensorbay.label.label_classification.ClassificationSubcatalog(description='')[source]
Bases:
tensorbay.label.basic.SubcatalogBase
,tensorbay.label.supports.CategoriesMixin
,tensorbay.label.supports.AttributesMixin
This class defines the subcatalog for classification type of labels.
- Parameters
description (str) –
- Return type
None
- description
The description of the entire classification subcatalog.
- Type
str
- categories
All the possible categories in the corresponding dataset stored in a
NameList
with the category names as keys and theCategoryInfo
as values.
- category_delimiter
The delimiter in category values indicating parent-child relationship.
- Type
str
- attributes
All the possible attributes in the corresponding dataset stored in a
NameList
with the attribute names as keys and theAttributeInfo
as values.
Examples
Initialization Method 1: Init from
ClassificationSubcatalog.loads()
method.>>> catalog = { ... "CLASSIFICATION": { ... "categoryDelimiter": ".", ... "categories": [ ... {"name": "a"}, ... {"name": "b"}, ... ], ... "attributes": [{"name": "gender", "enum": ["male", "female"]}], ... } ... } >>> ClassificationSubcatalog.loads(catalog["CLASSIFICATION"]) ClassificationSubcatalog( (category_delimiter): '.', (categories): NameList [...], (attributes): NameList [...] )
Initialization Method 2: Init an empty ClassificationSubcatalog and then add the attributes.
>>> from tensorbay.utility import NameList >>> from tensorbay.label import CategoryInfo, AttributeInfo, KeypointsInfo >>> categories = NameList() >>> categories.append(CategoryInfo("a")) >>> attributes = NameList() >>> attributes.append(AttributeInfo("gender", enum=["female", "male"])) >>> classification_subcatalog = ClassificationSubcatalog() >>> classification_subcatalog.category_delimiter = "." >>> classification_subcatalog.categories = categories >>> classification_subcatalog.attributes = attributes >>> classification_subcatalog ClassificationSubcatalog( (category_delimiter): '.', (categories): NameList [...], (attributes): NameList [...] )
- class tensorbay.label.label_classification.Classification(category=None, attributes=None)[source]
Bases:
tensorbay.label.basic._LabelBase
This class defines the concept of classification label.
Classification
is the classification type of label, which applies to different types of data, such as images and texts.- Parameters
category (str) – The category of the label.
attributes (Dict[str, Union[str, int, float, bool, List[Union[str, int, float, bool]]]]) – The attributes of the label.
- category
The category of the label.
- Type
str
- attributes
The attributes of the label.
- Type
Dict[str, Union[str, int, float, bool, List[Union[str, int, float, bool]]]]
Examples
>>> Classification(category="example", attributes={"attr": "a"}) Classification( (category): 'example', (attributes): {...} )
- classmethod loads(contents)[source]
Loads a Classification label from a dict containing the label information.
- Parameters
contents (Dict[str, Any]) – A dict containing the information of the classification label.
- Returns
The loaded
Classification
object.- Return type
tensorbay.label.label_classification._T
Examples
>>> contents = {"category": "example", "attributes": {"key": "value"}} >>> Classification.loads(contents) Classification( (category): 'example', (attributes): {...} )