Browse Source

Small refactoring using `black`

tags/v0.2.5-alpha
haixuanTao 2 years ago
parent
commit
27ccf614ba
5 changed files with 14 additions and 22 deletions
  1. +1
    -1
      examples/python-dataflow/dataflow.yml
  2. +2
    -1
      examples/python-dataflow/plot.py
  3. +1
    -1
      examples/python-operator-dataflow/dataflow.yml
  4. +4
    -10
      examples/python-operator-dataflow/object_detection.py
  5. +6
    -9
      examples/python-operator-dataflow/plot.py

+ 1
- 1
examples/python-dataflow/dataflow.yml View File

@@ -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


+ 2
- 1
examples/python-dataflow/plot.py View File

@@ -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()



+ 1
- 1
examples/python-operator-dataflow/dataflow.yml View File

@@ -3,7 +3,7 @@ nodes:
operator:
python: webcam.py
inputs:
tick: dora/timer/millis/100
tick: dora/timer/millis/50
outputs:
- image



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

@@ -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

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

@@ -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:
[


Loading…
Cancel
Save