tensorbay.label.label_box

LabeledBox2D ,LabeledBox3D, Box2DSubcatalog, Box3DSubcatalog.

Box2DSubcatalog defines the subcatalog for 2D box type of labels.

LabeledBox2D is the 2D bounding box type of label, which is often used for CV tasks such as object detection.

Box3DSubcatalog defines the subcatalog for 3D box type of labels.

LabeledBox3D is the 3D bounding box type of label, which is often used for object detection in 3D point cloud.

class tensorbay.label.label_box.Box2DSubcatalog(is_tracking: bool = False)[source]

Bases: tensorbay.label.basic.SubcatalogBase, tensorbay.label.supports.IsTrackingMixin, tensorbay.label.supports.CategoriesMixin, tensorbay.label.supports.AttributesMixin

This class defines the subcatalog for 2D box type of labels.

Parameters

is_tracking – A boolean value indicates whether the corresponding subcatalog contains tracking information.

description

The description of the entire 2D box subcatalog.

Type

str

categories

All the possible categories in the corresponding dataset stored in a NameList with the category names as keys and the CategoryInfo as values.

Type

tensorbay.utility.name.NameList[tensorbay.label.supports.CategoryInfo]

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 the AttributeInfo as values.

Type

tensorbay.utility.name.NameList[tensorbay.label.attributes.AttributeInfo]

is_tracking

Whether the Subcatalog contains tracking information.

Type

bool

Examples

Initialization Method 1: Init from Box2DSubcatalog.loads() method.

>>> catalog = {
...     "BOX2D": {
...         "isTracking": True,
...         "categoryDelimiter": ".",
...         "categories": [{"name": "0"}, {"name": "1"}],
...         "attributes": [{"name": "gender", "enum": ["male", "female"]}],
...     }
... }
>>> Box2DSubcatalog.loads(catalog["BOX2D"])
Box2DSubcatalog(
  (is_tracking): True,
  (category_delimiter): '.',
  (categories): NameList [...],
  (attributes): NameList [...]
)

Initialization Method 2: Init an empty Box2DSubcatalog and then add the attributes.

>>> from tensorbay.utility import NameList
>>> from tensorbay.label import CategoryInfo, AttributeInfo
>>> categories = NameList()
>>> categories.append(CategoryInfo("a"))
>>> attributes = NameList()
>>> attributes.append(AttributeInfo("gender", enum=["female", "male"]))
>>> box2d_subcatalog = Box2DSubcatalog()
>>> box2d_subcatalog.is_tracking = True
>>> box2d_subcatalog.category_delimiter = "."
>>> box2d_subcatalog.categories = categories
>>> box2d_subcatalog.attributes = attributes
>>> box2d_subcatalog
Box2DSubcatalog(
  (is_tracking): True,
  (category_delimiter): '.',
  (categories): NameList [...],
  (attributes): NameList [...]
)
class tensorbay.label.label_box.LabeledBox2D(xmin: float, ymin: float, xmax: float, ymax: float, *, category: Optional[str] = None, attributes: Optional[Dict[str, Any]] = None, instance: Optional[str] = None)[source]

Bases: tensorbay.utility.user.UserSequence[float]

This class defines the concept of 2D bounding box label.

LabeledBox2D is the 2D bounding box type of label, which is often used for CV tasks such as object detection.

Parameters
  • xmin – The x coordinate of the top-left vertex of the labeled 2D box.

  • ymin – The y coordinate of the top-left vertex of the labeled 2D box.

  • xmax – The x coordinate of the bottom-right vertex of the labeled 2D box.

  • ymax – The y coordinate of the bottom-right vertex of the labeled 2D box.

  • category – The category of the label.

  • attributes – The attributs of the label.

  • instance – The instance id 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]]]]

instance

The instance id of the label.

Type

str

Examples

>>> xmin, ymin, xmax, ymax = 1, 2, 4, 4
>>> LabeledBox2D(
...     xmin,
...     ymin,
...     xmax,
...     ymax,
...     category="example",
...     attributes={"attr": "a"},
...     instance="12345",
... )
LabeledBox2D(1, 2, 4, 4)(
  (category): 'example',
  (attributes): {...},
  (instance): '12345'
)
classmethod from_xywh(x: float, y: float, width: float, height: float, *, category: Optional[str] = None, attributes: Optional[Dict[str, Any]] = None, instance: Optional[str] = None) tensorbay.label.label_box._T[source]

Create a LabeledBox2D instance from the top-left vertex, the width and height.

Parameters
  • x – X coordinate of the top left vertex of the box.

  • y – Y coordinate of the top left vertex of the box.

  • width – Length of the box along the x axis.

  • height – Length of the box along the y axis.

  • category – The category of the label.

  • attributes – The attributs of the label.

  • instance – The instance id of the label.

Returns

The created LabeledBox2D instance.

Examples

>>> x, y, width, height = 1, 2, 3, 4
>>> LabeledBox2D.from_xywh(
...     x,
...     y,
...     width,
...     height,
...     category="example",
...     attributes={"key": "value"},
...     instance="12345",
... )
LabeledBox2D(1, 2, 4, 6)(
  (category): 'example',
  (attributes): {...},
  (instance): '12345'
)
classmethod loads(contents: Dict[str, Any]) tensorbay.label.label_box._T[source]

Loads a LabeledBox2D from a dict containing the information of the label.

Parameters

contents – A dict containing the information of the 2D bounding box label.

Returns

The loaded LabeledBox2D object.

Examples

>>> contents = {
...     "box2d": {"xmin": 1, "ymin": 2, "xmax": 5, "ymax": 8},
...     "category": "example",
...     "attributes": {"key": "value"},
...     "instance": "12345",
... }
>>> LabeledBox2D.loads(contents)
LabeledBox2D(1, 2, 5, 8)(
  (category): 'example',
  (attributes): {...},
  (instance): '12345'
)
dumps() Dict[str, Any][source]

Dumps the current 2D bounding box label into a dict.

Returns

A dict containing all the information of the 2D box label.

Examples

>>> xmin, ymin, xmax, ymax = 1, 2, 4, 4
>>> labelbox2d = LabeledBox2D(
...     xmin,
...     ymin,
...     xmax,
...     ymax,
...     category="example",
...     attributes={"attr": "a"},
...     instance="12345",
... )
>>> labelbox2d.dumps()
{
    'category': 'example',
    'attributes': {'attr': 'a'},
    'instance': '12345',
    'box2d': {'xmin': 1, 'ymin': 2, 'xmax': 4, 'ymax': 4},
}
class tensorbay.label.label_box.Box3DSubcatalog(is_tracking: bool = False)[source]

Bases: tensorbay.label.basic.SubcatalogBase, tensorbay.label.supports.IsTrackingMixin, tensorbay.label.supports.CategoriesMixin, tensorbay.label.supports.AttributesMixin

This class defines the subcatalog for 3D box type of labels.

Parameters

is_tracking – A boolean value indicates whether the corresponding subcatalog contains tracking information.

description

The description of the entire 3D box subcatalog.

Type

str

categories

All the possible categories in the corresponding dataset stored in a NameList with the category names as keys and the CategoryInfo as values.

Type

tensorbay.utility.name.NameList[tensorbay.label.supports.CategoryInfo]

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 the AttributeInfo as values.

Type

tensorbay.utility.name.NameList[tensorbay.label.attributes.AttributeInfo]

is_tracking

Whether the Subcatalog contains tracking information.

Type

bool

Examples

Initialization Method 1: Init from Box3DSubcatalog.loads() method.

>>> catalog = {
...     "BOX3D": {
...         "isTracking": True,
...         "categoryDelimiter": ".",
...         "categories": [{"name": "0"}, {"name": "1"}],
...         "attributes": [{"name": "gender", "enum": ["male", "female"]}],
...     }
... }
>>> Box3DSubcatalog.loads(catalog["BOX3D"])
Box3DSubcatalog(
  (is_tracking): True,
  (category_delimiter): '.',
  (categories): NameList [...],
  (attributes): NameList [...]
)

Initialization Method 2: Init an empty Box3DSubcatalog and then add the attributes.

>>> from tensorbay.utility import NameList
>>> from tensorbay.label import CategoryInfo, AttributeInfo
>>> categories = NameList()
>>> categories.append(CategoryInfo("a"))
>>> attributes = NameList()
>>> attributes.append(AttributeInfo("gender", enum=["female", "male"]))
>>> box3d_subcatalog = Box3DSubcatalog()
>>> box3d_subcatalog.is_tracking = True
>>> box3d_subcatalog.category_delimiter = "."
>>> box3d_subcatalog.categories = categories
>>> box3d_subcatalog.attributes = attributes
>>> box3d_subcatalog
Box3DSubcatalog(
  (is_tracking): True,
  (category_delimiter): '.',
  (categories): NameList [...],
  (attributes): NameList [...]
)
class tensorbay.label.label_box.LabeledBox3D(size: Iterable[float], translation: Iterable[float] = (0, 0, 0), rotation: Union[Iterable[float], quaternion.quaternion] = (1, 0, 0, 0), *, transform_matrix: Optional[Union[Sequence[Sequence[float]], numpy.ndarray]] = None, category: Optional[str] = None, attributes: Optional[Dict[str, Any]] = None, instance: Optional[str] = None)[source]

Bases: tensorbay.label.basic._LabelBase, tensorbay.geometry.box.Box3D

This class defines the concept of 3D bounding box label.

LabeledBox3D is the 3D bounding box type of label, which is often used for object detection in 3D point cloud.

Parameters
  • size – Size of the 3D bounding box label in a sequence of [x, y, z].

  • translation – Translation of the 3D bounding box label in a sequence of [x, y, z].

  • rotation – Rotation of the 3D bounding box label in a sequence of [w, x, y, z] or a numpy quaternion object.

  • transform_matrix – A 4x4 or 3x4 transformation matrix.

  • category – Category of the 3D bounding box label.

  • attributes – Attributs of the 3D bounding box label.

  • instance – The instance id of the 3D bounding box 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]]]]

instance

The instance id of the label.

Type

str

size

The size of the 3D bounding box.

transform

The transform of the 3D bounding box.

Examples

>>> LabeledBox3D(
...     size=[1, 2, 3],
...     translation=(1, 2, 3),
...     rotation=(0, 1, 0, 0),
...     category="example",
...     attributes={"key": "value"},
...     instance="12345",
... )
LabeledBox3D(
  (size): Vector3D(1, 2, 3),
  (translation): Vector3D(1, 2, 3),
  (rotation): quaternion(0, 1, 0, 0),
  (category): 'example',
  (attributes): {...},
  (instance): '12345'
)
classmethod loads(contents: Dict[str, Any]) tensorbay.label.label_box._T[source]

Loads a LabeledBox3D from a dict containing the information of the label.

Parameters

contents – A dict containing the information of the 3D bounding box label.

Returns

The loaded LabeledBox3D object.

Examples

>>> contents = {
...     "box3d": {
...         "size": {"x": 1, "y": 2, "z": 3},
...         "translation": {"x": 1, "y": 2, "z": 3},
...         "rotation": {"w": 1, "x": 0, "y": 0, "z": 0},
...     },
...     "category": "test",
...     "attributes": {"key": "value"},
...     "instance": "12345",
... }
>>> LabeledBox3D.loads(contents)
LabeledBox3D(
  (size): Vector3D(1, 2, 3),
  (translation): Vector3D(1, 2, 3),
  (rotation): quaternion(1, 0, 0, 0),
  (category): 'test',
  (attributes): {...},
  (instance): '12345'
)
dumps() Dict[str, Any][source]

Dumps the current 3D bounding box label into a dict.

Returns

A dict containing all the information of the 3D bounding box label.

Examples

>>> labeledbox3d = LabeledBox3D(
...     size=[1, 2, 3],
...     translation=(1, 2, 3),
...     rotation=(0, 1, 0, 0),
...     category="example",
...     attributes={"key": "value"},
...     instance="12345",
... )
>>> labeledbox3d.dumps()
{
    'category': 'example',
    'attributes': {'key': 'value'},
    'instance': '12345',
    'box3d': {
        'translation': {'x': 1, 'y': 2, 'z': 3},
        'rotation': {'w': 0.0, 'x': 1.0, 'y': 0.0, 'z': 0.0},
        'size': {'x': 1, 'y': 2, 'z': 3},
    },
}