未验证 提交 246502b1 编写于 作者: G gaojinwei01 提交者: GitHub

update yolov5s_timvx example to v6.0 && update EAIS-750E compile manual (#1342)

* update EAIS-750E compile manul

* update yolov5s_timvx example to v6.0 version
上级 f7c7c98a
......@@ -244,32 +244,11 @@ $ cp -rf ../TIM-VX/include ./source/device/tim-vx/
$ cp -rf ../TIM-VX/src ./source/device/tim-vx/
```
\- 准备编译环境 编译依赖的系统库在EAIS-750E板载/usr/lib/下能搜索到,因此只需要拷贝头文件
```bash
$ wget -c https://github.com/VeriSilicon/TIM-VX/releases/download/v1.1.28/aarch64_A311D_D312513_A294074_R311680_T312233_O312045.tgz
$ tar zxvf aarch64_A311D_D312513_A294074_R311680_T312233_O312045.tgz
$ mv aarch64_A311D_D312513_A294074_R311680_T312233_O312045 prebuild-sdk-a311d
$ cd <tengine-lite-root-dir>
$ mkdir -p ./3rdparty/tim-vx/include
$ mkdir -p ./3rdparty/tim-vx/lib/aarch64
$ cp -rf ../prebuild-sdk-a311d/include/* ./3rdparty/tim-vx/include/
```
\- 如遇到cmake版本不够,更新板子上的cmake版本
```bash
$ sudo apt-get autoremove cmake
$ wget https://cmake.org/files/v3.22/cmake-3.22.0-linux-aarch64.tar.gz
$ tar -xzvf cmake-3.22.0-linux-aarch64.tar.gz
$ sudo mv cmake-3.22.0-linux-aarch64 /opt/cmake-3.22
$ ln -sf /opt/cmake-3.22/bin/* /usr/bin/
$ cmake --version
```
\- 编译Tengine
```bash
$ cd <tengine-lite-root-dir>
$ mkdir build && cd build
$ cmake -DTENGINE_ENABLE_TIM_VX=ON ..
$ cmake -DTENGINE_ENABLE_TIM_VX=ON -DTENGINE_ENABLE_MODEL_CACHE=ON ..
$ make -j`nproc` && make install
```
......
......@@ -37,6 +37,8 @@
#include "tengine/c_api.h"
#include "tengine_operations.h"
#define YOLOV5_VERSION6 0
struct Object
{
cv::Rect_<float> rect;
......@@ -341,6 +343,69 @@ void get_input_data_focus_uint8(const char* image_file, uint8_t* input_data, int
}
}
void get_input_data_nofocus_uint8(const char* image_file, uint8_t* input_data, int letterbox_rows, int letterbox_cols, const float* mean,
const float* scale, float input_scale, int zero_point)
{
cv::Mat sample = cv::imread(image_file, 1);
cv::Mat img;
if (sample.channels() == 1)
cv::cvtColor(sample, img, cv::COLOR_GRAY2RGB);
else
cv::cvtColor(sample, img, cv::COLOR_BGR2RGB);
/* letterbox process to support different letterbox size */
float scale_letterbox;
int resize_rows;
int resize_cols;
if ((letterbox_rows * 1.0 / img.rows) < (letterbox_cols * 1.0 / img.cols))
{
scale_letterbox = letterbox_rows * 1.0 / img.rows;
}
else
{
scale_letterbox = letterbox_cols * 1.0 / img.cols;
}
resize_cols = int(scale_letterbox * img.cols);
resize_rows = int(scale_letterbox * img.rows);
cv::resize(img, img, cv::Size(resize_cols, resize_rows));
img.convertTo(img, CV_32FC3);
// Generate a gray image for letterbox using opencv
cv::Mat img_new(letterbox_cols, letterbox_rows, CV_32FC3, cv::Scalar(0.5 / scale[0] + mean[0], 0.5 / scale[1] + mean[1], 0.5 / scale[2] + mean[2]));
int top = (letterbox_rows - resize_rows) / 2;
int bot = (letterbox_rows - resize_rows + 1) / 2;
int left = (letterbox_cols - resize_cols) / 2;
int right = (letterbox_cols - resize_cols + 1) / 2;
// Letterbox filling
cv::copyMakeBorder(img, img_new, top, bot, left, right, cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0));
img_new.convertTo(img_new, CV_32FC3);
float* img_data = (float*)img_new.data;
/* nhwc to nchw */
for (int h = 0; h < letterbox_rows; h++)
{
for (int w = 0; w < letterbox_cols; w++)
{
for (int c = 0; c < 3; c++)
{
int in_index = h * letterbox_cols * 3 + w * 3 + c;
int out_index = c * letterbox_rows * letterbox_cols + h * letterbox_cols + w;
int udata = (round)((img_data[in_index] - mean[c]) * scale[c] / input_scale + (float)zero_point);
if (udata > 255)
udata = 255;
else if (udata < 0)
udata = 0;
input_data[out_index] = udata;
}
}
}
}
int main(int argc, char* argv[])
{
const char* model_file = nullptr;
......@@ -439,7 +504,11 @@ int main(int argc, char* argv[])
}
int img_size = letterbox_rows * letterbox_cols * img_c;
#if YOLOV5_VERSION6
int dims[] = {1, 3, letterbox_rows, letterbox_cols};
#else
int dims[] = {1, 12, int(letterbox_rows / 2), int(letterbox_cols / 2)};
#endif
std::vector<uint8_t> input_data(img_size);
tensor_t input_tensor = get_graph_input_tensor(graph, 0, 0);
......@@ -472,7 +541,13 @@ int main(int argc, char* argv[])
float input_scale = 0.f;
int input_zero_point = 0;
get_tensor_quant_param(input_tensor, &input_scale, &input_zero_point, 1);
get_input_data_focus_uint8(image_file, input_data.data(), letterbox_rows, letterbox_cols, mean, scale, input_scale, input_zero_point);
#if YOLOV5_VERSION6
get_input_data_nofocus_uint8(image_file, input_data.data(), letterbox_rows, letterbox_cols, mean, scale, input_scale, input_zero_point);
#else
get_input_data_focus_uint8(image_file, input_data.data(), letterbox_rows, letterbox_cols, mean, scale,input_scale, input_zero_point);
#endif
/* run graph */
double min_time = DBL_MAX;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册