Hi,

I'm trying to get my Yolov6n model to run standalone. It works when i run it on my PC directly however i am unable to receive the frames if i run it standalone. It basically stops responding,.

Here is the code i have tried flashing it before and it did not really work. So I'm trying to debug using the PC as client and host.

Here is the code

import depthai as dai

import time

import blobconverter

# Paths to your model files

xml_path = "C:/Users/wind/Desktop/Office work/CV/Trial1/gen2-yolo/host-decoding/models/best_ckpt.xml"

bin_path = "C:/Users/wind/Desktop/Office work/CV/Trial1/gen2-yolo/host-decoding/models/best_ckpt.bin"

model_blob = blobconverter.from_openvino(xml=xml_path, bin=bin_path)

pipeline = dai.Pipeline()

camRgb = pipeline.createColorCamera()

camRgb.setPreviewSize(640, 640)  # Set to match the input size expected by YOLOv6

camRgb.setInterleaved(False)

camRgb.setVideoSize(640, 640)    # Ensure this matches the NN input size

detection_nn = pipeline.create(dai.node.YoloDetectionNetwork)

detection_nn.setConfidenceThreshold(0.8)

detection_nn.setBlobPath(model_blob)

detection_nn.setNumInferenceThreads(2)

detection_nn.setNumClasses(5)

detection_nn.setCoordinateSize(4)

detection_nn.input.setBlocking(False)

default_anchors = [

    10, 13, 16, 30, 33, 23,

    30, 61, 62, 45, 59, 119,

    116, 90, 156, 198, 373, 326

]

# Set anchors and masks for YOLOv6

detection_nn.setAnchors(default_anchors)

detection_nn.setAnchorMasks({ "side26": [0, 1, 2], "side13": [3, 4, 5] })

detection_nn.setIouThreshold(0.5)

videoEnc = pipeline.create(dai.node.VideoEncoder)

videoEnc.setDefaultProfilePreset(30, dai.VideoEncoderProperties.Profile.MJPEG)

camRgb.preview.link(detection_nn.input)

camRgb.video.link(videoEnc.input)

script = pipeline.create(dai.node.Script)

script.setProcessor(dai.ProcessorType.LEON_CSS)

videoEnc.bitstream.link(script.inputs['frame'])

script.inputs['frame'].setBlocking(False)

script.inputs['frame'].setQueueSize(1)

detection_nn.out.link(script.inputs['detections'])

script.setScript("""

import socket

import time

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server.bind(("0.0.0.0", 5000))

server.listen()

node.warn("Server up")

while True:

    conn, client = server.accept()

    node.warn(f"Connected to client IP: {client}")

    try:

        while True:

            # Get the frame packet

            pck = node.io["frame"].get()

            data = pck.getData()

            ts = pck.getTimestamp()

            header = f"ABCDE " + str(ts.total_seconds()).ljust(18) + str(len(data)).ljust(8)

            node.warn(f'>{header}<')

            conn.send(bytes(header, encoding='ascii'))

            conn.send(data)

 # Get detection results

            detections = node.io["detections"].tryGet()

            # if detections is not None:

            #     for det in detections.detections:

            #         det_info = f"Label: {det.label}, Confidence: {det.confidence}, " \

            #                    f"Bounding box: [{det.xmin}, {det.ymin}, {det.xmax}, {det.ymax}]"

            #         node.warn(det_info)

            #         # Send detection information

            #         detection_data = f"{det.label},{det.confidence},{det.xmin},{det.ymin},{det.xmax},{det.ymax}\\n"

            #         conn.send(detection_data.encode('ascii'))

    except Exception as e:        node.warn(f"Client disconnected: {e}")        conn.close()""")

with dai.Device(pipeline) as device:

    print("Pipeline started, running...")

    try:        while True:            # Monitor and display warnings from the script node            logs = device.getQueueEvents()            for log in logs:                print(log)            time.sleep(1)  # Wait for a second before checking for new events    except KeyboardInterrupt:        print("Pipeline stopped by user")
print("Script finished")

    So i tried flashing it with,

    (f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()

    bootloader = dai.DeviceBootloader(bl)

    progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')

    bootloader.flash(progress, pipeline)

    Instead of the code above but i am getting the same issue. Upon looking further its something to do with Heading, encoding(ascii). I want to know if my setscript code is correct. Also i tried commenting sending the frames part and uncommented the detections. However i did not receive any detection. Please let me know if this is the right way to implement a yolo model in standalone mode or am i missing something.

    I am using the host way using script node to debug the issue btw.

    Can i process 640x640 image for yolov6n model on OAK PoE-1? Can it handle it ? Can i stream it if i can connect to a client?

    I am using the TCP way with socket connection sending the heading just like above.

    Hi @ZachJaison

    1. Have you tried UTF-8 instead of acii?
    2. By process you mean? The script node is pretty slow for large data manipulations since the CPU is not very performant. But just passing frames through like you are doing currently is fine because only the pointer is passed on. But don't expect to do CV2 operations on it.

    Thanks,
    Jaka