资源简介
用C++重新封装了一下NNIE的代码。把sample里面大部分的那坨垃圾代码全部弃用了,主要贡献如下,代码量是sample代码的几十分之一,结构清晰简单易懂
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “ins_nnie_interface.h“
#include “Tensor.h“
#include “util.h“
#include “opencv2/highgui.hpp“
#include “opencv2/imgproc.hpp“
#include “opencv2/core.hpp“
#include “opencv2/dnn.hpp“
/******************************************************************************
* function : show usage
******************************************************************************/
void Usage(char *pchPrgName)
{
printf(“Usage : %s \n“ pchPrgName);
printf(“index:\n“);
printf(“\t 1) Yolov3(Read File).\n“);
printf(“\t 2) Yolov2(Read File).\n“);
}
void yolov2DetectDemo(const char *model_path const char *image_path)
{
NNIE yolov2;
yolov2.init(model_path);
printf(“yolov2 start\n“);
struct timeval tv1;
struct timeval tv2;
long t1 t2 time;
unsigned char *data = (unsigned char *)malloc(sizeof(unsigned char) * 240 * 80 * 3);
cv::Mat img = cv::imread(image_path);
cv::resize(img img cv::Size(240 80));
int step = img.step;
int h = img.rows;
int w = img.cols;
int c = img.channels();
printf(“h=%d\n“ h);
printf(“w=%d\n“ w);
printf(“c=%d\n“ c);
unsigned char *data1 = (unsigned char *)img.data;
int count = 0;
for (int k = 0; k < c; k++)
{
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
data[count++] = data1[i * step + j * c + k];
}
}
}
gettimeofday(&tv1 NULL);
yolov2.run(data);
gettimeofday(&tv2 NULL);
t1 = tv2.tv_sec - tv1.tv_sec;
t2 = tv2.tv_usec - tv1.tv_usec;
time = (long)(t1 * 1000 + t2 / 1000);
printf(“yolov2 NNIE inference time : %dms\n“ time);
gettimeofday(&tv1 NULL);
Tensor output0 = yolov2.getOutputTensor(0);
printf(“%d\n“ output0.width);
printf(“%d\n“ output0.height);
printf(“%d\n“ output0.channel);
/*yolov2的参数*/
int img_width = 240;
int img_height = 80;
int num_classes = 35;
int kBoxPerCell = 2;
int feature_index0 = 0;
int feature_index1 = 1;
int feature_index2 = 2;
float conf_threshold = 0.2;
float nms_threshold = 0.2;
int is_nms = 1;
std::vector ids;
std::vector boxes;
std::vector confidences;
const std::vector> anchors = {
{{3.638 5.409} {3.281 4.764}}};
parseYolov2Feature(img_width
img_height
num_classes
kBoxPerCell
feature_index0
conf_threshold
anchors[0]
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-04-01 09:14 nnie-master\
文件 1601 2020-04-01 09:14 nnie-master\Makefile
文件 946 2020-04-01 09:14 nnie-master\README.md
目录 0 2020-04-01 09:14 nnie-master\data\
目录 0 2020-04-01 09:14 nnie-master\data\nnie_image\
目录 0 2020-04-01 09:14 nnie-master\data\nnie_image\test\
文件 519168 2020-04-01 09:14 nnie-master\data\nnie_image\test\dog_bike_car.bgr
目录 0 2020-04-01 09:14 nnie-master\data\nnie_model\
目录 0 2020-04-01 09:14 nnie-master\data\nnie_model\detection\
文件 62936560 2020-04-01 09:14 nnie-master\data\nnie_model\detection\inst_yolov3_cycle.wk
目录 0 2020-04-01 09:14 nnie-master\sample\
文件 13049 2020-04-01 09:14 nnie-master\sample\sample_nnie_main.cpp
目录 0 2020-04-01 09:14 nnie-master\src\
文件 208 2020-04-01 09:14 nnie-master\src\Tensor.h
文件 1389 2020-04-01 09:14 nnie-master\src\ins_nnie_interface.cpp
文件 1222 2020-04-01 09:14 nnie-master\src\ins_nnie_interface.h
文件 16469 2020-04-01 09:14 nnie-master\src\nnie_core.c
文件 1594 2020-04-01 09:14 nnie-master\src\nnie_core.h
文件 23141 2020-04-01 09:14 nnie-master\src\sample_comm.h
文件 23497 2020-04-01 09:14 nnie-master\src\sample_comm_nnie.c
文件 11216 2020-04-01 09:14 nnie-master\src\sample_comm_nnie.h
文件 25121 2020-04-01 09:14 nnie-master\src\sample_comm_svp.c
文件 7857 2020-04-01 09:14 nnie-master\src\sample_comm_svp.h
文件 10961 2020-04-01 09:14 nnie-master\src\util.h
目录 0 2020-04-01 09:14 nnie-master\third_party\
目录 0 2020-04-01 09:14 nnie-master\third_party\hisi\
目录 0 2020-04-01 09:14 nnie-master\third_party\hisi\include\
文件 8341 2020-04-01 09:14 nnie-master\third_party\hisi\include\aacdec.h
文件 5967 2020-04-01 09:14 nnie-master\third_party\hisi\include\aacenc.h
文件 7694 2020-04-01 09:14 nnie-master\third_party\hisi\include\acodec.h
目录 0 2020-04-01 09:14 nnie-master\third_party\hisi\include\adapt\
............此处省略600个文件信息
评论
共有 条评论