Category
SUMMARY
A single COCO-style object category.
python
from telekinesis import datatypes
category = datatypes.Category(id=1, name="person", supercategory="person")Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | int | Required | Category id. |
name | str | Required | Category name. |
supercategory | str | Required | Supercategory name. |
Raises
| Exception | Condition |
|---|---|
TypeError / ValueError | id isn't convertible via int(...) (e.g. a non-numeric string). name/supercategory are converted via str(...), which accepts virtually any object and rarely fails. |
Attributes
| Attribute | Type | Description |
|---|---|---|
id | int | Category id. |
name | str | Category name. |
supercategory | str | Supercategory name. |
All three fields are read-only after construction. Build a new Category to change one.
Methods
| Method | Type | Description |
|---|---|---|
Category.coerce(value) | Category | Converts a dict or an existing Category into one. If value is already a Category, it is returned unchanged; a dict with id, name, and supercategory keys is unpacked into the constructor. |
Operators
| Operation | Behavior |
|---|---|
a == b | True only if b is also a Category with equal id, name, and supercategory; NotImplemented if b isn't a Category. |
Visualization
python
import rerun as rr
# Your code block
# ....
rr.init("category_example", spawn=True)
datatypes.visualize(category, entity_path="/category", label="Category")Example
python
"""Demonstrates the Telekinesis Category datatype."""
import time
import rerun as rr
from loguru import logger
from telekinesis import datatypes
def category_example():
"""Demonstrate creation, inspection, operations, visualization, and serialization."""
# ======================= Create ============================================
category = datatypes.Category(id=1, name="person", supercategory="person")
logger.info(f"Created Category: {category}")
# ======================= Inspect ===========================================
logger.info(f"id={category.id}")
logger.info(f"name={category.name}")
logger.info(f"supercategory={category.supercategory}")
# ======================= Operations =========================================
other_category = datatypes.Category(id=2, name="bicycle", supercategory="vehicle")
logger.info(f"category == category: {category == category}")
logger.info(f"category == other_category: {category == other_category}")
# ======================= Visualize =========================================
rr.init("category_example", spawn=True)
datatypes.visualize(category, entity_path="/category")
# ======================= Serialize / Deserialize ===========================
start = time.perf_counter()
serialized = datatypes.serialize(category)
serialization_ms = (time.perf_counter() - start) * 1000
start = time.perf_counter()
deserialized = datatypes.deserialize(serialized)["param_0"]
deserialization_ms = (time.perf_counter() - start) * 1000
logger.info(f"Deserialized Category: {deserialized}")
logger.info(f"Round-trip successful: {category == deserialized}")
logger.info(f"Serialization time: {serialization_ms:.3f} ms")
logger.info(f"Deserialization time: {deserialization_ms:.3f} ms")
if __name__ == "__main__":
category_example()
