Commit 15756629c3214fb8bb87eb61e3a35cb2b97ca1ef

Authored by Hu Chunming
1 parent f3d83919

添加clothes算法

src/PicAnalysis.cpp
... ... @@ -27,9 +27,13 @@ int PicAnalysis::init(int dev_id) {
27 27 return -1;
28 28 }
29 29  
30   - ACL_CALL(aclrtCreateContext(&m_ctx, 0), ACL_ERROR_NONE, SY_FAILED);
31   - ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
  30 + ret = m_clothes_algorithm.init(dev_id);
  31 + if(0 != ret){
  32 + return -1;
  33 + }
32 34  
  35 + ACL_CALL(aclrtCreateContext(&m_ctx, 0), ACL_ERROR_NONE, SY_FAILED);
  36 + ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
33 37 ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED);
34 38 m_dvpp = new DvppProcess();
35 39 m_dvpp->InitResource(stream);
... ... @@ -39,6 +43,8 @@ int PicAnalysis::init(int dev_id) {
39 43  
40 44 int PicAnalysis::analysis_sync(vector<string> vec_file_path){
41 45  
  46 + ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
  47 +
42 48 const int batch_size = vec_file_path.size();
43 49  
44 50 vector<sy_img> vec_img;
... ... @@ -71,7 +77,7 @@ int PicAnalysis::analysis_sync(vector&lt;string&gt; vec_file_path){
71 77 vec_img.push_back(img);
72 78 }
73 79  
74   - // m_vehicle_analysis.detect(vec_img);
  80 + m_vehicle_analysis.detect(vec_img);
75 81  
76 82 vector<HeadTailResult> head_tail_result;
77 83 ret = m_head_tail_algorithm.detect(vec_img, head_tail_result);
... ... @@ -79,6 +85,8 @@ int PicAnalysis::analysis_sync(vector&lt;string&gt; vec_file_path){
79 85 LOG_ERROR("m_head_tail_algorithm failed!");
80 86 head_tail_result.clear();
81 87 }
  88 +
  89 + m_clothes_algorithm.detect(vec_img);
82 90  
83 91  
84 92 return 0;
... ...
src/PicAnalysis.h
1 1 #include "./ai_engine_module/include.h"
2 2 #include "./ai_engine_module/VehicleAnalysis.h"
3 3 #include "./ai_engine_module/VehicleHeadTail.h"
  4 +#include "./ai_engine_module/VidClothes.h"
4 5  
5 6 using namespace std;
6 7  
... ... @@ -25,6 +26,7 @@ private:
25 26  
26 27 VehicleAnalysis m_vehicle_analysis;
27 28 VehicleHeadTail m_head_tail_algorithm;
  29 + VidClothes m_clothes_algorithm;
28 30 };
29 31  
30 32  
... ...
src/ai_engine_module/VehicleAnalysis.cpp
... ... @@ -57,13 +57,12 @@ int VehicleAnalysis::init(int devId, int max_batch_size) {
57 57 param.models_Path="./models/vehicle_analysis/"; //所有模型的地址
58 58  
59 59 cout << "va_init start " << endl;
  60 + // 内部有 ctx
60 61 int ret = va_init(&m_handle, param);
61 62 if (ret != 0) {
62 63 return -1;
63 64 }
64 65  
65   - ACL_CALL(aclrtCreateContext(&ctx, devId), ACL_ERROR_NONE, SY_FAILED);
66   -
67 66 cout << "va_init success " << endl;
68 67 return 0;
69 68 }
... ... @@ -83,7 +82,6 @@ int VehicleAnalysis::detect(vector&lt;sy_img&gt; vec_img) {
83 82 }
84 83 }
85 84  
86   - ACL_CALL(aclrtSetCurrentContext(ctx), ACL_ERROR_NONE, SY_FAILED);
87 85 int ret = va_batch(m_handle, vec_img.data(), batch_size, result);
88 86  
89 87 for (int b = 0; b < batch_size; b++)
... ... @@ -615,13 +613,7 @@ int VehicleAnalysis::detect(vector&lt;sy_img&gt; vec_img) {
615 613 }
616 614  
617 615 void VehicleAnalysis::release(){
618   - if(ctx){
619   - aclrtSetCurrentContext(ctx);
620   - aclrtDestroyContext(ctx);
621   - }
622   -
623 616 if (m_handle) {
624 617 va_release(&m_handle);
625 618 }
626   -
627 619 }
... ...
src/ai_engine_module/VehicleAnalysis.h
... ... @@ -27,8 +27,6 @@ private:
27 27  
28 28 float m_threshold;
29 29 int m_max_batchsize{1};
30   -
31   - aclrtContext ctx{nullptr};
32 30 };
33 31  
34 32  
... ...
src/ai_engine_module/VidClothes.cpp 0 → 100644
  1 +#include "VidClothes.h"
  2 +
  3 +VidClothes::VidClothes(/* args */)
  4 +{
  5 +}
  6 +
  7 +VidClothes::~VidClothes()
  8 +{
  9 + release();
  10 +}
  11 +
  12 +int VidClothes::init(int devId){
  13 + ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
  14 +
  15 + vidclothes_param param;
  16 + param.modelNames = "./models/vid_clothes/vidClothes0325_310P.om";
  17 + param.thresld = 0.0;
  18 + param.devId = 0;
  19 +
  20 + cout << "vidclothes_init start " << endl;
  21 + int ret = vidclothes_init(&m_handle, param);
  22 + if (ret != 0) {
  23 + return -1;
  24 + }
  25 +
  26 + cout << "vidclothes_init success " << endl;
  27 +
  28 + return SY_SUCCESS;
  29 +}
  30 +
  31 +int VidClothes::detect(vector<sy_img> vec_img){
  32 +
  33 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  34 +
  35 + const int batchsize = vec_img.size();
  36 + vidclothes_result * results = new vidclothes_result[batchsize];
  37 +
  38 + int ret = SY_FAILED;
  39 +
  40 + do
  41 + {
  42 + ret = vidclothes_batch(m_handle, vec_img.data(), batchsize, results);
  43 + if (SY_SUCCESS != ret) {
  44 + printf("vidclothesClassification process failed!");
  45 + break;
  46 + }
  47 +
  48 + for(int batchIdx = 0;batchIdx<batchsize;batchIdx++) {
  49 + printf("index:%d,confidence:%f\n",results[batchIdx].index,results[batchIdx].score);
  50 + }
  51 + } while (0);
  52 +
  53 + if (results) {
  54 + delete [] results;
  55 + }
  56 +
  57 + return ret;
  58 +}
  59 +
  60 +void VidClothes::release() {
  61 + if(ctx){
  62 + aclrtSetCurrentContext(ctx);
  63 + aclrtDestroyContext(ctx);
  64 + }
  65 +
  66 + if (m_handle) {
  67 + vidclothes_release(&m_handle);
  68 + }
  69 +}
0 70 \ No newline at end of file
... ...
src/ai_engine_module/VidClothes.h 0 → 100644
  1 +#include "include.h"
  2 +#include "vid_clothes.h"
  3 +
  4 +class VidClothes
  5 +{
  6 +private:
  7 + /* data */
  8 +public:
  9 + VidClothes(/* args */);
  10 + ~VidClothes();
  11 +
  12 + int init(int devId);
  13 +
  14 + int detect(vector<sy_img> vec_img);
  15 +
  16 +private:
  17 + void release();
  18 +
  19 +private:
  20 + void* m_handle{nullptr};
  21 + aclrtContext ctx{nullptr};
  22 +};
  23 +
... ...