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

相关推荐
九河_几秒前
解决pip install gym==0.19.0安装失败问题
开发语言·python·pip·gym
红豆诗人几秒前
C语言进阶知识--文件操作
c语言·开发语言·文件操作
麦麦鸡腿堡1 小时前
Java绘图技术
java·开发语言
热爱编程的OP1 小时前
Linux进程池与管道通信详解:从原理到实现
linux·开发语言·c++
武子康8 小时前
Java-171 Neo4j 备份与恢复 + 预热与执行计划实战
java·开发语言·数据库·性能优化·系统架构·nosql·neo4j
怪兽20149 小时前
fastjson在kotlin不使用kotlin-reflect库怎么使用?
android·开发语言·kotlin
ClearLiang9 小时前
Kotlin-协程的挂起与恢复
开发语言·kotlin
彭同学学习日志9 小时前
Kotlin Fragment 按钮跳转报错解决:Unresolved reference ‘floatingActionButton‘
android·开发语言·kotlin
海域云赵从友9 小时前
破解跨境数据传输瓶颈:中国德国高速跨境组网专线与本地化 IP 的协同策略
开发语言·php
咚咚王者9 小时前
人工智能之编程进阶 Python高级:第九章 爬虫类模块
开发语言·python