tensorbay.label.label_polygon

LabeledPolygon, PolygonSubcatalog.

PolygonSubcatalog defines the subcatalog for polygon type of labels.

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

class tensorbay.label.label_polygon.PolygonSubcatalog(is_tracking: bool = False)[source]

Bases: tensorbay.utility.type.TypeMixin[tensorbay.label.basic.LabelType], tensorbay.utility.repr.ReprMixin, tensorbay.utility.attr.AttrsMixin

This class defines the subcatalog for polygon type of labels.

Parameters

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

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.LabeledPolygon(points: Optional[Iterable[Iterable[float]]] = None, *, category: Optional[str] = None, attributes: Optional[Dict[str, Any]] = None, instance: Optional[str] = None)[source]

Bases: tensorbay.utility.attr.AttrsMixin, tensorbay.utility.type.TypeMixin[tensorbay.label.basic.LabelType], tensorbay.utility.repr.ReprMixin

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: Dict[str, Any]) tensorbay.label.label_polygon._T[source]

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

Parameters

contents – A dict containing the information of the polygon label.

Returns

The loaded LabeledPolygon object.

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() Dict[str, Any][source]

Dumps the current polygon label into a dict.

Returns

A dict containing all the information of the polygon label.

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}],
}