Commit d708ccb3e30e89f83f664d6005da98d794857363
1 parent
a6115242
增加日志
Showing
9 changed files
with
162 additions
and
204 deletions
algorithm/vehicle_analysis/vehicle_analysis.h
... | ... | @@ -18,13 +18,10 @@ |
18 | 18 | #define VEHICLEANALYSIS_API __attribute__ ((visibility ("default"))) |
19 | 19 | #endif |
20 | 20 | |
21 | -#ifdef __cplusplus | |
22 | -extern "C" | |
23 | -{ | |
24 | -#endif | |
25 | 21 | |
26 | 22 | #include "sy_common.h" //通用数据结构体定义 |
27 | 23 | #include "vehicle_result.h" //车辆分析结果结构体定义 |
24 | +#include <string> | |
28 | 25 | |
29 | 26 | |
30 | 27 | #ifndef __VEHICLE_INFO__ |
... | ... | @@ -109,7 +106,11 @@ extern "C" |
109 | 106 | float vc_thresld=0.5; //车颜色阈值 |
110 | 107 | char* dbPath; //车型识别车型数据路路径 <当前仅支持英文路径> |
111 | 108 | char* models_Path; //所有模型的路径 <当前仅支持英文路径>//20210615 |
112 | - | |
109 | + | |
110 | + int log_level{2}; | |
111 | + int log_days{30}; //日志保存周期 | |
112 | + std::string log_path{"logs"}; //日志文件路径 | |
113 | + unsigned long log_mem{64 * 1024 * 1024}; //每个日志最大大小 | |
113 | 114 | }va_param; |
114 | 115 | #endif |
115 | 116 | |
... | ... | @@ -188,11 +189,5 @@ extern "C" |
188 | 189 | *************************************************************************/ |
189 | 190 | VEHICLEANALYSIS_API float va_compute_similarity_byvafeature(void * handle , float *Afea, float *Bfea, int featuresize); |
190 | 191 | |
191 | - | |
192 | - | |
193 | -#ifdef __cplusplus | |
194 | -}; | |
195 | -#endif | |
196 | - | |
197 | 192 | #endif |
198 | 193 | ... | ... |
build/jni/Makefile
... | ... | @@ -12,6 +12,7 @@ BIN_ROOT = $(PROJECT_ROOT)/bin |
12 | 12 | ACL_PATH = $(ASCEND_AICPU_PATH)/acllib |
13 | 13 | |
14 | 14 | ALGORITHM_PATH = $(PROJECT_ROOT)/algorithm |
15 | +SPDLOG_ROOT = $(PROJECT_ROOT)/3rdparty/spdlog-1.9.2/release | |
15 | 16 | |
16 | 17 | TARGET = $(PROJECT_ROOT)/bin/libvillage_ascend_arm_jni.so |
17 | 18 | |
... | ... | @@ -27,8 +28,10 @@ INCLUDE= -I $(SRC_ROOT)/include \ |
27 | 28 | -I $(THIRDPARTY_ROOT)/opencv_4_1/include \ |
28 | 29 | -I$(PROJECT_ROOT)/src/common \ |
29 | 30 | -I$(PROJECT_ROOT)/src/common/dvpp \ |
31 | + -I$(PROJECT_ROOT)/src/utils \ | |
30 | 32 | -I$(ACL_PATH)/include \ |
31 | 33 | -I$(ALGORITHM_PATH)/vehicle_analysis \ |
34 | + -I$(SPDLOG_ROOT)/include \ | |
32 | 35 | |
33 | 36 | |
34 | 37 | LIBSPATH= -L $(BIN_ROOT) -lvillage_ascend_arm \ |
... | ... | @@ -36,6 +39,7 @@ LIBSPATH= -L $(BIN_ROOT) -lvillage_ascend_arm \ |
36 | 39 | -L $(BIN_ROOT) -l:libcurl.so.4 -lssl -lcrypto \ |
37 | 40 | -L $(ACL_PATH)/lib64 -l:libascendcl.so \ |
38 | 41 | -L $(ACL_PATH)/lib64 -l:libacl_dvpp.so \ |
42 | + -L $(SPDLOG_ROOT)/lib -lspdlog \ | |
39 | 43 | |
40 | 44 | |
41 | 45 | SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) | ... | ... |
src/PicAnalysis.cpp
... | ... | @@ -27,11 +27,22 @@ int PicAnalysis::init(VillageParam param) { |
27 | 27 | LOG_INFO("log_days: {}", param.log_days); |
28 | 28 | LOG_INFO("log_path: {}", log_path); |
29 | 29 | |
30 | + LOG_INFO("编译时间:{} {}", __DATE__, __TIME__); | |
31 | + LOG_INFO("execute dir:{}", helpers::PathUtils::GetCmdDir()); | |
32 | + | |
30 | 33 | int dev_id = param.dev_id; |
31 | 34 | |
32 | 35 | int ret = SY_FAILED; |
33 | 36 | |
34 | - ret = m_vehicle_analysis.init(dev_id, param.sdk_path, 16); | |
37 | + VehicleAnalysisParam vehicle_analysis_param; | |
38 | + vehicle_analysis_param.devId = dev_id; | |
39 | + vehicle_analysis_param.sdk_root = param.sdk_path; | |
40 | + vehicle_analysis_param.max_batch_size = 16; | |
41 | + vehicle_analysis_param.log_level = param.log_level; | |
42 | + vehicle_analysis_param.log_path = param.log_path; | |
43 | + vehicle_analysis_param.log_days = param.log_days; | |
44 | + vehicle_analysis_param.log_mem = param.log_mem; | |
45 | + ret = m_vehicle_analysis.init(vehicle_analysis_param); | |
35 | 46 | if(0 != ret){ |
36 | 47 | return -1; |
37 | 48 | } |
... | ... | @@ -186,6 +197,8 @@ vector<AnalysisResult> PicAnalysis::analysis_img(vector<sy_img> vec_img){ |
186 | 197 | |
187 | 198 | LOG_INFO("vec_img size:{}", vec_img.size()); |
188 | 199 | |
200 | + std::lock_guard<std::mutex> l(m_single_mtx); | |
201 | + | |
189 | 202 | vector<AnalysisResult> vec_result; |
190 | 203 | |
191 | 204 | const int batch_size = vec_img.size(); | ... | ... |
src/PicAnalysis.h
... | ... | @@ -9,9 +9,12 @@ |
9 | 9 | #include "./ai_engine_module/RoadSegAnalysis.h" |
10 | 10 | |
11 | 11 | #include "./utils/CropUtil.h" |
12 | +#include "./utils/PathUtils.hpp" | |
12 | 13 | |
13 | 14 | #include "village_inc.h" |
14 | 15 | |
16 | +#include <mutex> | |
17 | + | |
15 | 18 | using namespace std; |
16 | 19 | |
17 | 20 | |
... | ... | @@ -47,6 +50,8 @@ private: |
47 | 50 | RoadSegAnalysis m_road_seg_algorithm; |
48 | 51 | |
49 | 52 | CropUtil m_crop_util; |
53 | + | |
54 | + std::mutex m_single_mtx; | |
50 | 55 | }; |
51 | 56 | |
52 | 57 | ... | ... |
src/ai_engine_module/VehicleAnalysis.cpp
... | ... | @@ -9,8 +9,9 @@ VehicleAnalysis::~VehicleAnalysis() { |
9 | 9 | release(); |
10 | 10 | } |
11 | 11 | |
12 | -int VehicleAnalysis::init(int devId, std::string sdk_root, int max_batch_size) { | |
13 | - | |
12 | +int VehicleAnalysis::init(VehicleAnalysisParam tParam) { | |
13 | + | |
14 | + va_param param; | |
14 | 15 | param.vehicle_detect_config= SY_CONFIG_OPEN; //1.开启车检测 SY_CONFIG_CLOSE SY_CONFIG_OPEN |
15 | 16 | param.vehicle_recg_config= SY_CONFIG_OPEN; //4.开启车型识别 |
16 | 17 | param.vehicle_recg_supplement_config= SY_CONFIG_OPEN; //4.开启车型识别补充识别 |
... | ... | @@ -22,7 +23,7 @@ int VehicleAnalysis::init(int devId, std::string sdk_root, int max_batch_size) { |
22 | 23 | param.vehicle_color_config= SY_CONFIG_OPEN; //3.开启车颜色识别 |
23 | 24 | param.vehicle_feature_config= SY_CONFIG_OPEN; //8.开启车辆特征提取 |
24 | 25 | |
25 | - param.gpuid=devId; | |
26 | + param.gpuid=tParam.devId; | |
26 | 27 | |
27 | 28 | //车检测参数 |
28 | 29 | //param.vehicle_det_param.process_min_l = 720;// 720; |
... | ... | @@ -52,12 +53,17 @@ int VehicleAnalysis::init(int devId, std::string sdk_root, int max_batch_size) { |
52 | 53 | //车颜色阈值 |
53 | 54 | param.vc_thresld = 0.5; |
54 | 55 | |
55 | - string dbPath = sdk_root + "/models/vehicle_analysis/db/vr_h0725x210605_r191230.db"; | |
56 | - string models_path = sdk_root + "/models/vehicle_analysis/"; | |
56 | + string dbPath = tParam.sdk_root + "/models/vehicle_analysis/db/vr_h0725x210605_r191230.db"; | |
57 | + string models_path = tParam.sdk_root + "/models/vehicle_analysis/"; | |
57 | 58 | //车型参数 |
58 | 59 | param.dbPath= (char*)dbPath.data(); |
59 | 60 | param.models_Path= (char*)models_path.data(); //所有模型的地址 |
60 | 61 | |
62 | + param.log_level = tParam.log_level; | |
63 | + param.log_path = tParam.log_path; | |
64 | + param.log_days = tParam.log_days; | |
65 | + param.log_mem = tParam.log_mem; | |
66 | + | |
61 | 67 | LOG_INFO("va_init start"); |
62 | 68 | // 内部有 ctx |
63 | 69 | int ret = va_init(&m_handle, param); |
... | ... | @@ -83,180 +89,13 @@ va_result * VehicleAnalysis::detect(vector<sy_img> vec_img) { |
83 | 89 | result[b].info[c].vehicle_pendant_det_res.vpd_res=new v_pendant_d_info[300]; |
84 | 90 | } |
85 | 91 | } |
86 | - | |
87 | - int ret = va_batch(m_handle, vec_img.data(), batch_size, result); | |
88 | 92 | |
89 | - vector<VehicleAnalysisResult> vec_result; | |
93 | + LOG_INFO("va_batch start"); | |
90 | 94 | |
91 | - for (int b = 0; b < batch_size; b++) | |
92 | - { | |
93 | - for(int c=0;c<result[b].count;c++) | |
94 | - { | |
95 | - vehicle_info result_info = result[b].info[c]; | |
96 | - | |
97 | - VehicleAnalysisResult analysis_result; | |
98 | - | |
99 | - std::string str_vehicle_type; | |
100 | - int shot_type=result_info.type; | |
101 | - if (shot_type==0)str_vehicle_type = "head"; | |
102 | - else if (shot_type==1)str_vehicle_type = "rear"; | |
103 | - else if (shot_type==2)str_vehicle_type = "motor"; | |
104 | - else if (shot_type==3)str_vehicle_type = "tricycle"; | |
105 | - else if (shot_type==4)str_vehicle_type = "body"; | |
106 | - else if (shot_type==5)str_vehicle_type = "body_nova"; | |
107 | - | |
108 | - analysis_result.shot_type = shot_type; | |
109 | - | |
110 | - //1.车头结果:蓝框//2.车窗结果:绿框 | |
111 | - if(param.vehicle_detect_config==SY_CONFIG_OPEN) | |
112 | - { | |
113 | - //车身 | |
114 | - //std::cout << "vehicle_body_detect_res info:"<< std::endl; | |
115 | - if(result_info.vehicle_body_detect_res.rect.width_>0) | |
116 | - { | |
117 | - float vehicle_body_detect_res_score = result_info.vehicle_body_detect_res.score; | |
118 | - int x1=result_info.vehicle_body_detect_res.rect.left_; | |
119 | - int y1=result_info.vehicle_body_detect_res.rect.top_; | |
120 | - int x2=result_info.vehicle_body_detect_res.rect.left_+result_info.vehicle_body_detect_res.rect.width_; | |
121 | - int y2=result_info.vehicle_body_detect_res.rect.top_+result_info.vehicle_body_detect_res.rect.height_; | |
122 | - std::cout << " vehicle_body_detect_res_score:" <<vehicle_body_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl; | |
123 | - | |
124 | - analysis_result.vehicle_rect = result_info.vehicle_body_detect_res.rect; | |
125 | - } | |
126 | - | |
127 | - // //车头 | |
128 | - // if(result_info.vehicle_detect_res.rect.width_>0) | |
129 | - // { | |
130 | - // float vehicle_detect_res_score = result_info.vehicle_detect_res.score; | |
131 | - // int x1=result_info.vehicle_detect_res.rect.left_; | |
132 | - // int y1=result_info.vehicle_detect_res.rect.top_; | |
133 | - // int x2=result_info.vehicle_detect_res.rect.left_+result_info.vehicle_detect_res.rect.width_; | |
134 | - // int y2=result_info.vehicle_detect_res.rect.top_+result_info.vehicle_detect_res.rect.height_; | |
135 | - // std::cout << " vehicle_detect_res_score:" <<vehicle_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl; | |
136 | - | |
137 | - // } | |
138 | - | |
139 | - // //车窗 | |
140 | - // if(result_info.vehicle_win_detect_res.rect.width_>0) | |
141 | - // { | |
142 | - // float vehicle_win_detect_res_score = result_info.vehicle_win_detect_res.score; | |
143 | - // int x1=result_info.vehicle_win_detect_res.rect.left_; | |
144 | - // int y1=result_info.vehicle_win_detect_res.rect.top_; | |
145 | - // int x2=result_info.vehicle_win_detect_res.rect.left_+result_info.vehicle_win_detect_res.rect.width_; | |
146 | - // int y2=result_info.vehicle_win_detect_res.rect.top_+result_info.vehicle_win_detect_res.rect.height_; | |
147 | - // std::cout << " vehicle_win_detect_res_score:" <<vehicle_win_detect_res_score<<",win_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl; | |
148 | - | |
149 | - // } | |
150 | - } | |
151 | - | |
152 | - //4.VR车型识别 | |
153 | - if(param.vehicle_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1 || shot_type==4 )) | |
154 | - { | |
155 | - char *vehicle_brand=result_info.vehicle_recg_res.vehicle_brand;//车辆品牌 | |
156 | - char* vehicle_subbrand=result_info.vehicle_recg_res.vehicle_subbrand; //车辆子品牌 | |
157 | - char* vehicle_issue_year=result_info.vehicle_recg_res.vehicle_issue_year; //车辆年款 | |
158 | - char* vehicle_type_=result_info.vehicle_recg_res.vehicle_type; //车辆类型 | |
159 | - char* freight_ton=result_info.vehicle_recg_res.freight_ton; //货车吨级 | |
160 | - float name_score=result_info.vehicle_recg_res.name_score; //识别置信度 | |
161 | - | |
162 | - float name_score_thre = 0; | |
163 | - //if(shot_type==0)name_score_thre=0.7;//车头车型识别建议阈值0.7 | |
164 | - //if(shot_type==1)name_score_thre=0.8;//车尾车型识别建议阈值0.8 | |
165 | - if(name_score > name_score_thre) | |
166 | - { | |
167 | - analysis_result.vehicle_type = vehicle_type_; | |
168 | - } | |
169 | - } else { | |
170 | - analysis_result.vehicle_type = str_vehicle_type; | |
171 | - } | |
172 | - std::cout << "vehicle_type_: " << analysis_result.vehicle_type << std::endl; | |
173 | - | |
174 | - //5.VP车牌检测识别 | |
175 | - if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1)) | |
176 | - { | |
177 | - vplate_results plate_result = result_info.vehicle_plate_det_recg_res; | |
178 | - std::cout << " car plate info:"<< endl; | |
179 | - int special_type=plate_result.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate. | |
180 | - std::cout << " special_type:" << special_type<< std::endl; | |
181 | - | |
182 | - float detect_score=plate_result.detect_score; | |
183 | - if(detect_score>0.3) | |
184 | - { | |
185 | - //车牌识别结果 | |
186 | - std::string plate_recg=""; | |
187 | - std::string character_prob; | |
188 | - //if(num_score>0.99)//车牌识别建议置信度阈值0.99 | |
189 | - { | |
190 | - | |
191 | - for (int m = 0; m < PLATENUM; m++) | |
192 | - { | |
193 | - plate_recg=plate_recg + plate_result.recg[m].character; | |
194 | - character_prob += std::string(plate_result.recg[m].character) + "-" + std::to_string(plate_result.recg[m].maxprob) + ","; | |
195 | - } | |
196 | - } | |
197 | - | |
198 | - analysis_result.plate_det_score = plate_result.detect_score; | |
199 | - analysis_result.plate_rect = plate_result.rect;//车牌检测坐标 | |
200 | - analysis_result.plate_type = plate_result.type; //车牌类型:0-单排蓝色 1-单排黄色 2-单排白色 3-单排黑色 4-双排黄色 5-双排白色 6-新能源黄绿色 7-新能源白绿色 | |
201 | - analysis_result.plate_num = plate_recg; | |
202 | - analysis_result.character_prob = character_prob; | |
203 | - analysis_result.plate_num_score = plate_result.num_score;//识别置信度 | |
204 | - // analysis_result.special_type; //常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate. | |
205 | - } | |
206 | - | |
207 | - } | |
208 | - | |
209 | - //6.车属性结果: | |
210 | - if(param.vehicle_pendant_det_config==SY_CONFIG_OPEN && (shot_type==0|| shot_type==4)) | |
211 | - { | |
212 | - std::cout << " vehicle_pendant_det_res info:"<< endl; | |
213 | - int vpd_num = result_info.vehicle_pendant_det_res.count; | |
214 | - //std::cout << vpd_num<< std::endl; | |
215 | - std::cout << " vpd_num:"<<vpd_num<< endl; | |
216 | - for(int p=0; p<vpd_num; p++) | |
217 | - { | |
218 | - int index = result_info.vehicle_pendant_det_res.vpd_res[p].index; | |
219 | - if(index == 0){ | |
220 | - DriverInfo info; | |
221 | - info.driver_rect = result_info.vehicle_pendant_det_res.vpd_res[p].rect; | |
222 | - info.driver_prob = result_info.vehicle_pendant_det_res.vpd_res[p].confidence; | |
223 | - analysis_result.vec_drivers.push_back(info); | |
224 | - } | |
225 | - } | |
226 | - } | |
95 | + int ret = va_batch(m_handle, vec_img.data(), batch_size, result); | |
227 | 96 | |
228 | - //11.摩托车三轮车分析 | |
229 | - if(param.vehicle_motor_tricycle_analysis_config==SY_CONFIG_OPEN && (shot_type==2 || shot_type==3)) | |
230 | - { | |
231 | - //std::cout << "mta output----"<< std::endl; | |
232 | - | |
233 | - if(shot_type==2)//摩托车 | |
234 | - { | |
235 | - //摩托车载人 | |
236 | - //int status=result_info.mta_res.motor_manned.status; | |
237 | - //float score=result_info.mta_res.motor_manned.confidence; | |
238 | - //if(status == MOTOR_MANNED) | |
239 | - // std::cout << "motor info: MOTOR_MANNED, prob: " << score << std::endl; | |
240 | - //else if(status == MOTOR_NOT_MANNED) | |
241 | - // std::cout << "motor info: MOTOR_NOT_MANNED, prob: " << score << std::endl; | |
242 | - | |
243 | - //摩托车驾驶人是否戴安全帽 | |
244 | - analysis_result.motor_helmeted = result_info.mta_res.motor_driver_helmeted.status; | |
245 | - float score=result_info.mta_res.motor_driver_helmeted.confidence; | |
246 | - | |
247 | - } | |
248 | - } | |
97 | + LOG_INFO("va_batch end:{}", ret); | |
249 | 98 | |
250 | - //载人输出 | |
251 | - if(param.vehicle_manned_config==SY_CONFIG_OPEN && shot_type!=5) | |
252 | - { | |
253 | - if(result_info.manned_res.hs_count >= 3){ | |
254 | - analysis_result.motor_manned = 1; | |
255 | - } | |
256 | - } | |
257 | - } | |
258 | - } | |
259 | - | |
260 | 99 | //delete result |
261 | 100 | // for(int b=0;b<batch_size;b++) |
262 | 101 | // { |
... | ... | @@ -264,12 +103,10 @@ va_result * VehicleAnalysis::detect(vector<sy_img> vec_img) { |
264 | 103 | // { |
265 | 104 | // if(result[b].info[c].vehicle_pendant_det_res.vpd_res!=NULL) |
266 | 105 | // delete[] result[b].info[c].vehicle_pendant_det_res.vpd_res; |
267 | - | |
268 | 106 | // } |
269 | 107 | // if(result[b].info!=NULL){ |
270 | 108 | // delete[] result[b].info; |
271 | 109 | // } |
272 | - | |
273 | 110 | // } |
274 | 111 | |
275 | 112 | // if(result!=NULL){ | ... | ... |
src/ai_engine_module/VehicleAnalysis.h
... | ... | @@ -11,6 +11,16 @@ struct DriverInfo { |
11 | 11 | int driver_color; |
12 | 12 | }; |
13 | 13 | |
14 | +struct VehicleAnalysisParam { | |
15 | + int devId; | |
16 | + std::string sdk_root; | |
17 | + int max_batch_size; | |
18 | + int log_level{2}; | |
19 | + int log_days{30}; //日志保存周期 | |
20 | + std::string log_path{"logs"}; //日志文件路径 | |
21 | + unsigned long log_mem{64 * 1024 * 1024}; //每个日志最大大小 | |
22 | +}; | |
23 | + | |
14 | 24 | struct VehicleAnalysisResult{ |
15 | 25 | int shot_type; |
16 | 26 | sy_rect vehicle_rect; |
... | ... | @@ -38,7 +48,7 @@ public: |
38 | 48 | VehicleAnalysis(/* args */); |
39 | 49 | ~VehicleAnalysis(); |
40 | 50 | |
41 | - int init(int devId, std::string sdk_root, int max_batch_size); | |
51 | + int init(VehicleAnalysisParam tParam); | |
42 | 52 | |
43 | 53 | va_result* detect(vector<sy_img> vec_img); |
44 | 54 | |
... | ... | @@ -49,7 +59,6 @@ private: |
49 | 59 | |
50 | 60 | private: |
51 | 61 | void* m_handle{nullptr}; |
52 | - va_param param; | |
53 | 62 | |
54 | 63 | float m_threshold; |
55 | 64 | int m_max_batchsize{1}; | ... | ... |
src/demo/main.cpp
... | ... | @@ -72,37 +72,43 @@ int main() { |
72 | 72 | |
73 | 73 | |
74 | 74 | vector<string> vec_path; |
75 | - GetFileNames("/home/share/data/villiage_test/test", vec_path); | |
75 | + GetFileNames("/home/share/data/villiage_test/test3", vec_path); | |
76 | 76 | |
77 | - vec_path = GetFilesFromFile("./files1.log"); | |
77 | + // vec_path = GetFilesFromFile("./files1.log"); | |
78 | 78 | |
79 | 79 | // { |
80 | 80 | // string path = "./img/test_road2.jpg"; |
81 | 81 | // vec_path.push_back(path); |
82 | 82 | // } |
83 | 83 | |
84 | - int last_recoder = 0; | |
84 | + size_t last_recoder = 0; | |
85 | 85 | int index = 0; |
86 | + int max_value = vec_path.size(); | |
86 | 87 | |
87 | 88 | while (true) |
88 | 89 | { |
89 | - for (size_t i = 0; i < vec_path.size(); i++) | |
90 | + // for (size_t i = 0; i < vec_path.size(); i++) | |
90 | 91 | { |
92 | + int first_index = rand() % max_value; | |
93 | + int second_index = rand() % max_value; | |
94 | + | |
91 | 95 | vector<string> vec_file_name; |
92 | - vec_file_name.push_back(vec_path[i]); | |
93 | - vec_file_name.push_back(vec_path[i]); | |
96 | + vec_file_name.push_back(vec_path[first_index]); | |
97 | + vec_file_name.push_back(vec_path[second_index]); | |
94 | 98 | |
95 | 99 | std::vector<AnalysisResult> result = village_pic_analysis_file(vaHandle, vec_file_name); |
96 | - show_result(result, vec_path); | |
100 | + // show_result(result, vec_path); | |
97 | 101 | |
98 | - int cur_recoder = GetDeviceMem(0); | |
102 | + size_t cur_recoder = GetDeviceMem(0); | |
99 | 103 | if (cur_recoder > last_recoder) |
100 | 104 | { |
101 | - LOG_INFO("memesize cur: {} last:{} file:{}", cur_recoder, last_recoder, vec_path[i]); | |
105 | + // LOG_INFO("memesize cur: {} last:{} file:{} file:{}", cur_recoder, last_recoder, vec_path[first_index], vec_path[second_index]); | |
106 | + LOG_INFO("memesize cur: {} last:{} ", cur_recoder, last_recoder); | |
102 | 107 | } |
103 | 108 | last_recoder = cur_recoder; |
104 | 109 | } |
105 | - LOG_INFO("第{}次完成:{}", index, vec_path.size()); | |
110 | + // LOG_INFO("第{}次完成:{}", index, vec_path.size()); | |
111 | + LOG_INFO("第{}次完成", index); | |
106 | 112 | index++; |
107 | 113 | } |
108 | 114 | ... | ... |
src/utils/DeviceUtil.hpp
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | #include "logger.hpp" |
9 | 9 | |
10 | 10 | |
11 | -int GetDeviceMem(int dev_id) { | |
11 | +size_t GetDeviceMem(int dev_id) { | |
12 | 12 | aclrtSetDevice(dev_id); |
13 | 13 | size_t free = 0; |
14 | 14 | size_t total = 0; |
... | ... | @@ -18,9 +18,11 @@ int GetDeviceMem(int dev_id) { |
18 | 18 | LOG_ERROR("aclrtGetMemInfo error!"); |
19 | 19 | return -1; |
20 | 20 | } |
21 | - LOG_INFO("device {} memory usage/total:{}/{}", dev_id, total - free, total); | |
22 | 21 | |
23 | - return total - free; | |
22 | + size_t usage = (total - free)/(1024*1024); | |
23 | + LOG_INFO("device {} memory usage/total:{}/{}", dev_id, usage, total/(1024*1024)); | |
24 | + | |
25 | + return usage; | |
24 | 26 | } |
25 | 27 | |
26 | 28 | ... | ... |
src/utils/PathUtils.hpp
0 → 100644
1 | +#ifndef _PATH_UTILS_H_ | |
2 | +#define _PATH_UTILS_H_ | |
3 | + | |
4 | +#include <string> | |
5 | + | |
6 | +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) | |
7 | + | |
8 | +#include<Windows.h> | |
9 | + | |
10 | +#elif defined(linux) || defined(__linux) | |
11 | + | |
12 | +#include <string.h> | |
13 | +#include <unistd.h> | |
14 | +#include <dlfcn.h> | |
15 | +#include <limits.h> | |
16 | +#include <iostream> | |
17 | + | |
18 | +#endif // WINDOWS | |
19 | + | |
20 | +namespace helpers | |
21 | +{ | |
22 | + namespace PathUtils { | |
23 | + | |
24 | + #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) | |
25 | + static HMODULE GetSelfModuleHandle() | |
26 | + { | |
27 | + MEMORY_BASIC_INFORMATION mbi; | |
28 | + return ( | |
29 | + (::VirtualQuery(GetSelfModuleHandle, &mbi, sizeof(mbi)) != 0) | |
30 | + ? (HMODULE)mbi.AllocationBase : NULL | |
31 | + ); | |
32 | + } | |
33 | + | |
34 | + static std::string GetCurrentProgramDir() | |
35 | + { | |
36 | + std::string strCurrentPath = ""; | |
37 | + char curDirector[260] = { 0 }; | |
38 | + GetModuleFileName(GetSelfModuleHandle(), curDirector, 260); | |
39 | + strCurrentPath = curDirector; | |
40 | + | |
41 | + size_t nameStart = strCurrentPath.rfind("\\"); | |
42 | + strCurrentPath = strCurrentPath.substr(0, nameStart + 1); | |
43 | + return strCurrentPath; | |
44 | + } | |
45 | + | |
46 | + #elif defined(linux) || defined(__linux) | |
47 | + static std::string GetCurrentProgramDir() | |
48 | + { | |
49 | + std::string strCurrentPath = ""; | |
50 | + char szCurWorkPath[256]; | |
51 | + memset(szCurWorkPath, '\0', 256); | |
52 | + int nRet = readlink("/proc/self/exe", szCurWorkPath, 256); | |
53 | + if (nRet > 256 || nRet < 0) | |
54 | + { | |
55 | + return strCurrentPath; | |
56 | + } | |
57 | + | |
58 | + for (int i = nRet; i > 0; i--) | |
59 | + { | |
60 | + if (szCurWorkPath[i] == '/' || szCurWorkPath[i] == '\\') | |
61 | + { | |
62 | + szCurWorkPath[i] = '\0'; | |
63 | + break; | |
64 | + } | |
65 | + } | |
66 | + | |
67 | + strCurrentPath = szCurWorkPath; | |
68 | + | |
69 | + return strCurrentPath; | |
70 | + } | |
71 | + | |
72 | + static std::string GetCmdDir() { | |
73 | + char cwd[PATH_MAX]; | |
74 | + if (getcwd(cwd, sizeof(cwd)) != nullptr) { | |
75 | + std::cout << "当前工作目录是: " << cwd << std::endl; | |
76 | + } else { | |
77 | + std::cerr << "错误: 无法获取当前工作目录。" << std::endl; | |
78 | + } | |
79 | + return cwd; | |
80 | + } | |
81 | + #endif | |
82 | + | |
83 | + } | |
84 | + | |
85 | +} | |
86 | + | |
87 | +#endif // !_PATH_UTILS_H_ | ... | ... |