From 27ccf614bacc63f4e7bd5ae209d42a4beeec36f7 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Thu, 3 Aug 2023 12:32:07 +0200 Subject: [PATCH] Small refactoring using `black` --- examples/python-dataflow/dataflow.yml | 2 +- examples/python-dataflow/plot.py | 3 ++- examples/python-operator-dataflow/dataflow.yml | 2 +- .../python-operator-dataflow/object_detection.py | 14 ++++---------- examples/python-operator-dataflow/plot.py | 15 ++++++--------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/examples/python-dataflow/dataflow.yml b/examples/python-dataflow/dataflow.yml index 1fc361ae..612ce410 100644 --- a/examples/python-dataflow/dataflow.yml +++ b/examples/python-dataflow/dataflow.yml @@ -4,7 +4,7 @@ nodes: source: ./webcam.py inputs: tick: - source: dora/timer/millis/100 + source: dora/timer/millis/50 queue_size: 1000 outputs: - image diff --git a/examples/python-dataflow/plot.py b/examples/python-dataflow/plot.py index b27e1537..5d0c6c01 100755 --- a/examples/python-dataflow/plot.py +++ b/examples/python-dataflow/plot.py @@ -13,6 +13,8 @@ from utils import LABELS CI = os.environ.get("CI") font = cv2.FONT_HERSHEY_SIMPLEX + + class Plotter: """ Plot image and bounding box @@ -77,7 +79,6 @@ class Plotter: return DoraStatus.CONTINUE - plotter = Plotter() node = Node() diff --git a/examples/python-operator-dataflow/dataflow.yml b/examples/python-operator-dataflow/dataflow.yml index 7088483b..92bf5f2b 100644 --- a/examples/python-operator-dataflow/dataflow.yml +++ b/examples/python-operator-dataflow/dataflow.yml @@ -3,7 +3,7 @@ nodes: operator: python: webcam.py inputs: - tick: dora/timer/millis/100 + tick: dora/timer/millis/50 outputs: - image diff --git a/examples/python-operator-dataflow/object_detection.py b/examples/python-operator-dataflow/object_detection.py index 6a60be93..c19b2c27 100755 --- a/examples/python-operator-dataflow/object_detection.py +++ b/examples/python-operator-dataflow/object_detection.py @@ -41,23 +41,17 @@ class Operator: """Handle image Args: dora_input (dict): Dict containing the "id", "data", and "metadata" - send_output Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None]: + send_output Callable[[str, bytes | pa.UInt8Array, 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.UInt8Array` - Third argument is dora metadata dict e.g.: `send_output("bbox", pa.array([100], type=pa.uint8()), dora_event["metadata"])` """ - frame = ( - dora_input["value"] - .to_numpy() - .reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3)) - ) + frame = dora_input["value"].to_numpy().reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3)) frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB) results = self.model(frame) # includes NMS - arrays = pa.array( - np.array(results.xyxy[0].cpu()).ravel().view(np.uint8) - ) + arrays = pa.array(np.array(results.xyxy[0].cpu()).ravel().view(np.uint8)) send_output("bbox", arrays, dora_input["metadata"]) return DoraStatus.CONTINUE diff --git a/examples/python-operator-dataflow/plot.py b/examples/python-operator-dataflow/plot.py index 1df89997..5a10231e 100755 --- a/examples/python-operator-dataflow/plot.py +++ b/examples/python-operator-dataflow/plot.py @@ -51,18 +51,19 @@ class Operator: Args: dora_input["id"] (str): Id of the dora_input declared in the yaml configuration dora_input["data"] (bytes): Bytes message of the dora_input - send_output Callable[[str, bytes | pa.UInt8Array, Optional[dict]], None]: + send_output Callable[[str, bytes | pa.UInt8Array, 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.UInt8Array` - Third argument is dora metadata dict - e.g.: `send_output("bbox", pa.array([100], type=pa.uint8()), dora_event["metadata"])` """ + e.g.: `send_output("bbox", pa.array([100], type=pa.uint8()), dora_event["metadata"])` + """ if dora_input["id"] == "image": frame = ( dora_input["value"] .to_numpy() .reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3)) - .copy() # copy the image because we want to modify it below + .copy() # copy the image because we want to modify it below ) self.image = frame @@ -74,11 +75,7 @@ class Operator: self.bboxs = np.reshape(bboxs, (-1, 6)) self.bounding_box_messages += 1 - print( - "received " - + str(self.bounding_box_messages) - + " bounding boxes" - ) + print("received " + str(self.bounding_box_messages) + " bounding boxes") for bbox in self.bboxs: [