海思多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

相关推荐
姓蔡小朋友6 分钟前
LUA脚本
开发语言·junit·lua
悟能不能悟15 分钟前
Java CheckFailedException会去获取message.properties的内容吗
java·开发语言
shang_xs18 分钟前
Java 25 ScopedValue - 作用域内安全访问的一种实现
java·开发语言·安全
向量引擎19 分钟前
[架构师级] 压榨GPT-5.2与Sora 2的极限性能:从单体调用到高并发多模态Agent集群的演进之路(附全套Python源码与性能调优方案)
开发语言·人工智能·python·gpt·ai·ai写作·api调用
小白学大数据27 分钟前
Java 异步爬虫高效获取小红书短视频内容
java·开发语言·爬虫·python·音视频
solar应急响应29 分钟前
域控宕机!如何强制夺取五大角色恢复业务?
开发语言·php
数据的世界0133 分钟前
C# 获评2025年度编程语言-编程语言排行榜2026年1月
开发语言
2201_757830871 小时前
Bean原理篇
java·开发语言
草原上唱山歌1 小时前
推荐学习的C++书籍
开发语言·c++·学习
asdfg12589631 小时前
小程序开发中的JS和Go的对比及用途
开发语言·javascript·golang