tensorbay.label.label_keypoints¶
The implementation of the TensorBay 2D keypoints label.
- class tensorbay.label.label_keypoints.Keypoints2DSubcatalog(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 2D keypoints 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 2D keypoints 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.
- is_tracking¶
Whether the Subcatalog contains tracking information.
- Type
bool
Examples
Initialization Method 1: Init from
Keypoints2DSubcatalog.loads()
method.>>> catalog = { ... "KEYPOINTS2D": { ... "isTracking": True, ... "categories": [{"name": "0"}, {"name": "1"}], ... "attributes": [{"name": "gender", "enum": ["male", "female"]}], ... "keypoints": [ ... { ... "number": 2, ... "names": ["L_shoulder", "R_Shoulder"], ... "skeleton": [(0, 1)], ... } ... ], ... } ... } >>> Keypoints2DSubcatalog.loads(catalog["KEYPOINTS2D"]) Keypoints2DSubcatalog( (is_tracking): True, (keypoints): [...], (categories): NameList [...], (attributes): NameList [...] )
Initialization Method 2: Init an empty Keypoints2DSubcatalog and then add the attributes.
>>> from tensorbay.label import CategoryInfo, AttributeInfo, KeypointsInfo >>> from tensorbay.utility import NameList >>> categories = NameList() >>> categories.append(CategoryInfo("a")) >>> attributes = NameList() >>> attributes.append(AttributeInfo("gender", enum=["female", "male"])) >>> keypoints2d_subcatalog = Keypoints2DSubcatalog() >>> keypoints2d_subcatalog.is_tracking = True >>> keypoints2d_subcatalog.categories = categories >>> keypoints2d_subcatalog.attributes = attributes >>> keypoints2d_subcatalog.add_keypoints( ... 2, ... names=["L_shoulder", "R_Shoulder"], ... skeleton=[(0,1)], ... visible="BINARY", ... parent_categories="shoulder", ... description="12345", ... ) >>> keypoints2d_subcatalog Keypoints2DSubcatalog( (is_tracking): True, (keypoints): [...], (categories): NameList [...], (attributes): NameList [...] )
- property keypoints: List[tensorbay.label.supports.KeypointsInfo]¶
Return the KeypointsInfo of the Subcatalog.
- Returns
A list of
KeypointsInfo
.
Examples
>>> keypoints2d_subcatalog = Keypoints2DSubcatalog() >>> keypoints2d_subcatalog.add_keypoints(2) >>> keypoints2d_subcatalog.keypoints [KeypointsInfo( (number): 2 )]
- add_keypoints(number, *, names=None, skeleton=None, visible=None, parent_categories=None, description='')[source]¶
Add a type of keypoints to the subcatalog.
- Parameters
number (int) – The number of keypoints.
names (Optional[Iterable[str]]) – All the names of keypoints.
skeleton (Optional[Iterable[Iterable[int]]]) – The skeleton of the keypoints indicating which keypoint should connect with another.
visible (Optional[str]) – The visible type of the keypoints, can only be ‘BINARY’ or ‘TERNARY’. It determines the range of the
Keypoint2D.v
.parent_categories (Union[None, str, Iterable[str]]) – The parent categories of the keypoints.
description (str) – The description of keypoints.
- Return type
None
Examples
>>> keypoints2d_subcatalog = Keypoints2DSubcatalog() >>> keypoints2d_subcatalog.add_keypoints( ... 2, ... names=["L_shoulder", "R_Shoulder"], ... skeleton=[(0,1)], ... visible="BINARY", ... parent_categories="shoulder", ... description="12345", ... ) >>> keypoints2d_subcatalog.keypoints [KeypointsInfo( (number): 2, (names): [...], (skeleton): [...], (visible): 'BINARY', (parent_categories): [...] )]
- dumps()[source]¶
Dumps all the information of the keypoints into a dict.
- Returns
A dict containing all the information of this Keypoints2DSubcatalog.
- Return type
Dict[str, Any]
Examples
>>> # keypoints2d_subcatalog is the instance initialized above. >>> keypoints2d_subcatalog.dumps() { 'isTracking': True, 'categories': [{'name': 'a'}], 'attributes': [{'name': 'gender', 'enum': ['female', 'male']}], 'keypoints': [ { 'number': 2, 'names': ['L_shoulder', 'R_Shoulder'], 'skeleton': [(0, 1)], } ] }
- class tensorbay.label.label_keypoints.LabeledKeypoints2D(keypoints=None, *, category=None, attributes=None, instance=None)[source]¶
Bases:
tensorbay.geometry.point_list.PointList2D
[tensorbay.geometry.keypoint.Keypoint2D
]This class defines the concept of 2D keypoints label.
LabeledKeypoints2D
is the 2D keypoints type of label, which is often used for CV tasks such as human body pose estimation.- Parameters
keypoints – A list of 2D keypoint.
category – The category of the label.
attributes – The attributes 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
>>> LabeledKeypoints2D( ... [(1, 2), (2, 3)], ... category="example", ... attributes={"key": "value"}, ... instance="123", ... ) LabeledKeypoints2D [ Keypoint2D(1, 2), Keypoint2D(2, 3) ]( (category): 'example', (attributes): {...}, (instance): '123' )
- classmethod loads(contents)[source]¶
Loads a LabeledKeypoints2D from a dict containing the information of the label.
- Parameters
contents (Dict[str, Any]) – A dict containing the information of the 2D keypoints label.
- Returns
The loaded
LabeledKeypoints2D
object.- Return type
tensorbay.label.label_keypoints._T
Examples
>>> contents = { ... "keypoints2d": [ ... {"x": 1, "y": 1, "v": 2}, ... {"x": 2, "y": 2, "v": 2}, ... ], ... "category": "example", ... "attributes": {"key": "value"}, ... "instance": "12345", ... } >>> LabeledKeypoints2D.loads(contents) LabeledKeypoints2D [ Keypoint2D(1, 1, 2), Keypoint2D(2, 2, 2) ]( (category): 'example', (attributes): {...}, (instance): '12345' )
- dumps()[source]¶
Dumps the current 2D keypoints label into a dict.
- Returns
A dict containing all the information of the 2D keypoints label.
- Return type
Dict[str, Any]
Examples
>>> labeledkeypoints2d = LabeledKeypoints2D( ... [(1, 1, 2), (2, 2, 2)], ... category="example", ... attributes={"key": "value"}, ... instance="123", ... ) >>> labeledkeypoints2d.dumps() { 'category': 'example', 'attributes': {'key': 'value'}, 'instance': '123', 'keypoints2d': [{'x': 1, 'y': 1, 'v': 2}, {'x': 2, 'y': 2, 'v': 2}], }