Browse Source

Change type hinting frfom Uint8 only array to any array

tags/v0.3.0-rc
haixuanTao 2 years ago
parent
commit
739cfd57f7
5 changed files with 14 additions and 16 deletions
  1. +3
    -5
      binaries/cli/src/template/python/operator/operator-template.py
  2. +1
    -1
      binaries/runtime/src/operator/python.rs
  3. +5
    -5
      examples/python-operator-dataflow/object_detection.py
  4. +4
    -4
      examples/python-operator-dataflow/plot.py
  5. +1
    -1
      examples/python-operator-dataflow/webcam.py

+ 3
- 5
binaries/cli/src/template/python/operator/operator-template.py View File

@@ -30,10 +30,10 @@ class Operator:

Args:
dora_input (dict): Input dict containing an `id`, `data` and `metadata`.
send_output Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None]:
send_output Callable[[str, bytes | pa.Array, Optional[dict]], None]:
Function for sending output to the dataflow:
- First argument is the `output_id`
- Second argument is the data as either bytes or `pa.UInt8Array`
- Second argument is the data as either bytes or `pa.Array`
- Third argument is dora metadata dict
e.g.: `send_output("bbox", pa.array([100], type=pa.uint8()), dora_event["metadata"])`

@@ -44,9 +44,7 @@ class Operator:
STOP means that the operator stop listening for inputs.

"""
print(
f"Received input {dora_input['id']}, with data: {dora_input['value']}"
)
print(f"Received input {dora_input['id']}, with data: {dora_input['value']}")

return DoraStatus.CONTINUE



+ 1
- 1
binaries/runtime/src/operator/python.rs View File

@@ -287,7 +287,7 @@ mod callback_impl {

/// Send an output from the operator:
/// - the first argument is the `output_id` as defined in your dataflow.
/// - the second argument is the data as either bytes or pyarrow.UInt8Array for zero copy.
/// - the second argument is the data as either bytes or pyarrow.Array for zero copy.
/// - the third argument is dora metadata if you want ot link the tracing from one input into an output.
/// `e.g.: send_output("bbox", pa.array([100], type=pa.uint8()), dora_event["metadata"])`
#[pymethods]


+ 5
- 5
examples/python-operator-dataflow/object_detection.py View File

@@ -27,7 +27,7 @@ class Operator:
def on_event(
self,
dora_event: dict,
send_output: Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None],
send_output: Callable[[str, bytes | pa.Array, Optional[dict]], None],
) -> DoraStatus:
if dora_event["type"] == "INPUT":
return self.on_input(dora_event, send_output)
@@ -36,15 +36,15 @@ class Operator:
def on_input(
self,
dora_input: dict,
send_output: Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None],
send_output: Callable[[str, bytes | pa.Array, Optional[dict]], None],
) -> DoraStatus:
"""Handle image
Args:
dora_input (dict): Dict containing the "id", "data", and "metadata"
send_output Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None]:
dora_input (dict): Dict containing the "id", value, and "metadata"
send_output Callable[[str, bytes | pa.Array, Optional[dict]], None]:
Function for sending output to the dataflow:
- First argument is the `output_id`
- Second argument is the data as either bytes or `pa.UInt8Array`
- Second argument is the data as either bytes or `pa.Array`
- Third argument is dora metadata dict
e.g.: `send_output("bbox", pa.array([100], type=pa.uint8()), dora_event["metadata"])`
"""


+ 4
- 4
examples/python-operator-dataflow/plot.py View File

@@ -34,7 +34,7 @@ class Operator:
def on_event(
self,
dora_event: dict,
send_output: Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None],
send_output: Callable[[str, bytes | pa.Array, Optional[dict]], None],
) -> DoraStatus:
if dora_event["type"] == "INPUT":
return self.on_input(dora_event, send_output)
@@ -43,7 +43,7 @@ class Operator:
def on_input(
self,
dora_input: dict,
send_output: Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None],
send_output: Callable[[str, bytes | pa.Array, Optional[dict]], None],
) -> DoraStatus:
"""
Put image and bounding box on cv2 window.
@@ -51,10 +51,10 @@ class Operator:
Args:
dora_input["id"] (str): Id of the dora_input declared in the yaml configuration
dora_input["value"] (arrow array): message of the dora_input
send_output Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None]:
send_output Callable[[str, bytes | pa.Array, Optional[dict]], None]:
Function for sending output to the dataflow:
- First argument is the `output_id`
- Second argument is the data as either bytes or `pa.UInt8Array`
- Second argument is the data as either bytes or `pa.Array`
- Third argument is dora metadata dict
e.g.: `send_output("bbox", pa.array([100], type=pa.uint8()), dora_event["metadata"])`
"""


+ 1
- 1
examples/python-operator-dataflow/webcam.py View File

@@ -32,7 +32,7 @@ class Operator:
def on_event(
self,
dora_event: str,
send_output: Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None],
send_output: Callable[[str, bytes | pa.Array, Optional[dict]], None],
) -> DoraStatus:
match dora_event["type"]:
case "INPUT":


Loading…
Cancel
Save