I am trying to integrate a custom neural net (an FCN build atop mobilenet 2). I've converted it using blobconverter and set FP16, mean of 0, and scale of 255. The following code works correctly and produces the expected mask output (despite the fact that I am not doing any pre-processing of the input which is just meant to be a division by 255, is that happening automatically?).
pipeline = depthai.Pipeline()
neural_network = pipeline.create(depthai.node.NeuralNetwork)
neural_network.setBlobPath("theneuralnet.blob")
xin_nn = pipeline.create(depthai.node.XLinkIn)
xin_nn.out.link(neural_network.input)
xin_nn.setStreamName("nn_in")
xout_nn = pipeline.create(depthai.node.XLinkOut)
xout_nn.setStreamName("nn_out")
neural_network.out.link(xout_nn.input)
im = cv2.resize(cv2.imread("/tmp/tags_image.jpg"), (640, 480)).astype("float16")
im = im.transpose((2, 0, 1)) # the model expects CHW
with depthai.Device(pipeline) as device:
q_nn = device.getOutputQueue("nn_out")
q_nn_in = device.getInputQueue("nn_in")
nn_data = dai.NNData()
nn_data.setLayer("input_layer_name", im)
q_nn_in.send(nn_data)
oot = q_nn.get()
out1 = (np.array(oot.getLayerFp16("output_name1")).reshape((480, 640, 1))[:, :, 0]*255).astype("uint8")
out2 = (np.array(oot.getLayerFp16("output_name2")).reshape((480, 640, 4))[:, :, 0]*255).astype("uint8")
I'm trying to get this model to run on the color camera of the OakD Pro POE but the output looks incorrect. Here's the code for that part.
pipeline = depthai.Pipeline()
cam_rgb = pipeline.create(depthai.node.ColorCamera)
cam_rgb.setFp16(True)
cam_rgb.setPreviewSize(640, 480)
cam_rgb.setInterleaved(False)
cam_rgb.setResolution(depthai.ColorCameraProperties.SensorResolution.THE_1080_P)
neural_network = pipeline.create(depthai.node.NeuralNetwork)
neural_network.setBlobPath("theneuralnet.blob")
cam_rgb.preview.link(neural_network.input)
xout_nn = pipeline.create(depthai.node.XLinkOut)
xout_nn.setStreamName("nn_out")
neural_network.out.link(xout_nn.input)
neural_network.passthrough.link(xout_rgb.input)
with depthai.Device(pipeline) as device:
q_rgb = device.getOutputQueue("rgb")
q_nn = device.getOutputQueue("nn_out")
while True:
oot = q_nn.tryGet()
if oot:
out1 = (np.array(oot.getLayerFp16("output_name1")).reshape((1, 480, 640, 1))[0, :, :, 0]*255).astype("uint8")
out2 = (np.array(oot.getLayerFp16("output_name2")).reshape((1, 480, 640, 4))[0, :, :, 0]*255).astype("uint8")
cv2.imshow("f1", np.vstack((out1, out2)))
cv2.waitKey(1)
I suspect the images are not making it into the neural net correctly. Maybe it's a discrepancy between image and model input order? How can I go about investigating this more?