You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to run ewasr_resnet18.blob in my OAK-D camera. For this, I first exported the model using export.py and then created a script, which follows the general ideal of prediction.py.
Nevertheless, the outputs of the OAK-D inference differ substantially from the ones of prediction.py (ran on my PC). Can you please help me out? We can surely put later the code in the repository ;)
My code:
frompathlibimportPathimportcv2importdepthaiasdaiimportnumpyasnp# Parametersdir="/your/directory/to/ewasr_resnet18.blob"fps=20shape_rgb= (3, 384, 512)
# Load modelnnBlobPath=str((Path(__file__).parent/Path(dir)).resolve().absolute())
ifnotPath(nnBlobPath).exists():
importsysraiseFileNotFoundError(f'Required file/s not found, please run "{sys.executable} install_requirements.py"')
pipeline=dai.Pipeline()
# Define RGB cameracamRgb=pipeline.create(dai.node.ColorCamera)
camRgb.setPreviewSize(shape_rgb[2], shape_rgb[1])
camRgb.setFps(fps)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setInterleaved(False)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)
camRgb.setFp16(True) # Model requires FP16 input# Define neural networknn=pipeline.create(dai.node.NeuralNetwork)
nn.setBlobPath(nnBlobPath)
nn.setNumInferenceThreads(2)
camRgb.preview.link(nn.input)
# xout for rgb and neural networkxoutNN=pipeline.create(dai.node.XLinkOut)
xoutNN.setStreamName("nn")
nn.out.link(xoutNN.input)
xoutRgb=pipeline.create(dai.node.XLinkOut)
xoutRgb.setStreamName("rgb")
nn.passthrough.link(xoutRgb.input)
definterpol_mask(frame, height, width):
# Interpolation using CV2mask=cv2.resize(frame, (width, height), interpolation=cv2.INTER_LINEAR)
returnmaskwithdai.Device(pipeline) asdevice:
# Output queues will be used to get the rgb frames and nn data from the outputs defined abovepreviewQueue=device.getOutputQueue(name="rgb", maxSize=4, blocking=False)
networkQueue=device.getOutputQueue(name="nn", maxSize=4, blocking=False)
whileTrue:
inRgb=previewQueue.get()
in_nn=networkQueue.tryGet()
# Model needs FP16 so we have to convert color frame back to U8 on the hostframe=np.array(inRgb.getData()).view(np.float16).reshape(shape_rgb).transpose(1, 2, 0).astype(np.uint8).copy()
# Prediction mask with extended image sizepred_masks=np.zeros((shape_rgb[1], shape_rgb[2], 3))
ifin_nnisnotNone:
# Get segmentation mask from nn and interpolatepred_origin=np.reshape(in_nn.getLayerFp16('prediction'), (3, 96, 128))
pred_mask_1, pred_mask_2, pred_mask_3=interpol_mask(pred_origin[0], shape_rgb[1], shape_rgb[2]), \
interpol_mask(pred_origin[1], shape_rgb[1], shape_rgb[2]), \
interpol_mask(pred_origin[2], shape_rgb[1], shape_rgb[2])
pred_masks=np.zeros((shape_rgb[1], shape_rgb[2], 3))
pred_masks[:, :, 0], pred_masks[:, :, 1], pred_masks[:, :, 2] =pred_mask_1, pred_mask_2, pred_mask_3# Argmax to get a single channel mask, then transform it to 3 channels to allow color overlaypred_masks_arg=np.argmax(pred_masks, axis=2)
pred_masks[pred_masks_arg==0] = [247, 195, 37]
pred_masks[pred_masks_arg==1] = [41, 167, 224]
pred_masks[pred_masks_arg==2] = [90, 75, 164]
ifpred_masksisnotNone:
# convert to uint8 to use addWeightedpred_masks=pred_masks.astype(np.uint8)
frame_mix=cv2.addWeighted(frame, 0.3, pred_masks, 0.7, 0)
cv2.imshow("mask ", frame_mix)
cv2.imshow("rgb", frame)
ifcv2.waitKey(1) ==ord('q'):
break
Thanks in addition!
The text was updated successfully, but these errors were encountered:
Hello @tersekmatija,
Thanks for the awesome project!
I'm trying to run
ewasr_resnet18.blob
in my OAK-D camera. For this, I first exported the model usingexport.py
and then created a script, which follows the general ideal ofprediction.py
.Nevertheless, the outputs of the OAK-D inference differ substantially from the ones of prediction.py (ran on my PC). Can you please help me out? We can surely put later the code in the repository ;)
My code:
Thanks in addition!
The text was updated successfully, but these errors were encountered: