Skip to content

Image Pipeline Playground

feat(backend/nodes): annotation port helpers

Mohammad Rajaei2f12c97c3cf8
diff --git a/backend/app/nodes/common.py b/backend/app/nodes/common.py
index e626951..2fab64f 100644
--- a/backend/app/nodes/common.py
+++ b/backend/app/nodes/common.py
@@ -39,6 +39,100 @@ def image_out(
)
+def mask_in(
+ port_id: str = "mask",
+ name: str = "Mask",
+ *,
+ optional: bool = True,
+) -> PortSpec:
+ return PortSpec(
+ id=port_id,
+ name=name,
+ direction=PortDirection.INPUT,
+ data_type="mask",
+ optional=optional,
+ )
+
+
+def mask_out(
+ port_id: str = "mask",
+ name: str = "Mask",
+ *,
+ multiple: bool = False,
+) -> PortSpec:
+ return PortSpec(
+ id=port_id,
+ name=name,
+ direction=PortDirection.OUTPUT,
+ data_type="mask",
+ multiple=multiple,
+ )
+
+
+def bboxes_in(
+ port_id: str = "bboxes",
+ name: str = "BBoxes",
+ *,
+ optional: bool = True,
+) -> PortSpec:
+ return PortSpec(
+ id=port_id,
+ name=name,
+ direction=PortDirection.INPUT,
+ data_type="bboxes",
+ optional=optional,
+ )
+
+
+def bboxes_out(
+ port_id: str = "bboxes",
+ name: str = "BBoxes",
+ *,
+ multiple: bool = False,
+) -> PortSpec:
+ return PortSpec(
+ id=port_id,
+ name=name,
+ direction=PortDirection.OUTPUT,
+ data_type="bboxes",
+ multiple=multiple,
+ )
+
+
+def keypoints_in(
+ port_id: str = "keypoints",
+ name: str = "Keypoints",
+ *,
+ optional: bool = True,
+) -> PortSpec:
+ return PortSpec(
+ id=port_id,
+ name=name,
+ direction=PortDirection.INPUT,
+ data_type="keypoints",
+ optional=optional,
+ )
+
+
+def keypoints_out(
+ port_id: str = "keypoints",
+ name: str = "Keypoints",
+ *,
+ multiple: bool = False,
+) -> PortSpec:
+ return PortSpec(
+ id=port_id,
+ name=name,
+ direction=PortDirection.OUTPUT,
+ data_type="keypoints",
+ multiple=multiple,
+ )
+
+
+ANNOTATION_DATA_TYPES = frozenset({"bboxes", "keypoints"})
+IMAGE_LIKE_DATA_TYPES = frozenset({"image", "mask"})
+
+
def require_image(
inputs: dict[str, np.ndarray | list[np.ndarray] | None],
port: str = "image",