tensorbay.label.label_polygon#

The implementation of the TensorBay polygon label.

class tensorbay.label.label_polygon.PolygonSubcatalog(is_tracking=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 polygon type of labels.

Parameters

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

Return type

None

description#

The description of the entire polygon 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 PolygonSubcatalog.loads() method.

>>> catalog = {
...     "POLYGON": {
...         "isTracking": True,
...         "categories": [{"name": "0"}, {"name": "1"}],
...         "attributes": [{"name": "gender", "enum": ["male", "female"]}],
...     }
... }
>>> PolygonSubcatalog.loads(catalog["POLYGON"])
PolygonSubcatalog(
  (is_tracking): True,
  (categories): NameList [...],
  (attributes): NameList [...]
)

Initialization Method 2: Init an empty PolygonSubcatalog 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"]))
>>> polygon_subcatalog = PolygonSubcatalog()
>>> polygon_subcatalog.is_tracking = True
>>> polygon_subcatalog.categories = categories
>>> polygon_subcatalog.attributes = attributes
>>> polygon_subcatalog
PolygonSubcatalog(
  (is_tracking): True,
  (categories): NameList [...],
  (attributes): NameList [...]
)
class tensorbay.label.label_polygon.MultiPolygonSubcatalog(is_tracking=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 multiple polygon type of labels.

Parameters

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

Return type

None

description#

The description of the entire multiple polygon 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 MultiPolygonSubcatalog.loads() method.

>>> catalog = {
...     "MULTI_POLYGON": {
...         "isTracking": True,
...         "categories": [{"name": "0"}, {"name": "1"}],
...         "attributes": [{"name": "gender", "enum": ["male", "female"]}],
...     }
... }
>>> MultiPolygonSubcatalog.loads(catalog["MULTI_POLYGON"])
MultiPolygonSubcatalog(
  (is_tracking): True,
  (categories): NameList [...],
  (attributes): NameList [...]
)

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

>>> from tensorbay.label import CategoryInfo, AttributeInfo
>>> multi_polygon_subcatalog = MultiPolygonSubcatalog()
>>> multi_polygon_subcatalog.is_tracking = True
>>> multi_polygon_subcatalog.add_category("a")
>>> multi_polygon_subcatalog.add_attribute("gender", enum=["female", "male"])
>>> multi_polygon_subcatalog
MultiPolyline2DSubcatalog(
  (is_tracking): True,
  (categories): NameList [...],
  (attributes): NameList [...]
)
class tensorbay.label.label_polygon.RLESubcatalog(is_tracking=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 rle type of labels.

Parameters

is_tracking (bool) – A boolean value indicating whether the corresponding subcatalog contains tracking information.

Return type

None

description#

The description of the rle 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 RLESubcatalog.loads() method.

>>> catalog = {
...     "RLE": {
...         "isTracking": True,
...         "categories": [{"name": "0"}, {"name": "1"}],
...         "attributes": [{"name": "gender", "enum": ["male", "female"]}],
...     }
... }
>>> RLESubcatalog.loads(catalog["RLESubcatalog"])
RLESubcatalog(
  (is_tracking): True,
  (categories): NameList [...],
  (attributes): NameList [...]
)

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

>>> from tensorbay.label import CategoryInfo, AttributeInfo
>>> rle_subcatalog = RLESubcatalog()
>>> rle_subcatalog.is_tracking = True
>>> rle_subcatalog.add_category("a")
>>> rle_subcatalog.add_attribute("gender", enum=["female", "male"])
>>> rle_subcatalog
RLESubcatalog(
  (is_tracking): True,
  (categories): NameList [...],
  (attributes): NameList [...]
)
class tensorbay.label.label_polygon.LabeledPolygon(points=None, *, category=None, attributes=None, instance=None)[source]#

Bases: tensorbay.geometry.point_list.PointList2D[tensorbay.geometry.vector.Vector2D]

This class defines the concept of polygon label.

LabeledPolygon is the polygon type of label, which is often used for CV tasks such as semantic segmentation.

Parameters
  • points – A list of 2D points representing the vertexes of the polygon.

  • 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

>>> LabeledPolygon(
...     [(1, 2), (2, 3), (1, 3)],
...     category = "example",
...     attributes = {"key": "value"},
...     instance = "123",
... )
LabeledPolygon [
  Vector2D(1, 2),
  Vector2D(2, 3),
  Vector2D(1, 3)
](
  (category): 'example',
  (attributes): {...},
  (instance): '123'
)
classmethod loads(contents)[source]#

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

Parameters

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

Returns

The loaded LabeledPolygon object.

Return type

tensorbay.label.label_polygon._T

Examples

>>> contents = {
...     "polygon": [
...         {"x": 1, "y": 2},
...         {"x": 2, "y": 3},
...         {"x": 1, "y": 3},
...     ],
...     "category": "example",
...     "attributes": {"key": "value"},
...     "instance": "12345",
... }
>>> LabeledPolygon.loads(contents)
LabeledPolygon [
  Vector2D(1, 2),
  Vector2D(2, 3),
  Vector2D(1, 3)
](
  (category): 'example',
  (attributes): {...},
  (instance): '12345'
)
dumps()[source]#

Dumps the current polygon label into a dict.

Returns

A dict containing all the information of the polygon label.

Return type

Dict[str, Any]

Examples

>>> labeledpolygon = LabeledPolygon(
...     [(1, 2), (2, 3), (1, 3)],
...     category = "example",
...     attributes = {"key": "value"},
...     instance = "123",
... )
>>> labeledpolygon.dumps()
{
    'category': 'example',
    'attributes': {'key': 'value'},
    'instance': '123',
    'polygon': [{'x': 1, 'y': 2}, {'x': 2, 'y': 3}, {'x': 1, 'y': 3}],
}
class tensorbay.label.label_polygon.LabeledMultiPolygon(polygons=None, *, category=None, attributes=None, instance=None)[source]#

Bases: tensorbay.geometry.point_list.MultiPointList2D[tensorbay.geometry.polygon.Polygon]

This class defines the concept of multiple polygon label.

LabeledMultiPolygon is the multipolygon type of label, which is often used for CV tasks such as semantic segmentation.

Parameters
  • points – A list of 2D points representing the vertices of the polygon.

  • 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

>>> LabeledMultiPolygon(
...     [[(1.0, 2.0), (2.0, 3.0), (1.0, 3.0)], [(1.0, 4.0), (2.0, 3.0), (1.0, 8.0)]],
...     category = "example",
...     attributes = {"key": "value"},
...     instance = "12345",
... )
LabeledMultiPolygon [
    Polygon [...],
    Polygon [...]
    ](
      (category): 'example',
      (attributes): {...},
      (instance): '12345'
    )
classmethod loads(contents)[source]#

Loads a LabeledMultiPolygon from a list of dict containing the information of the label.

Parameters

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

Returns

The loaded LabeledMultiPolygon object.

Return type

tensorbay.label.label_polygon._T

Examples

>>> contents = {
...     "multiPolygon": [
...         [
...             {"x": 1.0, "y": 2.0},
...             {"x": 2.0, "y": 3.0},
...             {"x": 1.0, "y": 3.0},
...        ],
...         [{"x": 1.0, "y": 4.0}, {"x": 2.0, "y": 3.0}, {"x": 1.0, "y": 8.0}],
...     ],
...     "category": "example",
...     "attributes": {"key": "value"},
...     "instance": "12345",
... }
>>> LabeledMultiPolygon.loads(contents)
LabeledMultiPolygon [
  Polygon [...],
  Polygon [...]
](
  (category): 'example',
  (attributes): {...},
  (instance): '12345'
)
dumps()[source]#

Dumps the current multipolygon label into a dict.

Returns

A dict containing all the information of the multipolygon label.

Return type

Dict[str, Any]

Examples

>>> labeledmultipolygon = LabeledMultiPolygon(
...     [[(1, 2), (2, 3), (1, 3)],[(1, 2), (2, 3), (1, 3)]],
...     category = "example",
...     attributes = {"key": "value"},
...     instance = "123",
... )
>>> labeledmultipolygon.dumps()
{
    'category': 'example',
    'attributes': {'key': 'value'},
    'instance': '123',
    'multiPolygon': [
        [{'x': 1, 'y': 2}, {'x': 2, 'y': 3}, {'x': 1, 'y': 3}],
        [{"x": 1.0, "y": 4.0}, {"x": 2.0, "y": 3.0}, {"x": 1.0, "y": 8.0}]
    ]
}
class tensorbay.label.label_polygon.LabeledRLE(rle=None, *, category=None, attributes=None, instance=None)[source]#

Bases: tensorbay.utility.user.UserMutableSequence[int]

This class defines the concept of rle label.

LabeledRLE is the rle type of label, which is often used for CV tasks such as semantic segmentation.

Parameters
  • rle – A rle format mask.

  • 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

>>> LabeledRLE(
...     [272, 2, 4, 4, 2, 9],
...     category = "example",
...     attributes = {"key": "value"},
...     instance = "12345",
... )
LabeledRLE [
  272,
  2,
  ...
](
    (category): 'example',
    (attributes): {...},
    (instance): '12345'
)
classmethod loads(contents)[source]#

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

Parameters

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

Returns

The loaded LabeledRLE object.

Return type

tensorbay.label.label_polygon._T

Examples

>>> contents = {
...     "rle": [272, 2, 4, 4, 2, 9],
...     "category": "example",
...     "attributes": {"key": "value"},
...     "instance": "12345",
... }
>>> LabeledRLE.loads(contents)
LabeledRLE [
  272,
  2,
  ...
](
  (category): 'example',
  (attributes): {...},
  (instance): '12345'
)
dumps()[source]#

Dumps the current rle label into a dict.

Returns

A dict containing all the information of the rle label.

Return type

Dict[str, Any]

Examples

>>> labeled_rle = LabeledRLE(
...     [272, 2, 4, 4, 2, 9],
...     category = "example",
...     attributes = {"key": "value"},
...     instance = "123",
... )
>>> labeled_rle.dumps()
{
    'category': 'example',
    'attributes': {'key': 'value'},
    'instance': '123',
    'rle': [272, 2, 4, 4, 2, 9]
}