finish nnie and succeed to use yolov3 to detect
This commit is contained in:
parent
cb3a6fcd31
commit
7c1feb9857
|
@ -5,6 +5,8 @@ Hi3516CV500_SDK/
|
||||||
build/
|
build/
|
||||||
Rouring/
|
Rouring/
|
||||||
Rouring-Vision/
|
Rouring-Vision/
|
||||||
|
smart_trash_bin/
|
||||||
|
nnie-yolov3-demo/
|
||||||
|
|
||||||
# MacOS Cache
|
# MacOS Cache
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
@ -60,6 +60,7 @@ target("hi_library")
|
||||||
"dl",
|
"dl",
|
||||||
{public = true}
|
{public = true}
|
||||||
)
|
)
|
||||||
|
|
||||||
-- scipt
|
-- scipt
|
||||||
on_load(function (target)
|
on_load(function (target)
|
||||||
print(target:get("links"))
|
print(target:get("links"))
|
||||||
|
@ -80,4 +81,16 @@ target("sample_common")
|
||||||
"SENSOR1_TYPE=GALAXYCORE_GC2053_MIPI_2M_30FPS_10BIT",
|
"SENSOR1_TYPE=GALAXYCORE_GC2053_MIPI_2M_30FPS_10BIT",
|
||||||
{public = true}
|
{public = true}
|
||||||
)
|
)
|
||||||
add_deps("sample_audio")
|
add_deps("sample_audio")
|
||||||
|
|
||||||
|
target("sample_svp")
|
||||||
|
set_kind("static")
|
||||||
|
add_files("Hi3516CV500_SDK/smp/a7_linux/mpp/sample/svp/common/*.c")
|
||||||
|
add_includedirs("Hi3516CV500_SDK/smp/a7_linux/mpp/sample/svp/common", {public = true})
|
||||||
|
add_deps("sample_common")
|
||||||
|
add_links(
|
||||||
|
lib.."libive.a",
|
||||||
|
lib.."libmd.a",
|
||||||
|
lib.."libnnie.a",
|
||||||
|
{public=true}
|
||||||
|
)
|
|
@ -16,7 +16,7 @@ typedef struct hiSAMPLE_VPSS_CONFIG_S {
|
||||||
VPSS_CHN_ATTR_S astChnAttrs[VPSS_MAX_PHY_CHN_NUM];
|
VPSS_CHN_ATTR_S astChnAttrs[VPSS_MAX_PHY_CHN_NUM];
|
||||||
} SAMPLE_VPSS_CONFIG_S;
|
} SAMPLE_VPSS_CONFIG_S;
|
||||||
|
|
||||||
static zlog_category_t* log = NULL;
|
static zlog_category_t* log_video = NULL;
|
||||||
|
|
||||||
// Sensor Info
|
// Sensor Info
|
||||||
static SAMPLE_VI_CONFIG_S g_stViConfig = {0};
|
static SAMPLE_VI_CONFIG_S g_stViConfig = {0};
|
||||||
|
@ -25,6 +25,7 @@ static SIZE_S stSize;
|
||||||
static HI_U32 u32Framerate;
|
static HI_U32 u32Framerate;
|
||||||
|
|
||||||
static VB_CONFIG_S g_stVbConfig = {0};
|
static VB_CONFIG_S g_stVbConfig = {0};
|
||||||
|
static SAMPLE_VO_CONFIG_S stVoConfig;
|
||||||
static SAMPLE_VPSS_CONFIG_S g_stVpss0Config = {0};
|
static SAMPLE_VPSS_CONFIG_S g_stVpss0Config = {0};
|
||||||
static SAMPLE_VPSS_CONFIG_S g_stVpss1Config = {0};
|
static SAMPLE_VPSS_CONFIG_S g_stVpss1Config = {0};
|
||||||
|
|
||||||
|
@ -91,8 +92,11 @@ static HI_S32 VPSS_GetParams(SAMPLE_VPSS_CONFIG_S* pstVpssConfig,
|
||||||
return HI_SUCCESS;
|
return HI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eb3516VideoInit(void) {
|
bool eb3516VideoInit(void) {
|
||||||
log = zlog_get_category("eb3516_video");
|
log_video = zlog_get_category("eb3516_video");
|
||||||
|
if (!log_video) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Get Sensor(VI) Info: picture size , frame rate
|
// Get Sensor(VI) Info: picture size , frame rate
|
||||||
SAMPLE_COMM_VI_GetSensorInfo(&g_stViConfig);
|
SAMPLE_COMM_VI_GetSensorInfo(&g_stViConfig);
|
||||||
|
@ -126,7 +130,7 @@ void eb3516VideoInit(void) {
|
||||||
g_stViConfig.astViInfo[0].stDevInfo.ViDev = 0;
|
g_stViConfig.astViInfo[0].stDevInfo.ViDev = 0;
|
||||||
g_stViConfig.astViInfo[0].stDevInfo.enWDRMode = WDR_MODE_NONE;
|
g_stViConfig.astViInfo[0].stDevInfo.enWDRMode = WDR_MODE_NONE;
|
||||||
// 设置 VI PIPE 信息
|
// 设置 VI PIPE 信息
|
||||||
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0] = 0; // video pipe
|
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0] = 0; // video pipe
|
||||||
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[1] = -1; // snap pipe
|
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[1] = -1; // snap pipe
|
||||||
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[2] = -1;
|
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[2] = -1;
|
||||||
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[3] = -1;
|
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[3] = -1;
|
||||||
|
@ -151,9 +155,9 @@ void eb3516VideoInit(void) {
|
||||||
|
|
||||||
// 配置 VPSS
|
// 配置 VPSS
|
||||||
VPSS_GetParams(&g_stVpss0Config, &stSize, false);
|
VPSS_GetParams(&g_stVpss0Config, &stSize, false);
|
||||||
VPSS_GetParams(&g_stVpss1Config, &stSize, true);
|
// VPSS_GetParams(&g_stVpss1Config, &stSize, true);
|
||||||
|
|
||||||
zlog_info(log, "eb3516 Video Init Finish...");
|
zlog_info(log_video, "eb3516 Video Init Finish...");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool eb3516VideoStart(void) {
|
bool eb3516VideoStart(void) {
|
||||||
|
@ -163,7 +167,7 @@ bool eb3516VideoStart(void) {
|
||||||
s32Ret = SAMPLE_COMM_SYS_InitWithVbSupplement(&g_stVbConfig,
|
s32Ret = SAMPLE_COMM_SYS_InitWithVbSupplement(&g_stVbConfig,
|
||||||
VB_SUPPLEMENT_JPEG_MASK);
|
VB_SUPPLEMENT_JPEG_MASK);
|
||||||
if (s32Ret != HI_SUCCESS) {
|
if (s32Ret != HI_SUCCESS) {
|
||||||
zlog_error(log, "Init VB and MPI failed with %#x!\n", s32Ret);
|
zlog_error(log_video, "Init VB and MPI failed with %#x!\n", s32Ret);
|
||||||
goto EXIT_SYS_RST_CLK;
|
goto EXIT_SYS_RST_CLK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,32 +182,31 @@ bool eb3516VideoStart(void) {
|
||||||
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0], &stIspCtrlParam);
|
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0], &stIspCtrlParam);
|
||||||
s32Ret = SAMPLE_COMM_VI_StartVi(&g_stViConfig);
|
s32Ret = SAMPLE_COMM_VI_StartVi(&g_stViConfig);
|
||||||
if (s32Ret != HI_SUCCESS) {
|
if (s32Ret != HI_SUCCESS) {
|
||||||
zlog_error(log, "Start VI failed with %#x!\n", s32Ret);
|
zlog_error(log_video, "Start VI failed with %#x!\n", s32Ret);
|
||||||
goto EXIT_SYS_STOP;
|
goto EXIT_SYS_STOP;
|
||||||
}
|
}
|
||||||
zlog_info(log, "eb3516 VI Start Success...");
|
zlog_info(log_video, "eb3516 VI Start Success...");
|
||||||
|
|
||||||
// 启动 VPSS
|
// 启动 VPSS
|
||||||
s32Ret = SAMPLE_COMM_VPSS_Start(
|
s32Ret = SAMPLE_COMM_VPSS_Start(
|
||||||
g_stVpss0Config.s32GrpId, g_stVpss0Config.abChnEnable,
|
g_stVpss0Config.s32GrpId, g_stVpss0Config.abChnEnable,
|
||||||
&g_stVpss0Config.stGrpAttr, g_stVpss0Config.astChnAttrs);
|
&g_stVpss0Config.stGrpAttr, g_stVpss0Config.astChnAttrs);
|
||||||
if (s32Ret != HI_SUCCESS) {
|
if (s32Ret != HI_SUCCESS) {
|
||||||
zlog_error(log, "Start VPSS group %d failed with %#x!\n",
|
zlog_error(log_video, "Start VPSS group %d failed with %#x!\n",
|
||||||
g_stVpss0Config.s32GrpId, s32Ret);
|
g_stVpss0Config.s32GrpId, s32Ret);
|
||||||
goto EXIT_VI_STOP;
|
goto EXIT_VI_STOP;
|
||||||
}
|
}
|
||||||
zlog_info(log, "eb3516 VPSS Start Success...");
|
zlog_info(log_video, "eb3516 VPSS Start Success...");
|
||||||
|
|
||||||
// 绑定 VI->VPSS
|
// 绑定 VI->VPSS
|
||||||
s32Ret = SAMPLE_COMM_VI_Bind_VPSS(
|
s32Ret = SAMPLE_COMM_VI_Bind_VPSS(
|
||||||
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0],
|
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0],
|
||||||
g_stViConfig.astViInfo[0].stChnInfo.ViChn, g_stVpss0Config.s32GrpId);
|
g_stViConfig.astViInfo[0].stChnInfo.ViChn, g_stVpss0Config.s32GrpId);
|
||||||
if (s32Ret != HI_SUCCESS) {
|
if (s32Ret != HI_SUCCESS) {
|
||||||
zlog_error(log, "VI Video Pipe bind VPSS failed with %#x!\n", s32Ret);
|
zlog_error(log_video, "VI Video Pipe bind VPSS failed with %#x!\n", s32Ret);
|
||||||
goto EXIT_VPSS_STOP;
|
goto EXIT_VPSS_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get Venc Config
|
// Get Venc Config
|
||||||
VENC_GOP_ATTR_S stGopAttr;
|
VENC_GOP_ATTR_S stGopAttr;
|
||||||
SAMPLE_COMM_VENC_GetGopAttr(VENC_GOPMODE_NORMALP, &stGopAttr);
|
SAMPLE_COMM_VENC_GetGopAttr(VENC_GOPMODE_NORMALP, &stGopAttr);
|
||||||
|
@ -213,14 +216,13 @@ bool eb3516VideoStart(void) {
|
||||||
SAMPLE_COMM_VENC_Creat(g_VencChn[0], g_CodecTypes[0], g_PicSizes[0],
|
SAMPLE_COMM_VENC_Creat(g_VencChn[0], g_CodecTypes[0], g_PicSizes[0],
|
||||||
SAMPLE_RC_VBR, 0, HI_FALSE, &stGopAttr);
|
SAMPLE_RC_VBR, 0, HI_FALSE, &stGopAttr);
|
||||||
if (s32Ret != HI_SUCCESS) {
|
if (s32Ret != HI_SUCCESS) {
|
||||||
zlog_error(log, "Create Venc Chn %d failed with %#x!\n", g_VencChn[0],
|
zlog_error(log_video, "Create Venc Chn %d failed with %#x!\n", g_VencChn[0],
|
||||||
s32Ret);
|
s32Ret);
|
||||||
goto EXIT_VI_VPSS_UNBIND;
|
goto EXIT_VI_VPSS_UNBIND;
|
||||||
}
|
}
|
||||||
zlog_info(log, "eb3516 VENC Start Success...");
|
zlog_info(log_video, "eb3516 VENC Start Success...");
|
||||||
|
|
||||||
/*config vo*/
|
/*config vo*/
|
||||||
SAMPLE_VO_CONFIG_S stVoConfig;
|
|
||||||
SAMPLE_COMM_VO_GetDefConfig(&stVoConfig);
|
SAMPLE_COMM_VO_GetDefConfig(&stVoConfig);
|
||||||
stVoConfig.enDstDynamicRange = DYNAMIC_RANGE_SDR8;
|
stVoConfig.enDstDynamicRange = DYNAMIC_RANGE_SDR8;
|
||||||
stVoConfig.enVoIntfType = VO_INTF_HDMI;
|
stVoConfig.enVoIntfType = VO_INTF_HDMI;
|
||||||
|
@ -228,27 +230,26 @@ bool eb3516VideoStart(void) {
|
||||||
|
|
||||||
/*start vo*/
|
/*start vo*/
|
||||||
s32Ret = SAMPLE_COMM_VO_StartVO(&stVoConfig);
|
s32Ret = SAMPLE_COMM_VO_StartVO(&stVoConfig);
|
||||||
if (HI_SUCCESS != s32Ret)
|
if (HI_SUCCESS != s32Ret) {
|
||||||
{
|
|
||||||
SAMPLE_PRT("start vo failed. s32Ret: 0x%x !\n", s32Ret);
|
SAMPLE_PRT("start vo failed. s32Ret: 0x%x !\n", s32Ret);
|
||||||
goto EXIT_VENC_H264_STOP;
|
goto EXIT_VENC_H264_STOP;
|
||||||
}
|
}
|
||||||
zlog_info(log, "eb3516 VO Start Success...");
|
zlog_info(log_video, "eb3516 VO Start Success...");
|
||||||
|
|
||||||
/*vpss bind vo*/
|
/*vpss bind vo*/
|
||||||
s32Ret = SAMPLE_COMM_VPSS_Bind_VO(g_stVpss0Config.s32GrpId, g_Vpss0Chn[0], stVoConfig.VoDev, g_VencChn[0]);
|
s32Ret = SAMPLE_COMM_VPSS_Bind_VO(g_stVpss0Config.s32GrpId, g_Vpss0Chn[0],
|
||||||
if (HI_SUCCESS != s32Ret)
|
stVoConfig.VoDev, g_VencChn[0]);
|
||||||
{
|
if (HI_SUCCESS != s32Ret) {
|
||||||
SAMPLE_PRT("vo bind vpss failed. s32Ret: 0x%x !\n", s32Ret);
|
SAMPLE_PRT("vo bind vpss failed. s32Ret: 0x%x !\n", s32Ret);
|
||||||
goto EXIT_VO_STOP;
|
goto EXIT_VO_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// // 绑定 VPSS[0,0]->VENC[0]
|
// // 绑定 VPSS[0,0]->VENC[0]
|
||||||
// s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(g_stVpss0Config.s32GrpId, g_Vpss0Chn[0],
|
// s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(g_stVpss0Config.s32GrpId,
|
||||||
|
// g_Vpss0Chn[0],
|
||||||
// g_VencChn[0]);
|
// g_VencChn[0]);
|
||||||
// if (s32Ret != HI_SUCCESS) {
|
// if (s32Ret != HI_SUCCESS) {
|
||||||
// zlog_error(log, "Venc bind Vpss failed with %#x!\n", s32Ret);
|
// zlog_error(log_video, "Venc bind Vpss failed with %#x!\n", s32Ret);
|
||||||
// goto EXIT_VENC_H265_STOP;
|
// goto EXIT_VENC_H265_STOP;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@ -256,16 +257,14 @@ bool eb3516VideoStart(void) {
|
||||||
// s32Ret = SAMPLE_COMM_VENC_StartGetStream(
|
// s32Ret = SAMPLE_COMM_VENC_StartGetStream(
|
||||||
// g_VencChn + 1, sizeof(g_VencChn) / sizeof(VENC_CHN) - 2);
|
// g_VencChn + 1, sizeof(g_VencChn) / sizeof(VENC_CHN) - 2);
|
||||||
// if (HI_SUCCESS != s32Ret) {
|
// if (HI_SUCCESS != s32Ret) {
|
||||||
// zlog_error(log, "Get venc stream failed!\n");
|
// zlog_error(log_video, "Get venc stream failed!\n");
|
||||||
// goto EXIT_VENC_H264_STOP;
|
// goto EXIT_VENC_H264_STOP;
|
||||||
// }
|
// }
|
||||||
// zlog_info(log, "eb3516 Stream Start Success...");
|
// zlog_info(log_video, "eb3516 Stream Start Success...");
|
||||||
|
|
||||||
PAUSE();
|
PAUSE();
|
||||||
|
|
||||||
// SAMPLE_COMM_VENC_StopGetStream();
|
// SAMPLE_COMM_VENC_StopGetStream();
|
||||||
zlog_info(log, "Exit process Sucessfully!");
|
|
||||||
|
|
||||||
|
|
||||||
EXIT_VO_STOP:
|
EXIT_VO_STOP:
|
||||||
SAMPLE_COMM_VO_StopVO(&stVoConfig);
|
SAMPLE_COMM_VO_StopVO(&stVoConfig);
|
||||||
|
@ -287,4 +286,18 @@ EXIT_SYS_STOP:
|
||||||
EXIT_SYS_RST_CLK:
|
EXIT_SYS_RST_CLK:
|
||||||
EXIT:
|
EXIT:
|
||||||
return s32Ret;
|
return s32Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void eb3516VideoStop(void) {
|
||||||
|
SAMPLE_COMM_VO_StopVO(&stVoConfig);
|
||||||
|
SAMPLE_COMM_VENC_Stop(g_VencChn[1]);
|
||||||
|
SAMPLE_COMM_VI_UnBind_VPSS(g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0],
|
||||||
|
g_stViConfig.astViInfo[0].stChnInfo.ViChn,
|
||||||
|
g_stVpss0Config.s32GrpId);
|
||||||
|
SAMPLE_COMM_VPSS_Stop(g_stVpss0Config.s32GrpId,
|
||||||
|
g_stVpss0Config.abChnEnable);
|
||||||
|
SAMPLE_COMM_VI_StopVi(&g_stViConfig);
|
||||||
|
SAMPLE_COMM_SYS_Exit();
|
||||||
|
|
||||||
|
zlog_info(log_video, "Exit process Sucessfully!");
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ extern "C"{
|
||||||
|
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
|
|
||||||
void eb3516VideoInit(void);
|
bool eb3516VideoInit(void);
|
||||||
bool eb3516VideoStart(void);
|
bool eb3516VideoStart(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "zlog.h"
|
#include "zlog.h"
|
||||||
|
|
||||||
#include "isp/eb3516_video.h"
|
#include "isp/eb3516_video.h"
|
||||||
|
#include "nnie/eb3516_nnie.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -35,8 +36,10 @@ int main(int argc, char** argv) {
|
||||||
zlog_warn(log, "Can't Create log dir FOR %s", file_error.message().c_str());
|
zlog_warn(log, "Can't Create log dir FOR %s", file_error.message().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
eb3516VideoInit();
|
// eb3516VideoInit();
|
||||||
eb3516VideoStart();
|
// eb3516VideoStart();
|
||||||
|
eb3516Yolov3Init("./coco_yolov3_detect.wk", "./dog_bike_car_416x416.bgr");
|
||||||
|
eb3516Yolov3Exit();
|
||||||
|
|
||||||
zlog_fini();
|
zlog_fini();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,705 @@
|
||||||
|
#include "eb3516_nnie.h"
|
||||||
|
|
||||||
|
#include "hi_comm_svp.h"
|
||||||
|
#include "hi_comm_sys.h"
|
||||||
|
#include "hi_common.h"
|
||||||
|
#include "sample_comm.h"
|
||||||
|
#include "sample_comm_ive.h"
|
||||||
|
#include "sample_comm_nnie.h"
|
||||||
|
#include "sample_comm_svp.h"
|
||||||
|
#include "sample_svp_nnie_software.h"
|
||||||
|
#include "zlog.h"
|
||||||
|
|
||||||
|
static zlog_category_t *log_nnie = NULL;
|
||||||
|
|
||||||
|
/*yolov3 para*/
|
||||||
|
static SAMPLE_SVP_NNIE_MODEL_S g_stNnieModel = {0};
|
||||||
|
static SAMPLE_SVP_NNIE_PARAM_S g_stNnieParam = {0};
|
||||||
|
static SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S g_stYolov3Param = {0};
|
||||||
|
|
||||||
|
static HI_S32 SAMPLE_SVP_NNIE_Detection_PrintResult(
|
||||||
|
SVP_BLOB_S *pstDstScore, SVP_BLOB_S *pstDstRoi, SVP_BLOB_S *pstClassRoiNum,
|
||||||
|
HI_FLOAT f32PrintResultThresh) {
|
||||||
|
HI_U32 i = 0, j = 0;
|
||||||
|
HI_U32 u32RoiNumBias = 0;
|
||||||
|
HI_U32 u32ScoreBias = 0;
|
||||||
|
HI_U32 u32BboxBias = 0;
|
||||||
|
HI_FLOAT f32Score = 0.0f;
|
||||||
|
HI_S32 *ps32Score =
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstScore->u64VirAddr);
|
||||||
|
HI_S32 *ps32Roi =
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstDstRoi->u64VirAddr);
|
||||||
|
HI_S32 *ps32ClassRoiNum =
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(HI_S32, pstClassRoiNum->u64VirAddr);
|
||||||
|
HI_U32 u32ClassNum = pstClassRoiNum->unShape.stWhc.u32Width;
|
||||||
|
HI_S32 s32XMin = 0, s32YMin = 0, s32XMax = 0, s32YMax = 0;
|
||||||
|
|
||||||
|
u32RoiNumBias += ps32ClassRoiNum[0];
|
||||||
|
for (i = 1; i < u32ClassNum; i++) {
|
||||||
|
u32ScoreBias = u32RoiNumBias;
|
||||||
|
u32BboxBias = u32RoiNumBias * SAMPLE_SVP_NNIE_COORDI_NUM;
|
||||||
|
/*if the confidence score greater than result threshold, the result will
|
||||||
|
* be printed*/
|
||||||
|
if ((HI_FLOAT)ps32Score[u32ScoreBias] / SAMPLE_SVP_NNIE_QUANT_BASE >=
|
||||||
|
f32PrintResultThresh &&
|
||||||
|
ps32ClassRoiNum[i] != 0) {
|
||||||
|
SAMPLE_SVP_TRACE_INFO("==== The %dth class box info====\n", i);
|
||||||
|
}
|
||||||
|
for (j = 0; j < (HI_U32)ps32ClassRoiNum[i]; j++) {
|
||||||
|
f32Score = (HI_FLOAT)ps32Score[u32ScoreBias + j] /
|
||||||
|
SAMPLE_SVP_NNIE_QUANT_BASE;
|
||||||
|
if (f32Score < f32PrintResultThresh) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
s32XMin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM];
|
||||||
|
s32YMin = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 1];
|
||||||
|
s32XMax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 2];
|
||||||
|
s32YMax = ps32Roi[u32BboxBias + j * SAMPLE_SVP_NNIE_COORDI_NUM + 3];
|
||||||
|
SAMPLE_SVP_TRACE_INFO("%d %d %d %d %f\n", s32XMin, s32YMin, s32XMax,
|
||||||
|
s32YMax, f32Score);
|
||||||
|
}
|
||||||
|
u32RoiNumBias += ps32ClassRoiNum[i];
|
||||||
|
}
|
||||||
|
return HI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HI_S32 SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit(
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam) {
|
||||||
|
HI_S32 s32Ret = HI_SUCCESS;
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_RET(NULL == pstSoftWareParam, HI_INVALID_VALUE,
|
||||||
|
SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error, pstSoftWareParam can't be NULL!\n");
|
||||||
|
if (0 != pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr &&
|
||||||
|
0 != pstSoftWareParam->stGetResultTmpBuf.u64VirAddr) {
|
||||||
|
SAMPLE_SVP_MMZ_FREE(pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr,
|
||||||
|
pstSoftWareParam->stGetResultTmpBuf.u64VirAddr);
|
||||||
|
pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = 0;
|
||||||
|
pstSoftWareParam->stGetResultTmpBuf.u64VirAddr = 0;
|
||||||
|
pstSoftWareParam->stDstRoi.u64PhyAddr = 0;
|
||||||
|
pstSoftWareParam->stDstRoi.u64VirAddr = 0;
|
||||||
|
pstSoftWareParam->stDstScore.u64PhyAddr = 0;
|
||||||
|
pstSoftWareParam->stDstScore.u64VirAddr = 0;
|
||||||
|
pstSoftWareParam->stClassRoiNum.u64PhyAddr = 0;
|
||||||
|
pstSoftWareParam->stClassRoiNum.u64VirAddr = 0;
|
||||||
|
}
|
||||||
|
return s32Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HI_S32 SAMPLE_SVP_NNIE_Yolov3_Deinit(
|
||||||
|
SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam,
|
||||||
|
SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel) {
|
||||||
|
HI_S32 s32Ret = HI_SUCCESS;
|
||||||
|
/*hardware deinit*/
|
||||||
|
if (pstNnieParam != NULL) {
|
||||||
|
s32Ret = SAMPLE_COMM_SVP_NNIE_ParamDeinit(pstNnieParam);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_TRACE(
|
||||||
|
HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,SAMPLE_COMM_SVP_NNIE_ParamDeinit failed!\n");
|
||||||
|
}
|
||||||
|
/*software deinit*/
|
||||||
|
if (pstSoftWareParam != NULL) {
|
||||||
|
s32Ret = SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit(pstSoftWareParam);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_TRACE(
|
||||||
|
HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,SAMPLE_SVP_NNIE_Yolov3_SoftwareDeinit failed!\n");
|
||||||
|
}
|
||||||
|
/*model deinit*/
|
||||||
|
if (pstNnieModel != NULL) {
|
||||||
|
s32Ret = SAMPLE_COMM_SVP_NNIE_UnloadModel(pstNnieModel);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_TRACE(
|
||||||
|
HI_SUCCESS != s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,SAMPLE_COMM_SVP_NNIE_UnloadModel failed!\n");
|
||||||
|
}
|
||||||
|
return s32Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HI_S32 SAMPLE_SVP_NNIE_Yolov3_SoftwareInit(
|
||||||
|
SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam) {
|
||||||
|
HI_S32 s32Ret = HI_SUCCESS;
|
||||||
|
HI_U32 u32ClassNum = 0;
|
||||||
|
HI_U32 u32TotalSize = 0;
|
||||||
|
HI_U32 u32DstRoiSize = 0;
|
||||||
|
HI_U32 u32DstScoreSize = 0;
|
||||||
|
HI_U32 u32ClassRoiNumSize = 0;
|
||||||
|
HI_U32 u32TmpBufTotalSize = 0;
|
||||||
|
HI_U64 u64PhyAddr = 0;
|
||||||
|
HI_U8 *pu8VirAddr = NULL;
|
||||||
|
|
||||||
|
pstSoftWareParam->u32OriImHeight =
|
||||||
|
pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Height;
|
||||||
|
pstSoftWareParam->u32OriImWidth =
|
||||||
|
pstNnieParam->astSegData[0].astSrc[0].unShape.stWhc.u32Width;
|
||||||
|
pstSoftWareParam->u32BboxNumEachGrid = 3;
|
||||||
|
pstSoftWareParam->u32ClassNum = 80;
|
||||||
|
pstSoftWareParam->au32GridNumHeight[0] = 13;
|
||||||
|
pstSoftWareParam->au32GridNumHeight[1] = 26;
|
||||||
|
pstSoftWareParam->au32GridNumHeight[2] = 52;
|
||||||
|
pstSoftWareParam->au32GridNumWidth[0] = 13;
|
||||||
|
pstSoftWareParam->au32GridNumWidth[1] = 26;
|
||||||
|
pstSoftWareParam->au32GridNumWidth[2] = 52;
|
||||||
|
pstSoftWareParam->u32NmsThresh =
|
||||||
|
(HI_U32)(0.3f * SAMPLE_SVP_NNIE_QUANT_BASE);
|
||||||
|
pstSoftWareParam->u32ConfThresh =
|
||||||
|
(HI_U32)(0.5f * SAMPLE_SVP_NNIE_QUANT_BASE);
|
||||||
|
pstSoftWareParam->u32MaxRoiNum = 10;
|
||||||
|
pstSoftWareParam->af32Bias[0][0] = 116;
|
||||||
|
pstSoftWareParam->af32Bias[0][1] = 90;
|
||||||
|
pstSoftWareParam->af32Bias[0][2] = 156;
|
||||||
|
pstSoftWareParam->af32Bias[0][3] = 198;
|
||||||
|
pstSoftWareParam->af32Bias[0][4] = 373;
|
||||||
|
pstSoftWareParam->af32Bias[0][5] = 326;
|
||||||
|
pstSoftWareParam->af32Bias[1][0] = 30;
|
||||||
|
pstSoftWareParam->af32Bias[1][1] = 61;
|
||||||
|
pstSoftWareParam->af32Bias[1][2] = 62;
|
||||||
|
pstSoftWareParam->af32Bias[1][3] = 45;
|
||||||
|
pstSoftWareParam->af32Bias[1][4] = 59;
|
||||||
|
pstSoftWareParam->af32Bias[1][5] = 119;
|
||||||
|
pstSoftWareParam->af32Bias[2][0] = 10;
|
||||||
|
pstSoftWareParam->af32Bias[2][1] = 13;
|
||||||
|
pstSoftWareParam->af32Bias[2][2] = 16;
|
||||||
|
pstSoftWareParam->af32Bias[2][3] = 30;
|
||||||
|
pstSoftWareParam->af32Bias[2][4] = 33;
|
||||||
|
pstSoftWareParam->af32Bias[2][5] = 23;
|
||||||
|
|
||||||
|
/*Malloc assist buffer memory*/
|
||||||
|
u32ClassNum = pstSoftWareParam->u32ClassNum + 1;
|
||||||
|
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_RET(
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM !=
|
||||||
|
pstNnieParam->pstModel->astSeg[0].u16DstNum,
|
||||||
|
HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,pstNnieParam->pstModel->astSeg[0].u16DstNum(%d) should be %d!\n",
|
||||||
|
pstNnieParam->pstModel->astSeg[0].u16DstNum,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM);
|
||||||
|
u32TmpBufTotalSize =
|
||||||
|
SAMPLE_SVP_NNIE_Yolov3_GetResultTmpBuf(pstNnieParam, pstSoftWareParam);
|
||||||
|
u32DstRoiSize =
|
||||||
|
SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum *
|
||||||
|
sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
|
||||||
|
u32DstScoreSize = SAMPLE_SVP_NNIE_ALIGN16(
|
||||||
|
u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
|
||||||
|
u32ClassRoiNumSize = SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
|
||||||
|
u32TotalSize = u32TotalSize + u32DstRoiSize + u32DstScoreSize +
|
||||||
|
u32ClassRoiNumSize + u32TmpBufTotalSize;
|
||||||
|
s32Ret = SAMPLE_COMM_SVP_MallocCached("SAMPLE_YOLOV3_INIT", NULL,
|
||||||
|
(HI_U64 *)&u64PhyAddr,
|
||||||
|
(void **)&pu8VirAddr, u32TotalSize);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret, s32Ret,
|
||||||
|
SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,Malloc memory failed!\n");
|
||||||
|
memset(pu8VirAddr, 0, u32TotalSize);
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(u64PhyAddr, (void *)pu8VirAddr, u32TotalSize);
|
||||||
|
|
||||||
|
/*set each tmp buffer addr*/
|
||||||
|
pstSoftWareParam->stGetResultTmpBuf.u64PhyAddr = u64PhyAddr;
|
||||||
|
pstSoftWareParam->stGetResultTmpBuf.u64VirAddr =
|
||||||
|
(HI_U64)((HI_UL)pu8VirAddr);
|
||||||
|
|
||||||
|
/*set result blob*/
|
||||||
|
pstSoftWareParam->stDstRoi.enType = SVP_BLOB_TYPE_S32;
|
||||||
|
pstSoftWareParam->stDstRoi.u64PhyAddr = u64PhyAddr + u32TmpBufTotalSize;
|
||||||
|
pstSoftWareParam->stDstRoi.u64VirAddr =
|
||||||
|
(HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize);
|
||||||
|
pstSoftWareParam->stDstRoi.u32Stride =
|
||||||
|
SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * pstSoftWareParam->u32MaxRoiNum *
|
||||||
|
sizeof(HI_U32) * SAMPLE_SVP_NNIE_COORDI_NUM);
|
||||||
|
pstSoftWareParam->stDstRoi.u32Num = 1;
|
||||||
|
pstSoftWareParam->stDstRoi.unShape.stWhc.u32Chn = 1;
|
||||||
|
pstSoftWareParam->stDstRoi.unShape.stWhc.u32Height = 1;
|
||||||
|
pstSoftWareParam->stDstRoi.unShape.stWhc.u32Width =
|
||||||
|
u32ClassNum * pstSoftWareParam->u32MaxRoiNum *
|
||||||
|
SAMPLE_SVP_NNIE_COORDI_NUM;
|
||||||
|
|
||||||
|
pstSoftWareParam->stDstScore.enType = SVP_BLOB_TYPE_S32;
|
||||||
|
pstSoftWareParam->stDstScore.u64PhyAddr =
|
||||||
|
u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize;
|
||||||
|
pstSoftWareParam->stDstScore.u64VirAddr =
|
||||||
|
(HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize);
|
||||||
|
pstSoftWareParam->stDstScore.u32Stride = SAMPLE_SVP_NNIE_ALIGN16(
|
||||||
|
u32ClassNum * pstSoftWareParam->u32MaxRoiNum * sizeof(HI_U32));
|
||||||
|
pstSoftWareParam->stDstScore.u32Num = 1;
|
||||||
|
pstSoftWareParam->stDstScore.unShape.stWhc.u32Chn = 1;
|
||||||
|
pstSoftWareParam->stDstScore.unShape.stWhc.u32Height = 1;
|
||||||
|
pstSoftWareParam->stDstScore.unShape.stWhc.u32Width =
|
||||||
|
u32ClassNum * pstSoftWareParam->u32MaxRoiNum;
|
||||||
|
|
||||||
|
pstSoftWareParam->stClassRoiNum.enType = SVP_BLOB_TYPE_S32;
|
||||||
|
pstSoftWareParam->stClassRoiNum.u64PhyAddr =
|
||||||
|
u64PhyAddr + u32TmpBufTotalSize + u32DstRoiSize + u32DstScoreSize;
|
||||||
|
pstSoftWareParam->stClassRoiNum.u64VirAddr =
|
||||||
|
(HI_U64)((HI_UL)pu8VirAddr + u32TmpBufTotalSize + u32DstRoiSize +
|
||||||
|
u32DstScoreSize);
|
||||||
|
pstSoftWareParam->stClassRoiNum.u32Stride =
|
||||||
|
SAMPLE_SVP_NNIE_ALIGN16(u32ClassNum * sizeof(HI_U32));
|
||||||
|
pstSoftWareParam->stClassRoiNum.u32Num = 1;
|
||||||
|
pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Chn = 1;
|
||||||
|
pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Height = 1;
|
||||||
|
pstSoftWareParam->stClassRoiNum.unShape.stWhc.u32Width = u32ClassNum;
|
||||||
|
|
||||||
|
return s32Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HI_S32 SAMPLE_SVP_NNIE_Yolov3_ParamInit(
|
||||||
|
SAMPLE_SVP_NNIE_CFG_S *pstCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S *pstSoftWareParam) {
|
||||||
|
HI_S32 s32Ret = HI_SUCCESS;
|
||||||
|
/*init hardware para*/
|
||||||
|
s32Ret = SAMPLE_COMM_SVP_NNIE_ParamInit(pstCfg, pstNnieParam);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_GOTO(
|
||||||
|
HI_SUCCESS != s32Ret, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error(%#x),SAMPLE_COMM_SVP_NNIE_ParamInit failed!\n", s32Ret);
|
||||||
|
|
||||||
|
/*init software para*/
|
||||||
|
s32Ret = SAMPLE_SVP_NNIE_Yolov3_SoftwareInit(pstCfg, pstNnieParam,
|
||||||
|
pstSoftWareParam);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_GOTO(
|
||||||
|
HI_SUCCESS != s32Ret, INIT_FAIL_0, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error(%#x),SAMPLE_SVP_NNIE_Yolov3_SoftwareInit failed!\n", s32Ret);
|
||||||
|
|
||||||
|
return s32Ret;
|
||||||
|
INIT_FAIL_0:
|
||||||
|
s32Ret =
|
||||||
|
SAMPLE_SVP_NNIE_Yolov3_Deinit(pstNnieParam, pstSoftWareParam, NULL);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_RET(
|
||||||
|
HI_SUCCESS != s32Ret, s32Ret, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error(%#x),SAMPLE_SVP_NNIE_Yolov3_Deinit failed!\n", s32Ret);
|
||||||
|
return HI_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HI_S32 SAMPLE_SVP_NNIE_FillSrcData(
|
||||||
|
SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg, SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx) {
|
||||||
|
FILE *fp = NULL;
|
||||||
|
HI_U32 i = 0, j = 0, n = 0;
|
||||||
|
HI_U32 u32Height = 0, u32Width = 0, u32Chn = 0, u32Stride = 0, u32Dim = 0;
|
||||||
|
HI_U32 u32VarSize = 0;
|
||||||
|
HI_S32 s32Ret = HI_SUCCESS;
|
||||||
|
HI_U8 *pu8PicAddr = NULL;
|
||||||
|
HI_U32 *pu32StepAddr = NULL;
|
||||||
|
HI_U32 u32SegIdx = pstInputDataIdx->u32SegIdx;
|
||||||
|
HI_U32 u32NodeIdx = pstInputDataIdx->u32NodeIdx;
|
||||||
|
HI_U32 u32TotalStepNum = 0;
|
||||||
|
|
||||||
|
/*open file*/
|
||||||
|
if (NULL != pstNnieCfg->pszPic) {
|
||||||
|
fp = fopen(pstNnieCfg->pszPic, "rb");
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_RET(NULL == fp, HI_INVALID_VALUE,
|
||||||
|
SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error, open file failed!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*get data size*/
|
||||||
|
if (SVP_BLOB_TYPE_U8 <=
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType &&
|
||||||
|
SVP_BLOB_TYPE_YVU422SP >=
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
|
||||||
|
u32VarSize = sizeof(HI_U8);
|
||||||
|
} else {
|
||||||
|
u32VarSize = sizeof(HI_U32);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*fill src data*/
|
||||||
|
if (SVP_BLOB_TYPE_SEQ_S32 ==
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
|
||||||
|
u32Dim = pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.unShape.stSeq.u32Dim;
|
||||||
|
u32Stride =
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Stride;
|
||||||
|
pu32StepAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_U32, pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.unShape.stSeq.u64VirAddrStep);
|
||||||
|
pu8PicAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_U8,
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr);
|
||||||
|
for (n = 0;
|
||||||
|
n < pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num;
|
||||||
|
n++) {
|
||||||
|
for (i = 0; i < *(pu32StepAddr + n); i++) {
|
||||||
|
s32Ret = fread(pu8PicAddr, u32Dim * u32VarSize, 1, fp);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_GOTO(1 != s32Ret, FAIL,
|
||||||
|
SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,Read image file failed!\n");
|
||||||
|
pu8PicAddr += u32Stride;
|
||||||
|
}
|
||||||
|
u32TotalStepNum += *(pu32StepAddr + n);
|
||||||
|
}
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64PhyAddr,
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_VOID, pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.u64VirAddr),
|
||||||
|
u32TotalStepNum * u32Stride);
|
||||||
|
} else {
|
||||||
|
u32Height = pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.unShape.stWhc.u32Height;
|
||||||
|
u32Width = pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.unShape.stWhc.u32Width;
|
||||||
|
u32Chn = pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.unShape.stWhc.u32Chn;
|
||||||
|
u32Stride =
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Stride;
|
||||||
|
pu8PicAddr = SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_U8,
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64VirAddr);
|
||||||
|
if (SVP_BLOB_TYPE_YVU420SP ==
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].enType) {
|
||||||
|
for (n = 0;
|
||||||
|
n <
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num;
|
||||||
|
n++) {
|
||||||
|
for (i = 0; i < u32Chn * u32Height / 2; i++) {
|
||||||
|
s32Ret = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_GOTO(
|
||||||
|
1 != s32Ret, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,Read image file failed!\n");
|
||||||
|
pu8PicAddr += u32Stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (SVP_BLOB_TYPE_YVU422SP == pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.enType) {
|
||||||
|
for (n = 0;
|
||||||
|
n <
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num;
|
||||||
|
n++) {
|
||||||
|
for (i = 0; i < u32Height * 2; i++) {
|
||||||
|
s32Ret = fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_GOTO(
|
||||||
|
1 != s32Ret, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,Read image file failed!\n");
|
||||||
|
pu8PicAddr += u32Stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (n = 0;
|
||||||
|
n <
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num;
|
||||||
|
n++) {
|
||||||
|
for (i = 0; i < u32Chn; i++) {
|
||||||
|
for (j = 0; j < u32Height; j++) {
|
||||||
|
s32Ret =
|
||||||
|
fread(pu8PicAddr, u32Width * u32VarSize, 1, fp);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_GOTO(
|
||||||
|
1 != s32Ret, FAIL, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,Read image file failed!\n");
|
||||||
|
pu8PicAddr += u32Stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u64PhyAddr,
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_VOID, pstNnieParam->astSegData[u32SegIdx]
|
||||||
|
.astSrc[u32NodeIdx]
|
||||||
|
.u64VirAddr),
|
||||||
|
pstNnieParam->astSegData[u32SegIdx].astSrc[u32NodeIdx].u32Num *
|
||||||
|
u32Chn * u32Height * u32Stride);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return HI_SUCCESS;
|
||||||
|
FAIL:
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return HI_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HI_S32 SAMPLE_SVP_NNIE_Forward(
|
||||||
|
SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S *pstInputDataIdx,
|
||||||
|
SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S *pstProcSegIdx, HI_BOOL bInstant) {
|
||||||
|
HI_S32 s32Ret = HI_SUCCESS;
|
||||||
|
HI_U32 i = 0, j = 0;
|
||||||
|
HI_BOOL bFinish = HI_FALSE;
|
||||||
|
SVP_NNIE_HANDLE hSvpNnieHandle = 0;
|
||||||
|
HI_U32 u32TotalStepNum = 0;
|
||||||
|
SAMPLE_SVP_NIE_PERF_STAT_DEF_VAR()
|
||||||
|
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(
|
||||||
|
pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx]
|
||||||
|
.stTskBuf.u64PhyAddr,
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_VOID, pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx]
|
||||||
|
.stTskBuf.u64VirAddr),
|
||||||
|
pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx]
|
||||||
|
.stTskBuf.u32Size);
|
||||||
|
|
||||||
|
SAMPLE_SVP_NNIE_PERF_STAT_BEGIN()
|
||||||
|
for (i = 0;
|
||||||
|
i < pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].u32DstNum;
|
||||||
|
i++) {
|
||||||
|
if (SVP_BLOB_TYPE_SEQ_S32 ==
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.enType) {
|
||||||
|
for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Num;
|
||||||
|
j++) {
|
||||||
|
u32TotalStepNum +=
|
||||||
|
*(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_U32,
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.unShape.stSeq.u64VirAddrStep) +
|
||||||
|
j);
|
||||||
|
}
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64PhyAddr,
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_VOID, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64VirAddr),
|
||||||
|
u32TotalStepNum *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Stride);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64PhyAddr,
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_VOID, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64VirAddr),
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Num *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.unShape.stWhc.u32Chn *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.unShape.stWhc.u32Height *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Stride);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*set input blob according to node name*/
|
||||||
|
if (pstInputDataIdx->u32SegIdx != pstProcSegIdx->u32SegIdx) {
|
||||||
|
for (i = 0;
|
||||||
|
i <
|
||||||
|
pstNnieParam->pstModel->astSeg[pstProcSegIdx->u32SegIdx].u16SrcNum;
|
||||||
|
i++) {
|
||||||
|
for (j = 0;
|
||||||
|
j < pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx]
|
||||||
|
.u16DstNum;
|
||||||
|
j++) {
|
||||||
|
if (0 == strncmp(pstNnieParam->pstModel
|
||||||
|
->astSeg[pstInputDataIdx->u32SegIdx]
|
||||||
|
.astDstNode[j]
|
||||||
|
.szName,
|
||||||
|
pstNnieParam->pstModel
|
||||||
|
->astSeg[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astSrcNode[i]
|
||||||
|
.szName,
|
||||||
|
SVP_NNIE_NODE_NAME_LEN)) {
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astSrc[i] =
|
||||||
|
pstNnieParam->astSegData[pstInputDataIdx->u32SegIdx]
|
||||||
|
.astDst[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_RET(
|
||||||
|
(j == pstNnieParam->pstModel->astSeg[pstInputDataIdx->u32SegIdx]
|
||||||
|
.u16DstNum),
|
||||||
|
HI_FAILURE, SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,can't find %d-th seg's %d-th src blob!\n",
|
||||||
|
pstProcSegIdx->u32SegIdx, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*NNIE_Forward*/
|
||||||
|
SAMPLE_SVP_NNIE_PERF_STAT_BEGIN()
|
||||||
|
s32Ret = HI_MPI_SVP_NNIE_Forward(
|
||||||
|
&hSvpNnieHandle,
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astSrc,
|
||||||
|
pstNnieParam->pstModel,
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx].astDst,
|
||||||
|
&pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx], bInstant);
|
||||||
|
SAMPLE_SVP_CHECK_EXPR_RET(HI_SUCCESS != s32Ret, s32Ret,
|
||||||
|
SAMPLE_SVP_ERR_LEVEL_ERROR,
|
||||||
|
"Error,HI_MPI_SVP_NNIE_Forward failed!\n");
|
||||||
|
|
||||||
|
if (bInstant) {
|
||||||
|
/*Wait NNIE finish*/
|
||||||
|
while (HI_ERR_SVP_NNIE_QUERY_TIMEOUT ==
|
||||||
|
(s32Ret = HI_MPI_SVP_NNIE_Query(
|
||||||
|
pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx]
|
||||||
|
.enNnieId,
|
||||||
|
hSvpNnieHandle, &bFinish, HI_TRUE))) {
|
||||||
|
usleep(100);
|
||||||
|
SAMPLE_SVP_TRACE(SAMPLE_SVP_ERR_LEVEL_INFO,
|
||||||
|
"HI_MPI_SVP_NNIE_Query Query timeout!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
u32TotalStepNum = 0;
|
||||||
|
|
||||||
|
SAMPLE_SVP_NNIE_PERF_STAT_BEGIN()
|
||||||
|
for (i = 0;
|
||||||
|
i < pstNnieParam->astForwardCtrl[pstProcSegIdx->u32SegIdx].u32DstNum;
|
||||||
|
i++) {
|
||||||
|
if (SVP_BLOB_TYPE_SEQ_S32 ==
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.enType) {
|
||||||
|
for (j = 0; j < pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Num;
|
||||||
|
j++) {
|
||||||
|
u32TotalStepNum +=
|
||||||
|
*(SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_U32,
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.unShape.stSeq.u64VirAddrStep) +
|
||||||
|
j);
|
||||||
|
}
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64PhyAddr,
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_VOID, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64VirAddr),
|
||||||
|
u32TotalStepNum *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Stride);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SAMPLE_COMM_SVP_FlushCache(
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64PhyAddr,
|
||||||
|
SAMPLE_SVP_NNIE_CONVERT_64BIT_ADDR(
|
||||||
|
HI_VOID, pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u64VirAddr),
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Num *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.unShape.stWhc.u32Chn *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.unShape.stWhc.u32Height *
|
||||||
|
pstNnieParam->astSegData[pstProcSegIdx->u32SegIdx]
|
||||||
|
.astDst[i]
|
||||||
|
.u32Stride);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s32Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool eb3516Yolov3Init(const char *model_file, const char *pic_file) {
|
||||||
|
HI_S32 ret = HI_SUCCESS;
|
||||||
|
|
||||||
|
SAMPLE_SVP_NNIE_CFG_S stNnieCfg = {0};
|
||||||
|
SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S stInputDataIdx = {0};
|
||||||
|
SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S stProcSegIdx = {0};
|
||||||
|
HI_FLOAT f32PrintResultThresh = 0.0f;
|
||||||
|
|
||||||
|
/*Set configuration parameter*/
|
||||||
|
f32PrintResultThresh = 0.8f;
|
||||||
|
stNnieCfg.pszPic= pic_file;
|
||||||
|
stNnieCfg.u32MaxInputNum = 1; //max input image num in each batch
|
||||||
|
stNnieCfg.u32MaxRoiNum = 0;
|
||||||
|
stNnieCfg.aenNnieCoreId[0] = SVP_NNIE_ID_0;//set NNIE core
|
||||||
|
|
||||||
|
// Get logger
|
||||||
|
log_nnie = zlog_get_category("eb3516_nnie");
|
||||||
|
if (!log_nnie) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init Sys
|
||||||
|
SAMPLE_COMM_SVP_CheckSysInit();
|
||||||
|
zlog_info(log_nnie, "Sys succeed to init");
|
||||||
|
|
||||||
|
// Load model
|
||||||
|
ret = SAMPLE_COMM_SVP_NNIE_LoadModel((HI_CHAR *)model_file, &g_stNnieModel);
|
||||||
|
if (HI_SUCCESS != ret) {
|
||||||
|
zlog_error(log_nnie, "NNIE failed to load model");
|
||||||
|
goto EXIT_SYS;
|
||||||
|
}
|
||||||
|
zlog_info(log_nnie, "Model succeed to be loaded");
|
||||||
|
|
||||||
|
// Init parameter
|
||||||
|
g_stNnieParam.pstModel = &g_stNnieModel.stModel;
|
||||||
|
ret = SAMPLE_SVP_NNIE_Yolov3_ParamInit(&stNnieCfg, &g_stNnieParam,
|
||||||
|
&g_stYolov3Param);
|
||||||
|
if (HI_SUCCESS != ret) {
|
||||||
|
zlog_error(log_nnie, "NNIE failed to init parameter");
|
||||||
|
goto EXIT_DEINIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read src pic
|
||||||
|
stInputDataIdx.u32SegIdx = 0;
|
||||||
|
stInputDataIdx.u32NodeIdx = 0;
|
||||||
|
ret = SAMPLE_SVP_NNIE_FillSrcData(&stNnieCfg, &g_stNnieParam,
|
||||||
|
&stInputDataIdx);
|
||||||
|
if (HI_SUCCESS != ret) {
|
||||||
|
zlog_error(log_nnie, "NNIE failed to read picture");
|
||||||
|
goto EXIT_DEINIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NNIE Forward
|
||||||
|
stProcSegIdx.u32SegIdx = 0;
|
||||||
|
ret = SAMPLE_SVP_NNIE_Forward(&g_stNnieParam, &stInputDataIdx,
|
||||||
|
&stProcSegIdx, HI_TRUE);
|
||||||
|
if (HI_SUCCESS != ret) {
|
||||||
|
zlog_error(log_nnie, "NNIE failed to start forward");
|
||||||
|
goto EXIT_DEINIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Result
|
||||||
|
ret = SAMPLE_SVP_NNIE_Yolov3_GetResult(&g_stNnieParam, &g_stYolov3Param);
|
||||||
|
if (HI_SUCCESS != ret) {
|
||||||
|
zlog_error(log_nnie, "NNIE failed to get result");
|
||||||
|
goto EXIT_DEINIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print Result
|
||||||
|
(void)SAMPLE_SVP_NNIE_Detection_PrintResult(
|
||||||
|
&g_stYolov3Param.stDstScore, &g_stYolov3Param.stDstRoi,
|
||||||
|
&g_stYolov3Param.stClassRoiNum, f32PrintResultThresh);
|
||||||
|
|
||||||
|
EXIT_DEINIT:
|
||||||
|
SAMPLE_SVP_NNIE_Yolov3_Deinit(&g_stNnieParam, &g_stYolov3Param,
|
||||||
|
&g_stNnieModel);
|
||||||
|
EXIT_SYS:
|
||||||
|
SAMPLE_COMM_SVP_CheckSysExit();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void eb3516Yolov3Exit(void) {
|
||||||
|
SAMPLE_SVP_NNIE_Yolov3_Deinit(&g_stNnieParam, &g_stYolov3Param,
|
||||||
|
&g_stNnieModel);
|
||||||
|
memset(&g_stNnieParam, 0, sizeof(SAMPLE_SVP_NNIE_PARAM_S));
|
||||||
|
memset(&g_stYolov3Param, 0,
|
||||||
|
sizeof(SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S));
|
||||||
|
memset(&g_stNnieModel, 0, sizeof(SAMPLE_SVP_NNIE_MODEL_S));
|
||||||
|
SAMPLE_COMM_SVP_CheckSysExit();
|
||||||
|
|
||||||
|
zlog_info(log_nnie, "Yolov3 Exit Successfully");
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef __EB3516_NNIE_H__
|
||||||
|
#define __EB3516_NNIE_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool eb3516Yolov3Init(const char *model_file, const char *pic_file);
|
||||||
|
void eb3516Yolov3Exit(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,134 @@
|
||||||
|
#ifndef _SAMPLE_SVP_USER_KERNEL_H_
|
||||||
|
#define _SAMPLE_SVP_USER_KERNEL_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "hi_comm_svp.h"
|
||||||
|
#include "hi_nnie.h"
|
||||||
|
#include "mpi_nnie.h"
|
||||||
|
#include "sample_comm_svp.h"
|
||||||
|
#include "sample_comm_nnie.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define SAMPLE_SVP_NNIE_ADDR_ALIGN_16 16 /*16 byte alignment*/
|
||||||
|
#define SAMPLE_SVP_NNIE_MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#define SAMPLE_SVP_NNIE_MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#define SAMPLE_SVP_NNIE_SIGMOID(x) (HI_FLOAT)(1.0f/(1+exp(-x)))
|
||||||
|
|
||||||
|
#define SAMPLE_SVP_NNIE_COORDI_NUM 4 /*coordinate numbers*/
|
||||||
|
#define SAMPLE_SVP_NNIE_PROPOSAL_WIDTH 6 /*the number of proposal values*/
|
||||||
|
#define SAMPLE_SVP_NNIE_QUANT_BASE 4096 /*the base value*/
|
||||||
|
#define SAMPLE_SVP_NNIE_SCORE_NUM 2 /*the num of RPN scores*/
|
||||||
|
#define SAMPLE_SVP_NNIE_HALF 0.5f /*the half value*/
|
||||||
|
#define SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM 3 /*yolov3 report blob num*/
|
||||||
|
#define SAMPLE_SVP_NNIE_YOLOV3_EACH_GRID_BIAS_NUM 6 /*yolov3 bias num of each grid*/
|
||||||
|
#define SAMPLE_SVP_NNIE_YOLOV3_EACH_BBOX_INFER_RESULT_NUM 85 /*yolov3 inference result num of each bbox*/
|
||||||
|
|
||||||
|
/*CNN GetTopN unit*/
|
||||||
|
typedef struct hiSAMPLE_SVP_NNIE_CNN_GETTOPN_UNIT_S
|
||||||
|
{
|
||||||
|
HI_U32 u32ClassId;
|
||||||
|
HI_U32 u32Confidence;
|
||||||
|
}SAMPLE_SVP_NNIE_CNN_GETTOPN_UNIT_S;
|
||||||
|
|
||||||
|
/*stack for sort*/
|
||||||
|
typedef struct hiSAMPLE_SVP_NNIE_STACK
|
||||||
|
{
|
||||||
|
HI_S32 s32Min;
|
||||||
|
HI_S32 s32Max;
|
||||||
|
}SAMPLE_SVP_NNIE_STACK_S;
|
||||||
|
|
||||||
|
/*stack for sort*/
|
||||||
|
typedef struct hiSAMPLE_SVP_NNIE_YOLOV1_SCORE
|
||||||
|
{
|
||||||
|
HI_U32 u32Idx;
|
||||||
|
HI_S32 s32Score;
|
||||||
|
}SAMPLE_SVP_NNIE_YOLOV1_SCORE_S;
|
||||||
|
|
||||||
|
typedef struct hiSAMPLE_SVP_NNIE_YOLOV2_BBOX
|
||||||
|
{
|
||||||
|
HI_FLOAT f32Xmin;
|
||||||
|
HI_FLOAT f32Xmax;
|
||||||
|
HI_FLOAT f32Ymin;
|
||||||
|
HI_FLOAT f32Ymax;
|
||||||
|
HI_S32 s32ClsScore;
|
||||||
|
HI_U32 u32ClassIdx;
|
||||||
|
HI_U32 u32Mask;
|
||||||
|
}SAMPLE_SVP_NNIE_YOLOV2_BBOX_S;
|
||||||
|
|
||||||
|
typedef SAMPLE_SVP_NNIE_YOLOV2_BBOX_S SAMPLE_SVP_NNIE_YOLOV3_BBOX_S;
|
||||||
|
|
||||||
|
/*CNN*/
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Cnn_GetTopN(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
/*FasterRcnn*/
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_RpnTmpBufSize(HI_U32 u32RatioAnchorsNum,
|
||||||
|
HI_U32 u32ScaleAnchorsNum, HI_U32 u32ConvHeight, HI_U32 u32ConvWidth);
|
||||||
|
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_FasterRcnn_GetResultTmpBufSize(
|
||||||
|
HI_U32 u32MaxRoiNum, HI_U32 u32ClassNum);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_Rpn(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_FasterRcnn_GetResult(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
|
||||||
|
/*Pvanet*/
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_Pvanet_GetResultTmpBufSize(
|
||||||
|
HI_U32 u32MaxRoiNum, HI_U32 u32ClassNum);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Pvanet_Rpn(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Pvanet_GetResult(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
/*RFCN*/
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_Rfcn_GetResultTmpBuf(HI_U32 u32MaxRoiNum, HI_U32 u32ClassNum);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Rfcn_Rpn(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Rfcn_GetResult(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
/*SSD*/
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_Ssd_GetResultTmpBuf(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Ssd_GetResult(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
/*YOLOV1*/
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_Yolov1_GetResultTmpBuf(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Yolov1_GetResult(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
/*YOLOV2*/
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_Yolov2_GetResultTmpBuf(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Yolov2_GetResult(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
/*YOLOV3*/
|
||||||
|
HI_U32 SAMPLE_SVP_NNIE_Yolov3_GetResultTmpBuf(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
|
||||||
|
HI_S32 SAMPLE_SVP_NNIE_Yolov3_GetResult(SAMPLE_SVP_NNIE_PARAM_S*pstNnieParam,
|
||||||
|
SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S* pstSoftwareParam);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SAMPLE_SVP_USER_KERNEL_H_ */
|
79
xmake.lua
79
xmake.lua
|
@ -12,11 +12,18 @@ target("ISP")
|
||||||
add_deps("sample_common")
|
add_deps("sample_common")
|
||||||
add_packages("zlog")
|
add_packages("zlog")
|
||||||
|
|
||||||
|
target("NNIE")
|
||||||
|
set_kind("static")
|
||||||
|
add_files("src/nnie/*.c")
|
||||||
|
add_includedirs("src")
|
||||||
|
add_deps("sample_common","sample_svp")
|
||||||
|
add_packages("zlog")
|
||||||
|
|
||||||
target("CatFeeder")
|
target("CatFeeder")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_includedirs("src")
|
add_includedirs("src")
|
||||||
add_files("src/*.cpp")
|
add_files("src/*.cpp")
|
||||||
add_deps("hi_library", "ISP")
|
add_deps("hi_library", "ISP", "NNIE")
|
||||||
add_packages("zlog")
|
add_packages("zlog")
|
||||||
add_links("stdc++fs")
|
add_links("stdc++fs")
|
||||||
after_build(function (target)
|
after_build(function (target)
|
||||||
|
@ -28,73 +35,3 @@ if is_mode("debug") then
|
||||||
set_symbols("debug")
|
set_symbols("debug")
|
||||||
set_optimize("none")
|
set_optimize("none")
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
|
||||||
-- If you want to known more usage about xmake, please see https://xmake.io
|
|
||||||
--
|
|
||||||
-- ## FAQ
|
|
||||||
--
|
|
||||||
-- You can enter the project directory firstly before building project.
|
|
||||||
--
|
|
||||||
-- $ cd projectdir
|
|
||||||
--
|
|
||||||
-- 1. How to build project?
|
|
||||||
--
|
|
||||||
-- $ xmake
|
|
||||||
--
|
|
||||||
-- 2. How to configure project?
|
|
||||||
--
|
|
||||||
-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
|
|
||||||
--
|
|
||||||
-- 3. Where is the build output directory?
|
|
||||||
--
|
|
||||||
-- The default output directory is `./build` and you can configure the output directory.
|
|
||||||
--
|
|
||||||
-- $ xmake f -o outputdir
|
|
||||||
-- $ xmake
|
|
||||||
--
|
|
||||||
-- 4. How to run and debug target after building project?
|
|
||||||
--
|
|
||||||
-- $ xmake run [targetname]
|
|
||||||
-- $ xmake run -d [targetname]
|
|
||||||
--
|
|
||||||
-- 5. How to install target to the system directory or other output directory?
|
|
||||||
--
|
|
||||||
-- $ xmake install
|
|
||||||
-- $ xmake install -o installdir
|
|
||||||
--
|
|
||||||
-- 6. Add some frequently-used compilation flags in xmake.lua
|
|
||||||
--
|
|
||||||
-- @code
|
|
||||||
-- -- add debug and release modes
|
|
||||||
-- add_rules("mode.debug", "mode.release")
|
|
||||||
--
|
|
||||||
-- -- add macro definition
|
|
||||||
-- add_defines("NDEBUG", "_GNU_SOURCE=1")
|
|
||||||
--
|
|
||||||
-- -- set warning all as error
|
|
||||||
-- set_warnings("all", "error")
|
|
||||||
--
|
|
||||||
-- -- set language: c99, c++11
|
|
||||||
-- set_languages("c99", "c++11")
|
|
||||||
--
|
|
||||||
-- -- set optimization: none, faster, fastest, smallest
|
|
||||||
-- set_optimize("fastest")
|
|
||||||
--
|
|
||||||
-- -- add include search directories
|
|
||||||
-- add_includedirs("/usr/include", "/usr/local/include")
|
|
||||||
--
|
|
||||||
-- -- add link libraries and search directories
|
|
||||||
-- add_links("tbox")
|
|
||||||
-- add_linkdirs("/usr/local/lib", "/usr/lib")
|
|
||||||
--
|
|
||||||
-- -- add system link libraries
|
|
||||||
-- add_syslinks("z", "pthread")
|
|
||||||
--
|
|
||||||
-- -- add compilation and link flags
|
|
||||||
-- add_cxflags("-stdnolib", "-fno-strict-aliasing")
|
|
||||||
-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
|
|
||||||
--
|
|
||||||
-- @endcode
|
|
||||||
--
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue