某些低端的host, 图像采集的时候, ISP最终输出的图像一般为NV12的数据格式, 一般的AI模型的架构为RGB数据集。如果在host端将NV12转换为RGB,然后发送给Hailo进行推理则可能会极大的占用CPU的使用率,从而影响最终pipeline的性能。
我们推荐将NV12转RGB这个步骤放到Hailo中进行,Hailo已经支持了。
有两种alls可以参考:
yuv_to_rgb1 = input_conversion(yuv_to_rgb)
reshape = input_conversion(input_layer1, nv12_to_hailo_yuv, emulator_support=False)
或者(DFC 3.29.0支持)
reshape_nv12,rgb_layer = input_conversion(input_layer1, nv12_to_rgb, emulator_support=True)
请注意我这边两个脚本中emulator_support设定的不同,此设定的目的是为了说明我们在校准这个模型的时候使用的数据集格式不同。当设置为True的时候,说明我们使用的是NV12数据集进行校准; 当为False的时候则为RGB校准集。
如何准备这种NV12数据集以及如何使用pyhailort或者DFC模拟器进行推理呢?
一个正常的(N,H,W,C)的RGB校准集,如果格式为NV12,我们工具要求的格式为(N,H/2,W,C)
具体转换函数可以参考:
def bgr2nv12(bgr:np.ndarray) -> np.ndarray:
yuv = cv2.cvtColor(bgr, cv2.COLOR_BGR2YUV_I420)
uv_row_cnt = yuv.shape[0] // 3
uv_plane = np.transpose(yuv[uv_row_cnt * 2:].reshape(2, -1), [1, 0])
yuv[uv_row_cnt * 2:] = uv_plane.reshape(uv_row_cnt, -1)
return yuv
实际上使用:
image_array = bgr2nv12(image_array)
image_array = np.reshape(image_array, (height/2, width, 3))
当然也可以参考我们model中的方式进行数据转换:
类似的,如果你想在颜色转换基础上再加上一个resize功能的话,可以参考我们的model zoo yolov5n_seg_nv12_fhd.alls:
resize_input1 = resize(input_layer1, resize_shapes=[1080, 1920])
yuv_to_rgb1 = input_conversion(yuv_to_rgb)
reshape = input_conversion(input_layer1, nv12_to_hailo_yuv, emulator_support=True)
发表回复