luxonis / depthai

DepthAI Python API utilities, examples, and tutorials.
https://docs.luxonis.com
MIT License
941 stars 233 forks source link

dai::XLinkWriteError on deploying custom blob on OAK-D pro #1157

Closed KunalA18 closed 8 months ago

KunalA18 commented 9 months ago

Hi, We are trying to deploy a model on our OAK-D Pro camera steps we followed:- Converted .pth -> .onnx -> .blob (using blobconverter) blob size -> 408 MB

Code that we are running on OAK-D ->

import cv2
import depthai as dai
import numpy as np
import argparse
import time
from misc import crf_refine

# --------------- Pipeline ---------------
NN_WIDTH, NN_HEIGHT = 416, 416
# Start defining a pipeline
pipeline = dai.Pipeline()
pipeline.setOpenVINOVersion(version=dai.OpenVINO.VERSION_2021_1)

# Define a neural network
detection_nn = pipeline.create(dai.node.NeuralNetwork)
detection_nn.setBlobPath("/home/kunal/Downloads/FYP/OptiDepth/GDNet/model_g.blob")
detection_nn.setNumPoolFrames(4)
detection_nn.input.setBlocking(False)
detection_nn.setNumInferenceThreads(2)

# Define camera
cam = pipeline.create(dai.node.ColorCamera)
cam.setPreviewSize(NN_WIDTH, NN_HEIGHT)
cam.setInterleaved(False)
cam.setFps(40)
cam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)

# Create outputs
xout_cam = pipeline.create(dai.node.XLinkOut)
xout_cam.setStreamName("cam")

xout_nn = pipeline.create(dai.node.XLinkOut)
xout_nn.setStreamName("nn")

# Link
cam.preview.link(detection_nn.input)
detection_nn.passthrough.link(xout_cam.input)
detection_nn.out.link(xout_nn.input)

# --------------- Inference ---------------
# Pipeline defined, now the device is assigned and pipeline is started
with dai.Device(pipeline) as device:
    # Output queues will be used to get the rgb frames and nn data from the outputs defined above
    q_cam = device.getOutputQueue("cam", 4, blocking=False)
    q_nn = device.getOutputQueue(name="nn", maxSize=4, blocking=False)

    start_time = time.time()
    counter = 0
    fps = 0
    layer_info_printed = False

    while True:
        in_frame = q_cam.get()
        in_nn = q_nn.get()

        frame = in_frame.getCvFrame()
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        # Get output layer
        pred_mask = np.array(in_nn.getFirstLayerFp16()).reshape((NN_HEIGHT, NN_WIDTH))
        pred_mask = (pred_mask*255).astype(np.uint8)

        f_1 = crf_refine(np.array(frame), pred_mask)

        cv2.imshow("Mask", f_1)

        # Calculate FPS
        counter += 1
        if (time.time() - start_time) > 1:
            fps = counter / (time.time() - start_time)

            counter = 0
            start_time = time.time()
            print(fps)

        if cv2.waitKey(1) == ord('q'):
            break

Error we are getting ->

Screenshot from 2024-02-27 19-43-45

Can someone pls provide some insights on how can we solve this? Thanks

KunalA18 commented 8 months ago

found out that 300MB is the limit in blobconverter so anything bigger than that would not pass.