海思多batch推理

代码:https://github.com/mxsurui/NNIE-lite

修改

c 复制代码
void nnie_param_init(SAMPLE_SVP_NNIE_MODEL_S *s_stModel, SAMPLE_SVP_NNIE_CFG_S *stNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *s_stNnieParam)
{
    if (NULL == s_stModel || NULL == stNnieCfg || NULL == s_stNnieParam)
    {
        printf("NULL == s_stModel || NULL == stNnieCfg || NULL == s_stNnieParam \n");
        return;
    }
    stNnieCfg->u32MaxInputNum = 4; //修改为batch size
    stNnieCfg->u32MaxRoiNum = 0;
    stNnieCfg->aenNnieCoreId[0] = SVP_NNIE_ID_0; // set NNIE core
    s_stNnieParam->pstModel = &s_stModel->stModel;

    HI_S32 s32Ret = HI_SUCCESS;
    s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(stNnieCfg, s_stNnieParam);
    if (HI_SUCCESS != s32Ret)
    {
        NNIE_Param_Deinit(s_stNnieParam, s_stModel);
        SAMPLE_SVP_TRACE_INFO("Error,nnie_Param_init failed!\n");
        return;
    }
    else
    {
        printf("**** nnie param init success\n");
    }
}
c 复制代码
	int n = 4;
...
	unsigned char *data = (unsigned char *)malloc(sizeof(unsigned char) * MODEL_HEIGHT * MODEL_HEIGHT * c * n);
	yolov5->run(data);
    Tensor output0 = yolov5_mnas->getOutputTensor(0);
    Tensor output1 = yolov5_mnas->getOutputTensor(1);
    Tensor output2 = yolov5_mnas->getOutputTensor(2);
    for (int i = 0; i < n; i++)
    {

        output0.data + i*6400*3*9;
        output1.data + i*1600*3*9;
        output2.data + i*400*3*9;
        parseYolov5Feature(MODEL_HEIGHT, MODEL_HEIGHT, num_classes, kBoxPerCell, feature_index0, conf_threshold, anchors[2], output0, ids, boxes, confidences);
        parseYolov5Feature(MODEL_HEIGHT, MODEL_HEIGHT, num_classes, kBoxPerCell, feature_index1, conf_threshold, anchors[1], output1, ids, boxes, confidences);
        parseYolov5Feature(MODEL_HEIGHT, MODEL_HEIGHT, num_classes, kBoxPerCell, feature_index2, conf_threshold, anchors[0], output2, ids, boxes, confidences);
		...

    }

实测多batch比单batch在yolov5推理上节省时间并不多。

bs=1: 311ms

bs=4: 1158ms

bs=8: 2287ms

相关推荐
Luis Li 的猫猫8 分钟前
MATLAB跳动的爱心
开发语言·算法·matlab
AIGC魔法师27 分钟前
AI 极客低代码平台快速上手 --生成Python代码
开发语言·harmonyos·低代码平台·ai极客
熊猫钓鱼>_>41 分钟前
对话即编程:如何用 Trae 的 @智能体 5 分钟修复一个复杂 Bug?
开发语言·python·bug
搏博44 分钟前
WPS JS宏实现去掉文档中的所有空行
开发语言·javascript·wps
hie988941 小时前
MATLAB中进行语音信号分析
开发语言·matlab·语音识别
前进的程序员1 小时前
C++经典库介绍
开发语言·c++
(・Д・)ノ2 小时前
python打卡day31
开发语言·人工智能·python
北漂老男孩2 小时前
JavaScript 性能优化实战指南
开发语言·javascript·性能优化
yorushika_2 小时前
python打卡训练营打卡记录day31
开发语言·python·机器学习
qq_2518364572 小时前
基于springboot3 VUE3 火车订票系统前后端分离项目适合新手学习的项目包含 智能客服 换乘算法
java·开发语言·spring boot·后端·学习