Hi @jakaskerl
Please find the MRE below.
So I am using our own custom Yolov6n trained model. If you can share with me your official email id, then I can give you the access to the model blob and json file to reproduce.
I tried to reproduced it using the pretrained yolov4_tiny model provided by depthai for car detection under depthai-experiments. However i don't see any issue when I am using this model.
You will require the following libraries to run the script:
- OpenCv Python
- DepthAI
- blobconverter
- numpy
Also, put the model and json file paths in the argument parser lines as the default path. The script will itself pick that default path when you run it from VS code.
from pathlib import Path
import cv2
import depthai as dai
import numpy as np
import time
import argparse
import json
import blobconverter
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--model", help="Provide model name or model path for inference",
default='models/6_shaves_model/best_ckpt_openvino_2022.1_6shave.blob', type=str)
parser.add_argument("-c", "--config", help="Provide config path for inference",
default='models/6_shaves_model/best_ckpt.json', type=str)
args = parser.parse_args()
# parse config
configPath = Path(args.config)
if not configPath.exists():
raise ValueError("Path {} does not exist!".forma/t(configPath))
with configPath.open() as f:
config = json.load(f)
nnConfig = config.get("nn_config", {})
# parse input shape
if "input_size" in nnConfig:
W, H = tuple(map(int, nnConfig.get("input_size").split('x')))
# extract metadata
metadata = nnConfig.get("NN_specific_metadata", {})
classes = metadata.get("classes", {})
coordinates = metadata.get("coordinates", {})
anchors = metadata.get("anchors", {})
anchorMasks = metadata.get("anchor_masks", {})
iouThreshold = metadata.get("iou_threshold", {})
confidenceThreshold = metadata.get("confidence_threshold", {})
print(metadata)
# parse labels
nnMappings = config.get("mappings", {})
labels = nnMappings.get("labels", {})
print("Labels: ", labels)
# get model path
nnPath = args.model
if not Path(nnPath).exists():
print("No blob found at {}. Looking into DepthAI model zoo.".format(nnPath))
nnPath = str(blobconverter.from_zoo(args.model, shaves = 6, zoo_type = "depthai", use_cache=True))
# sync outputs
syncNN = True
# Create pipeline
pipeline = dai.Pipeline()
# Define sources and outputs
camRgb = pipeline.create(dai.node.ColorCamera)
detectionNetwork = pipeline.create(dai.node.YoloDetectionNetwork)
#xoutRgb = pipeline.create(dai.node.XLinkOut)
nnOut = pipeline.create(dai.node.XLinkOut)
# By Yishu
xoutISP = pipeline.create(dai.node.XLinkOut)
manip = pipeline.create(dai.node.ImageManip)
xoutManip = pipeline.create(dai.node.XLinkOut)
# Passthrough to debug
# Send passthrough frames to the host, so frames are in sync with bounding boxes
passthroughOut = pipeline.create(dai.node.XLinkOut)
passthroughOut.setStreamName("pass")
detectionNetwork.passthrough.link(passthroughOut.input)
#xoutRgb.setStreamName("rgb")
xoutISP.setStreamName("ISP")
nnOut.setStreamName("nn")
xoutManip.setStreamName("Manip")
# Properties
camRgb.setPreviewSize(W, H)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP) #THE_1080_P
camRgb.setInterleaved(False)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
camRgb.setFps(25) #40
# By Yishu
manip.initialConfig.setKeepAspectRatio(False) #True
manip.initialConfig.setResize(W, H)
# Change to RGB image than BGR - Yishu
manip.initialConfig.setFrameType(dai.ImgFrame.Type.BGR888p)
# setMaxOutputFrameSize to avoid image bigger than max frame size error - Yishu
manip.setMaxOutputFrameSize(1228800)
# By Yishu
nnOut.input.setBlocking(False)
xoutISP.input.setBlocking(False)
xoutManip.input.setBlocking(False)
# By Yishu
nnOut.input.setQueueSize(10)
xoutISP.input.setQueueSize(10)
xoutManip.input.setQueueSize(10)
detectionNetwork.input.setQueueSize(10)
# Network specific settings
detectionNetwork.setConfidenceThreshold(confidenceThreshold)
detectionNetwork.setNumClasses(classes)
detectionNetwork.setCoordinateSize(coordinates)
detectionNetwork.setAnchors(anchors)
detectionNetwork.setAnchorMasks(anchorMasks)
detectionNetwork.setIouThreshold(iouThreshold)
detectionNetwork.setBlobPath(nnPath)
detectionNetwork.setNumInferenceThreads(2)
detectionNetwork.input.setBlocking(False)
camRgb.isp.link(manip.inputImage)
manip.out.link(detectionNetwork.input)
# By Yishu
manip.out.link(xoutManip.input)
detectionNetwork.out.link(nnOut.input)
camRgb.isp.link(xoutISP.input)
device_info = dai.DeviceInfo("192.168.220.10")
# Connect to device and start pipeline
with dai.Device(pipeline, device_info) as device:
# Output queues will be used to get the rgb frames and nn data from the outputs defined above
qDet = device.getOutputQueue("nn", 4, blocking=False) #device.getOutputQueue("nn", 1, blocking=False)
qISP = device.getOutputQueue("ISP", 4, blocking=False)
qManip = device.getOutputQueue("Manip", 4, blocking=False)
# Passthrough to debug
qPass = device.getOutputQueue(name="pass")
frame = None
detections = []
startTime = time.monotonic()
counter = 0
color2 = (255, 255, 255)
j=1
###Create the folder that will contain capturing
folder_name = "D:\\Cameras_Live\\PayOff"
path = Path(folder_name)
while True:
###Create the folder that will contain capturing
path.mkdir(parents=True, exist_ok=True)
# By Yishu
inISP = qISP.tryGet() # ISP QUEUE IS ALWAYS NONE WHEN SETTING THE RESOLUTION TO 12MP
inManip = qManip.tryGet()
print('1')
frame_pass = qPass.get() #.getCvFrame()
print('2')
inDet = qDet.get()
print('3')
if inISP is not None:
frame = inISP.getCvFrame()
nn_fps =counter / (time.monotonic() - startTime)
print("nn_fps: ", nn_fps)
cv2.putText(frame, "NN fps: {:.2f}".format(nn_fps),
(2, frame.shape[0] - 4), cv2.FONT_HERSHEY_TRIPLEX, 0.4, color2)
if inDet is not None:
detections = inDet.detections
counter += 1
if cv2.waitKey(1) == ord('q'):
break
j=j+1
if j==5:
j=1
Thanks,
Yishu