erik Hi Erik, I could not reply earlier. Here the minimum reproduceable code that crashes the device. I also explanined it a little earlier. Code has two script nodes one just arrange frames and order one post process output of NN node. Neural network is just digit recognition network. I have shared link for downloading its blob file. Please have a look. https://drive.google.com/file/d/1qYLMy7P6hGO9PQPCLKtD4_Inn-vuM2te/view?usp=sharing
Above link is for the blob file and below link is the python code file that is pasted below.
https://drive.google.com/file/d/1G7gWjvHbbZ_u9EWOujephRNNnN0xIvIA/view?usp=sharing
import depthai as dai
import numpy as np
import marshal
import time
import logging
import os
import requests
whitelist=set('0123456789')
time_bb_cord=[0.3070,0.6312,0.6008,0.8187]
local_bb_cord=[0.2289,0.2812,0.3914,0.4537]
visit_bb_cord=[0.5492,0.2762,0.7164,0.4525]
# Create pipeline
def Manip_Frame(pipeline,region_bb_cord):
manip_time = pipeline.create(dai.node.ImageManip)
manip_time.initialConfig.setCropRect(region_bb_cord[0],region_bb_cord[1],region_bb_cord[2],region_bb_cord[3])
manip_time.setKeepAspectRatio(False)
manip_time.initialConfig.setResize(100,32)
return manip_time
def NN_node(pipeline,path):
nn = pipeline.create(dai.node.NeuralNetwork)
nn.setBlobPath(path)
return nn
pipeline = dai.Pipeline()
model_path = 'crnn_99_soft_no_norm_4.blob'
cam = pipeline.create(dai.node.MonoCamera)
cam.setBoardSocket(dai.CameraBoardSocket.RIGHT)
cam.setFps(6)
cam.setResolution(dai.MonoCameraProperties.SensorResolution.THE_800_P)
manip_time=Manip_Frame(pipeline,time_bb_cord)
cam.out.link(manip_time.inputImage)
manip_local=Manip_Frame(pipeline,local_bb_cord)
cam.out.link(manip_local.inputImage)
manip_visit=Manip_Frame(pipeline,visit_bb_cord)
cam.out.link(manip_visit.inputImage)
script=pipeline.create(dai.node.Script)
manip_time.out.link(script.inputs['time_frame'])
manip_local.out.link(script.inputs['local_frame'])
manip_visit.out.link(script.inputs['visit_frame'])
script.setScript("""
import marshal
f_list={}
while True:
t_frame=node.io['time_frame'].get()
l_frame=node.io['local_frame'].get()
v_frame=node.io['visit_frame'].get()
if t_frame is not None and 'time' not in f_list.keys():
t_f_num=t_frame.getSequenceNum()
f_list['time']=t_f_num
if l_frame is not None and 'local' not in f_list.keys():
l_f_num=t_frame.getSequenceNum()
f_list['local']=l_f_num
if v_frame is not None and 'visit' not in f_list.keys():
v_f_num=t_frame.getSequenceNum()
f_list['visit']=v_f_num
if len(f_list.keys())==3 and f_list['time']==f_list['local'] and f_list['time']==f_list['visit']:
f_list.clear()
node.io['script_out'].send(t_frame)
node.io['script_out1'].send(l_frame)
node.io['script_out2'].send(v_frame)
""")
recog_nn=NN_node(pipeline,model_path)
script.outputs['script_out'].link(recog_nn.input)
script.outputs['script_out1'].link(recog_nn.input)
script.outputs['script_out2'].link(recog_nn.input)
decoder_script=pipeline.create(dai.node.Script)
recog_nn.out.link(decoder_script.inputs['log_probs'])
decoder_script.setScript("""
import marshal
label2char={1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: '.', 12: ':'}
def get_strings(nndata):
outname=nndata.getAllLayerNames()[0]
data=nndata.getLayerFp16(outname)
raw_preds=[]
for i in range(24):
log_probs=data[i*13:i*13+13]
raw_preds.append(log_probs.index(max(log_probs)))
results=[]
previous=None
for l in raw_preds:
if l != previous:
results.append(l)
previous = l
results = [l for l in results if l != 0]
f_results=''
for r in range(len(results)):
f_results=f_results+label2char[results[r]]
return f_results
outs=[]
while True:
time_=node.io['log_probs'].get()
results=get_strings(time_)
if len(results)==0:
results='none'
if len(outs)==0:
outs.append(results)
elif len(outs)>0:
if results=='none':
outs.append(results)
elif results!=outs[-1]:
outs.append(results)
if len(outs)==3:
x_serial = marshal.dumps(outs)
b = Buffer(len(x_serial))
b.setData(x_serial)
outs.clear()
node.io['f_time'].send(b)
""")
nn_Out = pipeline.create(dai.node.XLinkOut)
nn_Out.setStreamName("recogs1")
decoder_script.outputs['f_time'].link(nn_Out.input)
with dai.Device(pipeline) as device:
nn_queue1 = device.getOutputQueue(name='recogs1', maxSize=4, blocking=False)
while True:
nn_out1 = nn_queue1.get()
if nn_out1 is not None:
score_dict=marshal.loads(nn_out1.getData())
print(score_dict)
`