tensorbay.label.catalog

The implementation of the TensorBay catalog.

class tensorbay.label.catalog.Catalog[source]

Bases: tensorbay.utility.repr.ReprMixin, tensorbay.utility.attr.AttrsMixin

This class defines the concept of catalog.

Catalog is used to describe the types of labels contained in a DatasetBase and all the optional values of the label contents.

A Catalog contains one or several SubcatalogBase, corresponding to different types of labels. Each of the SubcatalogBase contains the features, fields and the specific definitions of the labels.

Examples

>>> from tensorbay.utility import NameList
>>> from tensorbay.label import ClassificationSubcatalog, CategoryInfo
>>> classification_subcatalog = ClassificationSubcatalog()
>>> categories = NameList()
>>> categories.append(CategoryInfo("example"))
>>> classification_subcatalog.categories = categories
>>> catalog = Catalog()
>>> catalog.classification = classification_subcatalog
>>> catalog
Catalog(
  (classification): ClassificationSubcatalog(
    (categories): NameList [...]
  )
)
classmethod loads(contents)[source]

Load a Catalog from a dict containing the catalog information.

Parameters

contents (Dict[str, Any]) – A dict containing all the information of the catalog.

Returns

The loaded Catalog object.

Return type

tensorbay.label.catalog._T

Examples

>>> contents = {
...     "CLASSIFICATION": {
...         "categories": [
...             {
...                 "name": "example",
...             }
...         ]
...     },
...     "KEYPOINTS2D": {
...         "keypoints": [
...             {
...                 "number": 5,
...             }
...         ]
...     },
... }
>>> Catalog.loads(contents)
Catalog(
  (classification): ClassificationSubcatalog(
    (categories): NameList [...]
  ),
  (keypoints2d): Keypoints2DSubcatalog(
    (is_tracking): False,
    (keypoints): [...]
  )
)
dumps()[source]

Dumps the catalog into a dict containing the information of all the subcatalog.

Returns

A dict containing all the subcatalog information with their label types as keys.

Return type

Dict[str, Any]

Examples

>>> # catalog is the instance initialized above.
>>> catalog.dumps()
{'CLASSIFICATION': {'categories': [{'name': 'example'}]}}