HumanParsing.cpp
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "HumanParsing.h"
HumanParsing::HumanParsing(/* args */)
{
}
HumanParsing::~HumanParsing()
{
release();
}
int HumanParsing::init(int dev_id, string model_dir){
string model_path = model_dir + "/models/hp2/hp220908_310p.om" ;
LOG_INFO("hp 版本:{} 模型路径:{}", hp_get_version(), model_path);
hp_param param;
char modelNames[100];
strcpy(modelNames, model_path.c_str());
param.modelNames = modelNames;
param.devId = dev_id;
m_devId = param.devId;
ACL_CALL(aclrtSetDevice(m_devId), ACL_SUCCESS, -1);
ACL_CALL(aclrtCreateContext(&m_algorthim_ctx, m_devId), ACL_SUCCESS, -1);
int ret = hp_init(&m_handle, param);
if(ret != 0){
LOG_ERROR("vpt init error.");
return -1;
}
return 0;
}
vector<hp_analysis_res> HumanParsing::process(vector<DeviceMemory*> vec_gpuMem) {
int batchsize = vec_gpuMem.size();
vector<sy_img> batch_img;
for (int i = 0; i < batchsize; i++) {
DeviceMemory* mem = vec_gpuMem[i];
sy_img img;
img.w_ = mem->getWidth();
img.h_ = mem->getHeight();
img.data_ = mem->getMem();
batch_img.push_back(img);
}
int ret = aclrtSetCurrentContext(m_algorthim_ctx);
vector<hp_analysis_res> vec_result;
vec_result.resize(batchsize);
ret = hp_batch(m_handle, batch_img.data(), batchsize, vec_result.data());
if (SY_SUCCESS != ret) {
printf("HumanCarParse process failed!");
return vec_result;
}
return vec_result;
}
void HumanParsing::release(){
if (m_handle){
hp_release(&m_handle);
m_handle = NULL;
}
if(m_algorthim_ctx){
aclrtDestroyContext(m_algorthim_ctx);
m_algorthim_ctx = nullptr;
}
}