Hi,
I’m trying to run a YOLO model on a OAK-D S2 PoE camera using DepthAI v3 (Python 3.1.0 bindings).
I can successfully load my YOLO .blob file and run inference with the DetectionNetwork node, but:
inDet.detections is always empty
- The network outputs tensors, but no decoded bounding boxes
- There is no error, just 0 detections every frame
Below is my code for you reference:
import cv2
import depthai as dai
import numpy as np
BLOB_PATH = r"C:/EMVS_Development_Camera_Scripts/Box & Label Detection/best_ckpt_openvino_2022.1_5shave.blob"
W, H = 416, 320 # model input size (width, height)
with dai.Pipeline() as pipeline:
# Camera
cam = pipeline.create(dai.node.Camera).build()
# Request NN-sized frames from the camera
cam_out = cam.requestOutput(
size=(W, H),
type=dai.ImgFrame.Type.BGR888p,
resizeMode=dai.ImgResizeMode.LETTERBOX,
fps=10,
)
# DetectionNetwork – load local blob from disk
det = pipeline.create(dai.node.DetectionNetwork)
det.setBlobPath(BLOB_PATH)
det.setConfidenceThreshold(0.5)
det.setNumInferenceThreads(2)
# Link camera to NN
cam_out.link(det.input)
# Output queues
qDet = det.out.createOutputQueue(maxSize=4, blocking=False)
qRgb = det.passthrough.createOutputQueue(maxSize=4, blocking=False)
# Start pipeline
pipeline.start()
def frameNorm(frame, bbox):
normVals = np.full(len(bbox), frame.shape[0])
normVals[::2] = frame.shape[1]
return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int)
while pipeline.isRunning():
inFrame = qRgb.tryGet()
inDet = qDet.tryGet()
if inFrame is not None:
frame = inFrame.getCvFrame()
# Draw detections if we also have dets
print("InDet: ", inDet)
if inDet is not None:
for d in inDet.detections:
print("Detections Inside: ", d)
b = frameNorm(frame, (d.xmin, d.ymin, d.xmax, d.ymax))
cv2.rectangle(frame, (b[0], b[1]), (b[2], b[3]), (0, 255, 0), 2)
cv2.putText(frame, f"{int(d.confidence * 100)}%",
(b[0], b[1] - 5),
cv2.FONT_HERSHEY_TRIPLEX, 0.5, (0, 255, 0))
cv2.imshow("YOLO", frame)
if cv2.waitKey(1) == ord("q"):
break
I did read here that the DetectionNetwork node replaces the YoloDetectionNetwork from v2. However, I didn't find any examples that shows how we can use a blob file of our yolo model tuned on custom data (most examples make use of yolo models from the Model Zoo) and how do we set the parameters below that were available in v2 to be set using the YoloDetectionNetwork node:
- setNumClasses
- setCoordinateSize
- setAnchors
- setAnchorMasks
- setIouThreshold (for NMS algorithm)
Your help and response is highly appreciated as I am trying to resolve this issue asap.
Thanks,
Yishu