前言
模型转换后,性能多多少少都有点损失,为了评估肯定需要在海思上跑个数据集,但是海思的图片输入格式是bgr_planner格式,所以需要对图片做个格式转换。对于大神来说,直接全用c/c++完成,但本菜逼只能选择这种two-stage方式了。
代码
废话不多说,代码都是经过试验,确定能跑的通的。为了放心,特意还做了个试验,同一张图片用python转为bgr_planner格式,和用c++转为bgr_planner格式,再先后喂入人脸识别模型,最后的输出特征值差了0.05左右。
import cv2
import os
import numpy as np
import struct
# 图片转为bgr_planner文件并保存
def mat_to_bgr_planner(img_path, bgr_path, new_size, bgr_planner=1):
img = cv2.imread(img_path)
img = cv2.resize(img, new_size)
height = img.shape[0]
width = img.shape[1]
channel = img.shape[