提交 12bc3be5 编写于 作者: S stephon

Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleClas into add_en_doc

......@@ -7,7 +7,7 @@ function _set_params(){
batch_size=${2:-"64"}
fp_item=${3:-"fp32"} # fp32|fp16
epochs=${4:-"2"} # 可选,如果需要修改代码提前中断
model_name=${5:-"model_name"}
model_item=${5:-"model_item"}
run_log_path=${TRAIN_LOG_DIR:-$(pwd)} # TRAIN_LOG_DIR 后续QA设置该参数
index=1
......@@ -23,16 +23,17 @@ function _set_params(){
device=${CUDA_VISIBLE_DEVICES//,/ }
arr=(${device})
num_gpu_devices=${#arr[*]}
log_file=${run_log_path}/clas_${model_name}_${run_mode}_bs${batch_size}_${fp_item}_${num_gpu_devices}
log_file=${run_log_path}/clas_${model_item}_${run_mode}_bs${batch_size}_${fp_item}_${num_gpu_devices}
model_name=${model_item}_bs${batch_size}_${fp_item} # model_item 用于yml匹配,model_name用于入库
}
function _train(){
echo "Train on ${num_gpu_devices} GPUs"
echo "current CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES, gpus=$num_gpu_devices, batch_size=$batch_size"
if [ ${fp_item} = "fp32" ];then
model_config=`find ppcls/configs/ImageNet -name ${model_name}.yaml`
model_config=`find ppcls/configs/ImageNet -name ${model_item}.yaml`
else
model_config=`find ppcls/configs/ImageNet -name ${model_name}_fp16.yaml`
model_config=`find ppcls/configs/ImageNet -name ${model_item}_fp16.yaml`
fi
train_cmd="-c ${model_config} -o DataLoader.Train.sampler.batch_size=${batch_size} -o Global.epochs=${epochs} -o Global.eval_during_train=False -o Global.print_batch_step=2"
......
......@@ -215,9 +215,9 @@ cp ../configs/inference_cls.yaml tools/
#### 2.3.2 执行
```shell
./build/clas_system -c inference_cls.yaml
./build/clas_system -c tools/inference_cls.yaml
# or
./build/clas_system -config inference_cls.yaml
./build/clas_system -config tools/inference_cls.yaml
```
最终屏幕上会输出结果,如下图所示。
......
......@@ -59,7 +59,7 @@ namespace Feature {
cv::Mat resize_img;
std::vector<double> time;
auto preprocess_start = std::chrono::system_clock::now();
auto preprocess_start = std::chrono::steady_clock::now();
this->resize_op_.Run(img, resize_img, this->resize_short_,
this->resize_size_);
......@@ -70,9 +70,9 @@ namespace Feature {
auto input_names = this->predictor_->GetInputNames();
auto input_t = this->predictor_->GetInputHandle(input_names[0]);
input_t->Reshape({1, 3, resize_img.rows, resize_img.cols});
auto preprocess_end = std::chrono::system_clock::now();
auto preprocess_end = std::chrono::steady_clock::now();
auto infer_start = std::chrono::system_clock::now();
auto infer_start = std::chrono::steady_clock::now();
input_t->CopyFromCpu(input.data());
this->predictor_->Run();
......@@ -84,18 +84,18 @@ namespace Feature {
out_data.resize(out_num);
output_t->CopyToCpu(out_data.data());
auto infer_end = std::chrono::system_clock::now();
auto infer_end = std::chrono::steady_clock::now();
auto postprocess_start = std::chrono::system_clock::now();
auto postprocess_start = std::chrono::steady_clock::now();
if (this->feature_norm)
FeatureNorm(out_data);
auto postprocess_end = std::chrono::system_clock::now();
auto postprocess_end = std::chrono::steady_clock::now();
std::chrono::duration<float> preprocess_diff =
preprocess_end - preprocess_start;
time.push_back(double(preprocess_diff.count()));
time.push_back(double(preprocess_diff.count()) * 1000);
std::chrono::duration<float> inference_diff = infer_end - infer_start;
double inference_cost_time = double(inference_diff.count());
double inference_cost_time = double(inference_diff.count() * 1000);
time.push_back(inference_cost_time);
// std::chrono::duration<float> postprocess_diff =
// postprocess_end - postprocess_start;
......
......@@ -179,9 +179,9 @@ int main(int argc, char **argv) {
if (config.config_file["Global"]["visual_det"].IsDefined()) {
visual_det = config.config_file["Global"]["visual_det"].as<bool>();
}
bool run_benchmark = false;
bool benchmark = false;
if (config.config_file["Global"]["benchmark"].IsDefined()) {
run_benchmark = config.config_file["Global"]["benchmark"].as<bool>();
benchmark = config.config_file["Global"]["benchmark"].as<bool>();
}
int max_det_results = 5;
if (config.config_file["Global"]["max_det_results"].IsDefined()) {
......@@ -210,6 +210,8 @@ int main(int argc, char **argv) {
// for time log
std::vector<double> cls_times = {0, 0, 0};
std::vector<double> det_times = {0, 0, 0};
std::vector<double> search_times = {0, 0, 0};
int instance_num = 0;
// for read images
std::vector <cv::Mat> batch_imgs;
std::vector <std::string> img_paths;
......@@ -222,7 +224,12 @@ int main(int argc, char **argv) {
// for nms
std::vector<int> indeices;
int warmup_iter = img_files_list.size() > 5 ? 5 : 0;
int warmup_iter = img_files_list.size() > 5 ? 5 : img_files_list.size();
if (benchmark) {
img_files_list.insert(img_files_list.begin(), img_files_list.begin(),
img_files_list.begin() + warmup_iter);
}
for (int idx = 0; idx < img_files_list.size(); ++idx) {
std::string img_path = img_files_list[idx];
cv::Mat srcimg = cv::imread(img_path, cv::IMREAD_COLOR);
......@@ -238,12 +245,14 @@ int main(int argc, char **argv) {
// step1: get all detection results
DetPredictImage(batch_imgs, img_paths, batch_size, &detector, det_result,
det_bbox_num, det_times, visual_det, run_benchmark);
det_bbox_num, det_times, visual_det, false);
// select max_det_results bbox
if (det_result.size() > max_det_results) {
det_result.resize(max_det_results);
}
instance_num += det_result.size();
// step2: add the whole image for recognition to improve recall
Detection::ObjectResult result_whole_img = {
{0, 0, srcimg.cols - 1, srcimg.rows - 1}, 0, 1.0};
......@@ -262,16 +271,25 @@ int main(int argc, char **argv) {
}
// step4: get search result
auto search_start = std::chrono::steady_clock::now();
search_result = searcher.Search(features.data(), det_result.size());
auto search_end = std::chrono::steady_clock::now();
// nms for search result
for (int i = 0; i < det_result.size(); ++i) {
det_result[i].confidence = search_result.D[search_result.return_k * i];
}
NMSBoxes(det_result, searcher.GetThreshold(), rec_nms_thresold, indeices);
auto nms_end = std::chrono::steady_clock::now();
std::chrono::duration<float> search_diff = search_end - search_start;
search_times[1] += double(search_diff.count() * 1000);
std::chrono::duration<float> nms_diff = nms_end - search_end;
search_times[2] += double(nms_diff.count() * 1000);
// print result
PrintResult(img_path, det_result, indeices, searcher, search_result);
if (not benchmark or (benchmark and idx >= warmup_iter))
PrintResult(img_path, det_result, indeices, searcher, search_result);
// for postprocess
batch_imgs.clear();
......@@ -281,18 +299,44 @@ int main(int argc, char **argv) {
feature.clear();
features.clear();
indeices.clear();
if (benchmark and warmup_iter == idx + 1) {
det_times = {0, 0, 0};
cls_times = {0, 0, 0};
search_times = {0, 0, 0};
instance_num = 0;
}
}
std::string presion = "fp32";
if (benchmark) {
std::string presion = "fp32";
if (config.config_file["Global"]["use_fp16"].IsDefined() and
config.config_file["Global"]["use_fp16"].as<bool>())
presion = "fp16";
bool use_gpu = config.config_file["Global"]["use_gpu"].as<bool>();
bool use_tensorrt = config.config_file["Global"]["use_tensorrt"].as<bool>();
bool enable_mkldnn =
config.config_file["Global"]["enable_mkldnn"].as<bool>();
int cpu_num_threads =
config.config_file["Global"]["cpu_num_threads"].as<int>();
int batch_size = config.config_file["Global"]["batch_size"].as<int>();
std::vector<int> shape =
config.config_file["Global"]["image_shape"].as < std::vector < int >> ();
std::string det_shape = std::to_string(shape[0]);
for (int i = 1; i < shape.size(); ++i)
det_shape = det_shape + ", " + std::to_string(shape[i]);
// if (config.use_fp16)
// presion = "fp16";
// if (config.benchmark) {
// AutoLogger autolog("Classification", config.use_gpu, config.use_tensorrt,
// config.use_mkldnn, config.cpu_threads, 1,
// "1, 3, 224, 224", presion, cls_times,
// img_files_list.size());
// autolog.report();
// }
AutoLogger autolog_det("Det", use_gpu, use_tensorrt, enable_mkldnn,
cpu_num_threads, batch_size, det_shape, presion,
det_times, img_files_list.size() - warmup_iter);
autolog_det.report();
AutoLogger autolog_rec("Rec", use_gpu, use_tensorrt, enable_mkldnn,
cpu_num_threads, batch_size, "3, 224, 224", presion,
cls_times, instance_num);
autolog_rec.report();
AutoLogger autolog_search("Search", false, use_tensorrt, enable_mkldnn,
cpu_num_threads, batch_size, "dynamic", presion,
search_times, instance_num);
autolog_search.report();
}
return 0;
}
......@@ -14,20 +14,21 @@ def parse_args():
def main():
args = parse_args()
with open(args.config)as fd:
config = yaml.load(fd)
with open(args.config) as fd:
config = yaml.load(fd.read(), yaml.FullLoader)
index_dir = ""
try:
index_dir = config["IndexProcess"]["index_dir"]
except Exception as e:
print("The IndexProcess.index_dir in config_file dose not exist")
print("The IndexProcess.index_dir in config_file dose not exist")
exit(1)
id_map_path = os.path.join(index_dir, "id_map.pkl")
assert os.path.exists(id_map_path), "The id_map file dose not exist: {}".format(id_map_path)
assert os.path.exists(
id_map_path), "The id_map file dose not exist: {}".format(id_map_path)
with open(id_map_path, "rb")as fd:
with open(id_map_path, "rb") as fd:
ids = pickle.load(fd)
with open(os.path.join(index_dir, "id_map.txt"), "w")as fd:
with open(os.path.join(index_dir, "id_map.txt"), "w") as fd:
for k, v in ids.items():
v = v.split("\t")[1]
fd.write(str(k) + " " + v + "\n")
......
docs/images/wx_group.png

112.8 KB | W: | H:

docs/images/wx_group.png

57.6 KB | W: | H:

docs/images/wx_group.png
docs/images/wx_group.png
docs/images/wx_group.png
docs/images/wx_group.png
  • 2-up
  • Swipe
  • Onion skin
## 识别效果展示
- 商品识别
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/channelhandle_5.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/cliniqueblush_1.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/daoxiangcunjinzhubing_10.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/gannidress_10.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/gbyingerche_15.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/lafiolewine_03.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/taochunqiu_8.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_product/weiduomeinaiyougege_10.jpg" width = "400" />
</div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140277277-7b29f596-35f6-4f00-8d2b-0ef0be57a090.jpg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140277291-f7d2b2a1-5790-4f5b-a0e6-f5c52d04a69a.jpg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140277300-8ce0d5ce-e0ca-46ea-bb9a-74df0df66ae3.jpg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140277308-14a097bd-2bcd-41ce-a9e6-5e9cd0bd8b08.jpg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140277311-208ae574-a708-46e2-a41e-c639322913b1.jpg" width = "400" /> </div>
[更多效果图](../../images/recognition/more_demo_images/product.md)
- 动漫人物识别
<div align="center">
<img src="../../images/recognition/more_demo_images/output_cartoon/labixiaoxin-005.jpeg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_cartoon/liuchuanfeng-010.jpeg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_cartoon/zhangchulan-007.jpeg" width = "400" />
</div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140069108-ad54ae1d-610d-4cfa-9cd6-8ee8d280d61d.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140069100-7539d292-1bd8-4655-8a6d-d1f2238bd618.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140069080-a821e0b7-8a10-4946-bf05-ff093cc16064.jpeg" width = "400" /> </div>
[更多效果图](../../images/recognition/more_demo_images/cartoon.md)
- logo识别
<div align="center">
<img src="../../images/recognition/more_demo_images/output_logo/cctv_4.jpg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_logo/mangguo_8.jpeg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_logo/zhongshiyou-007.jpg" width = "400" />
</div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140096687-5b562e2d-0653-4be6-861d-1936a4440df2.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140096701-4a4b2bd9-85f2-4d55-be4b-be6ab5e0fb81.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140096706-ef4ad024-7284-4cb3-975a-779fd06b96f5.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140096713-48e629aa-c637-4603-b005-18570fa94d6d.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140096752-1f98c937-5d83-4c29-b495-01971b5fb258.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140096767-e8f701eb-d0e8-4304-b031-e2bff8c199f3.jpeg" width = "400" /> </div>
[更多效果图](../../images/recognition/more_demo_images/logo.md)
- 车辆识别
<div align="center">
<img src="../../images/recognition/more_demo_images/output_vehicle/audia5-115.jpeg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_vehicle/bentian-yage-101.jpeg" width = "400" />
</div>
<div align="center">
<img src="../../images/recognition/more_demo_images/output_vehicle/bmw-m340-107.jpeg" width = "400" />
</div>
[更多效果图](../../images/recognition/more_demo_images)
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140243899-c60f0a51-db9b-438a-9f2d-0d2893c200bb.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140243905-7eeb938d-d88f-4540-a667-06e08dcf1f55.jpeg" width = "400" /> </div>
<div align="center"> <img src="https://user-images.githubusercontent.com/12560511/140243911-735a6ec0-a624-4965-b3cd-2b9f52fa8d65.jpeg" width = "400" /> </div>
[更多效果图](../../images/recognition/more_demo_images/vehicle.md)
......@@ -11,10 +11,10 @@
- [4. 模型训练](#4)
- [4.1 使用 CPU 进行模型训练](#4.1)
- [4.1.1 不使用预训练模型进行训练](#4.1.1)
- [4.1.2 使用预训练模型进行训练](#4.1.2)
- [4.1.2 使用预训练模型进行训练](#4.1.2)
- [4.2 使用 GPU 进行模型训练](#4.2)
- [4.2.1 不使用预训练模型进行训练](#4.2.1)
- [4.2.2 使用预训练模型进行训练](#4.2.2)
- [4.2.2 使用预训练模型进行训练](#4.2.2)
- [5. 模型预测](#5)
<a name="1"></a>
......
......@@ -152,7 +152,7 @@ python3 -m paddle.distributed.launch \
* **注意**
* 其他数据增广的配置文件可以参考 `ppcls/configs/DataAugment` 中的配置文件。
* 其他数据增广的配置文件可以参考 `ppcls/configs/ImageNet/DataAugment/` 中的配置文件。
* 训练 CIFAR100 的迭代轮数较少,因此进行训练时,验证集的精度指标可能会有 1% 左右的波动。
<a name="4"></a>
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,7 +16,8 @@ Global:
# model architecture
Arch:
name: PPLCNet_x0_25
class_num: 1000
# loss function config for traing/eval process
Loss:
Train:
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,6 +16,7 @@ Global:
# model architecture
Arch:
name: PPLCNet_x0_35
class_num: 1000
# loss function config for traing/eval process
Loss:
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,6 +16,7 @@ Global:
# model architecture
Arch:
name: PPLCNet_x0_5
class_num: 1000
# loss function config for traing/eval process
Loss:
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,6 +16,7 @@ Global:
# model architecture
Arch:
name: PPLCNet_x0_75
class_num: 1000
# loss function config for traing/eval process
Loss:
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,6 +16,7 @@ Global:
# model architecture
Arch:
name: PPLCNet_x1_0
class_num: 1000
# loss function config for traing/eval process
Loss:
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,6 +16,7 @@ Global:
# model architecture
Arch:
name: PPLCNet_x1_5
class_num: 1000
# loss function config for traing/eval process
Loss:
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,7 +16,7 @@ Global:
# model architecture
Arch:
name: PPLCNet_x2_0
class_num: 1000
# loss function config for traing/eval process
Loss:
Train:
......
......@@ -4,7 +4,6 @@ Global:
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
......@@ -17,6 +16,7 @@ Global:
# model architecture
Arch:
name: PPLCNet_x2_5
class_num: 1000
# loss function config for traing/eval process
Loss:
......
......@@ -373,7 +373,7 @@ class Engine(object):
"inference")
if self.quanter:
self.quanter.save_quantized_model(
model,
model.base_model,
save_path,
input_spec=[
paddle.static.InputSpec(
......
===========================cpp_infer_params===========================
model_name:PPShiTu
cpp_infer_type:shitu
feature_inference_model_dir:./feature_inference/
det_inference_model_dir:./det_inference
cls_inference_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar
det_inference_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
infer_quant:False
inference_cmd:./deploy/cpp_shitu/build/pp_shitu -c inference_drink.yaml
use_gpu:True|False
enable_mkldnn:True|False
cpu_threads:1|6
batch_size:1
use_tensorrt:False|True
precision:fp32|fp16
data_dir:./dataset/drink_dataset_v1.0
benchmark:True
generate_yaml_cmd:python3 test_tipc/generate_cpp_yaml.py
transform_index_cmd:python3 deploy/cpp_shitu/tools/transform_id_map.py -c inference_drink.yaml
===========================cpp_infer_params===========================
model_name:ResNet50_vd
cpp_infer_type:cls
cls_inference_model_dir:./cls_inference/
det_inference_model_dir:
cls_inference_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/whole_chain/ResNet50_vd_inference.tar
det_inference_url:
infer_quant:False
inference_cmd:./deploy/cpp/build/clas_system -c inference_cls.yaml
use_gpu:True|False
enable_mkldnn:True|False
cpu_threads:1|6
batch_size:1
use_tensorrt:False|True
precision:fp32|fp16
image_dir:./dataset/ILSVRC2012/val
benchmark:True
generate_yaml_cmd:python3 test_tipc/generate_cpp_yaml.py
# C++预测功能测试
C++预测功能测试的主程序为`test_inference_cpp.sh`,可以测试基于C++预测库的模型推理功能。
## 1. 测试结论汇总
基于训练是否使用量化,进行本测试的模型可以分为`正常模型``量化模型`,这两类模型对应的C++预测功能汇总如下:
| 模型类型 |device | batchsize | tensorrt | mkldnn | cpu多线程 |
| ---- | ---- | ---- | :----: | :----: | :----: |
| 正常模型 | GPU | 1/6 | fp32/fp16 | - | - |
| 正常模型 | CPU | 1/6 | - | fp32 | 支持 |
| 量化模型 | GPU | 1/6 | int8 | - | - |
| 量化模型 | CPU | 1/6 | - | int8 | 支持 |
## 2. 测试流程
运行环境配置请参考[文档](./install.md)的内容配置TIPC的运行环境。
### 2.1 功能测试
先运行`prepare.sh`准备数据和模型,然后运行`test_inference_cpp.sh`进行测试,最终在```test_tipc/output```目录下生成`cpp_infer_*.log`后缀的日志文件。
```shell
bash test_tipc/prepare.sh test_tipc/config/ResNet/ResNet50_vd_linux_gpu_normal_normal_infer_cpp_linux_gpu_cpu.txt cpp_infer
# 用法1:
bash test_tipc/test_inference_cpp.sh test_tipc/config/ResNet/ResNet50_vd_linux_gpu_normal_normal_infer_cpp_linux_gpu_cpu.txt
# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号
bash test_tipc/test_inference_cpp.sh test_tipc/config/ResNet/ResNet50_vd_linux_gpu_normal_normal_infer_cpp_linux_gpu_cpu.txt 1
```
运行预测指令后,在`test_tipc/output`文件夹下自动会保存运行日志,包括以下文件:
```shell
test_tipc/output/
|- results_cpp.log # 运行指令状态的日志
|- cls_cpp_infer_cpu_usemkldnn_False_threads_1_precision_fp32_batchsize_1.log # CPU上不开启Mkldnn,线程数设置为1,测试batch_size=1条件下的预测运行日志
|- cls_cpp_infer_cpu_usemkldnn_False_threads_6_precision_fp32_batchsize_1.log # CPU上不开启Mkldnn,线程数设置为6,测试batch_size=1条件下的预测运行日志
|- cls_cpp_infer_gpu_usetrt_False_precision_fp32_batchsize_1.log # GPU上不开启TensorRT,测试batch_size=1的fp32精度预测日志
|- cls_cpp_infer_gpu_usetrt_True_precision_fp16_batchsize_1.log # GPU上开启TensorRT,测试batch_size=1的fp16精度预测日志
......
```
其中results_cpp.log中包含了每条指令的运行状态,如果运行成功会输出:
```
Run successfully with command - ./deploy/cpp/build/clas_system -c inference_cls.yaml 2>&1|tee test_tipc/output/cls_cpp_infer_gpu_usetrt_False_precision_fp32_batchsize_1.log
......
```
如果运行失败,会输出:
```
Run failed with command - ./deploy/cpp/build/clas_system -c inference_cls.yaml 2>&1|tee test_tipc/output/cls_cpp_infer_gpu_usetrt_False_precision_fp32_batchsize_1.log
......
```
可以很方便的根据results_cpp.log中的内容判定哪一个指令运行错误。
### 2.2 精度测试
使用compare_results.py脚本比较模型预测的结果是否符合预期,主要步骤包括:
- 提取日志中的预测坐标;
- 从本地文件中提取保存好的坐标结果;
- 比较上述两个结果是否符合精度预期,误差大于设置阈值时会报错。
#### 使用方式
运行命令:
```shell
python3.7 test_tipc/compare_results.py --gt_file=./test_tipc/results/cls_cpp_*.txt --log_file=./test_tipc/output/cls_cpp_*.log --atol=1e-3 --rtol=1e-3
```
参数介绍:
- gt_file: 指向事先保存好的预测结果路径,支持*.txt 结尾,会自动索引*.txt格式的文件,文件默认保存在test_tipc/result/ 文件夹下
- log_file: 指向运行test_tipc/test_inference_cpp.sh 脚本的infer模式保存的预测日志,预测日志中打印的有预测结果,比如:文本框,预测文本,类别等等,同样支持cpp_infer_*.log格式传入
- atol: 设置的绝对误差
- rtol: 设置的相对误差
#### 运行结果
正常运行效果如下图:
<img src="compare_cpp_right.png" width="1000">
出现不一致结果时的运行输出:
<img src="compare_cpp_wrong.png" width="1000">
## 3. 更多教程
本文档为功能测试用,更详细的c++预测使用教程请参考:[服务器端C++预测](../../docs/zh_CN/inference_deployment/)
import os
import yaml
import argparse
def str2bool(v):
if v.lower() == 'true':
return True
else:
return False
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--type', required=True, choices=["cls", "shitu"])
parser.add_argument('--batch_size', type=int, default=1)
parser.add_argument('--mkldnn', type=str2bool, default=True)
parser.add_argument('--gpu', type=str2bool, default=False)
parser.add_argument('--cpu_thread', type=int, default=1)
parser.add_argument('--tensorrt', type=str2bool, default=False)
parser.add_argument('--precision', type=str, choices=["fp32", "fp16"])
parser.add_argument('--benchmark', type=str2bool, default=True)
parser.add_argument('--gpu_id', type=int, default=0)
parser.add_argument(
'--cls_yaml_path',
type=str,
default="deploy/configs/inference_cls.yaml")
parser.add_argument(
'--shitu_yaml_path',
type=str,
default="deploy/configs/inference_drink.yaml")
parser.add_argument('--data_dir', type=str, required=True)
parser.add_argument('--save_path', type=str, default='./')
parser.add_argument('--cls_model_dir', type=str)
parser.add_argument('--det_model_dir', type=str)
args = parser.parse_args()
return args
def main():
args = parse_args()
if args.type == "cls":
save_path = os.path.join(args.save_path,
os.path.basename(args.cls_yaml_path))
fd = open(args.cls_yaml_path)
else:
save_path = os.path.join(args.save_path,
os.path.basename(args.shitu_yaml_path))
fd = open(args.shitu_yaml_path)
config = yaml.load(fd, yaml.FullLoader)
fd.close()
config["Global"]["batch_size"] = args.batch_size
config["Global"]["use_gpu"] = args.gpu
config["Global"]["enable_mkldnn"] = args.mkldnn
config["Global"]["benchmark"] = args.benchmark
config["Global"]["use_tensorrt"] = args.tensorrt
config["Global"]["use_fp16"] = True if args.precision == "fp16" else False
config["Global"]["gpu_id"] = args.gpu_id
if args.type == "cls":
config["Global"]["infer_imgs"] = args.data_dir
assert args.cls_model_dir
config["Global"]["inference_model_dir"] = args.cls_model_dir
else:
config["Global"]["infer_imgs"] = os.path.join(args.data_dir,
"test_images")
config["IndexProcess"]["index_dir"] = os.path.join(args.data_dir,
"index")
assert args.cls_model_dir
assert args.det_model_dir
config["Global"]["det_inference_model_dir"] = args.det_model_dir
config["Global"]["rec_inference_model_dir"] = args.cls_model_dir
with open(save_path, 'w') as fd:
yaml.dump(config, fd)
print("Generate new yaml done")
if __name__ == "__main__":
main()
......@@ -33,6 +33,59 @@ function func_parser_value(){
fi
}
function func_get_url_file_name(){
strs=$1
IFS="/"
array=(${strs})
tmp=${array[${#array[@]}-1]}
echo ${tmp}
}
model_name=$(func_parser_value "${lines[1]}")
if [ ${MODE} = "cpp_infer" ];then
if [[ $FILENAME == *infer_cpp_linux_gpu_cpu.txt ]];then
cpp_type=$(func_parser_value "${lines[2]}")
cls_inference_model_dir=$(func_parser_value "${lines[3]}")
det_inference_model_dir=$(func_parser_value "${lines[4]}")
cls_inference_url=$(func_parser_value "${lines[5]}")
det_inference_url=$(func_parser_value "${lines[6]}")
if [[ $cpp_type == "cls" ]];then
eval "wget -nc $cls_inference_url"
tar xf "${model_name}_inference.tar"
eval "mv inference $cls_inference_model_dir"
cd dataset
rm -rf ILSVRC2012
wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/whole_chain_infer.tar
tar xf whole_chain_infer.tar
ln -s whole_chain_infer ILSVRC2012
cd ..
elif [[ $cpp_type == "shitu" ]];then
eval "wget -nc $cls_inference_url"
tar_name=$(func_get_url_file_name "$cls_inference_url")
model_dir=${tar_name%.*}
eval "tar xf ${tar_name}"
eval "mv ${model_dir} ${cls_inference_model_dir}"
eval "wget -nc $det_inference_url"
tar_name=$(func_get_url_file_name "$det_inference_url")
model_dir=${tar_name%.*}
eval "tar xf ${tar_name}"
eval "mv ${model_dir} ${det_inference_model_dir}"
cd dataset
wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v1.0.tar
tar -xf drink_dataset_v1.0.tar
else
echo "Wrong cpp type in config file in line 3. only support cls, shitu"
fi
exit 0
else
echo "use wrong config file"
exit 1
fi
fi
model_name=$(func_parser_value "${lines[1]}")
model_url_value=$(func_parser_value "${lines[35]}")
model_url_key=$(func_parser_key "${lines[35]}")
......@@ -114,63 +167,3 @@ if [ ${MODE} = "serving_infer" ];then
cd ./deploy/paddleserving
wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/ResNet50_vd_infer.tar && tar xf ResNet50_vd_infer.tar
fi
if [ ${MODE} = "cpp_infer" ];then
cd deploy/cpp
echo "################### build opencv ###################"
rm -rf 3.4.7.tar.gz opencv-3.4.7/
wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz
tar -xf 3.4.7.tar.gz
install_path=$(pwd)/opencv-3.4.7/opencv3
cd opencv-3.4.7/
rm -rf build
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=${install_path} \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_IPP=OFF \
-DBUILD_IPP_IW=OFF \
-DWITH_LAPACK=OFF \
-DWITH_EIGEN=OFF \
-DCMAKE_INSTALL_LIBDIR=lib64 \
-DWITH_ZLIB=ON \
-DBUILD_ZLIB=ON \
-DWITH_JPEG=ON \
-DBUILD_JPEG=ON \
-DWITH_PNG=ON \
-DBUILD_PNG=ON \
-DWITH_TIFF=ON \
-DBUILD_TIFF=ON
make -j
make install
cd ../../
echo "################### build opencv finished ###################"
echo "################### build PaddleClas demo ####################"
OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/
LIB_DIR=$(pwd)/Paddle/build/paddle_inference_install_dir/
CUDA_LIB_DIR=$(dirname `find /usr -name libcudart.so`)
CUDNN_LIB_DIR=$(dirname `find /usr -name libcudnn.so`)
BUILD_DIR=build
rm -rf ${BUILD_DIR}
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
cmake .. \
-DPADDLE_LIB=${LIB_DIR} \
-DWITH_MKL=ON \
-DDEMO_NAME=clas_system \
-DWITH_GPU=OFF \
-DWITH_STATIC_LIB=OFF \
-DWITH_TENSORRT=OFF \
-DTENSORRT_DIR=${TENSORRT_DIR} \
-DOPENCV_DIR=${OPENCV_DIR} \
-DCUDNN_LIB=${CUDNN_LIB_DIR} \
-DCUDA_LIB=${CUDA_LIB_DIR} \
make -j
echo "################### build PaddleClas demo finished ###################"
fi
......@@ -2,6 +2,10 @@
source test_tipc/common_func.sh
FILENAME=$1
GPUID=$2
if [[ ! $GPUID ]];then
GPUID=0
fi
dataline=$(awk 'NR==1, NR==16{print}' $FILENAME)
# parser params
......@@ -10,37 +14,29 @@ lines=(${dataline})
# parser cpp inference model
model_name=$(func_parser_value "${lines[1]}")
use_opencv=$(func_parser_value "${lines[2]}")
cpp_infer_model_dir_list=$(func_parser_value "${lines[3]}")
cpp_infer_is_quant=$(func_parser_value "${lines[4]}")
cpp_infer_type=$(func_parser_value "${lines[2]}")
cpp_infer_model_dir=$(func_parser_value "${lines[3]}")
cpp_det_infer_model_dir=$(func_parser_value "${lines[4]}")
cpp_infer_is_quant=$(func_parser_value "${lines[7]}")
# parser cpp inference
inference_cmd=$(func_parser_value "${lines[5]}")
cpp_use_gpu_key=$(func_parser_key "${lines[6]}")
cpp_use_gpu_list=$(func_parser_value "${lines[6]}")
cpp_use_mkldnn_key=$(func_parser_key "${lines[7]}")
cpp_use_mkldnn_list=$(func_parser_value "${lines[7]}")
cpp_cpu_threads_key=$(func_parser_key "${lines[8]}")
cpp_cpu_threads_list=$(func_parser_value "${lines[8]}")
cpp_batch_size_key=$(func_parser_key "${lines[9]}")
cpp_batch_size_list=$(func_parser_value "${lines[9]}")
cpp_use_trt_key=$(func_parser_key "${lines[10]}")
cpp_use_trt_list=$(func_parser_value "${lines[10]}")
cpp_precision_key=$(func_parser_key "${lines[11]}")
cpp_precision_list=$(func_parser_value "${lines[11]}")
cpp_infer_model_key=$(func_parser_key "${lines[12]}")
cpp_image_dir_key=$(func_parser_key "${lines[13]}")
cpp_infer_img_dir=$(func_parser_value "${lines[13]}")
cpp_infer_key1=$(func_parser_key "${lines[14]}")
cpp_infer_value1=$(func_parser_value "${lines[14]}")
cpp_benchmark_key=$(func_parser_key "${lines[15]}")
cpp_benchmark_value=$(func_parser_value "${lines[15]}")
inference_cmd=$(func_parser_value "${lines[8]}")
cpp_use_gpu_list=$(func_parser_value "${lines[9]}")
cpp_use_mkldnn_list=$(func_parser_value "${lines[10]}")
cpp_cpu_threads_list=$(func_parser_value "${lines[11]}")
cpp_batch_size_list=$(func_parser_value "${lines[12]}")
cpp_use_trt_list=$(func_parser_value "${lines[13]}")
cpp_precision_list=$(func_parser_value "${lines[14]}")
cpp_image_dir_value=$(func_parser_value "${lines[15]}")
cpp_benchmark_value=$(func_parser_value "${lines[16]}")
generate_yaml_cmd=$(func_parser_value "${lines[17]}")
transform_index_cmd=$(func_parser_value "${lines[18]}")
LOG_PATH="./test_tipc/output"
mkdir -p ${LOG_PATH}
status_log="${LOG_PATH}/results_cpp.log"
# generate_yaml_cmd="python3 test_tipc/generate_cpp_yaml.py"
function func_cpp_inference(){
function func_shitu_cpp_inference(){
IFS='|'
_script=$1
_model_dir=$2
......@@ -48,6 +44,7 @@ function func_cpp_inference(){
_img_dir=$4
_flag_quant=$5
# inference
for use_gpu in ${cpp_use_gpu_list[*]}; do
if [ ${use_gpu} = "False" ] || [ ${use_gpu} = "cpu" ]; then
for use_mkldnn in ${cpp_use_mkldnn_list[*]}; do
......@@ -60,17 +57,14 @@ function func_cpp_inference(){
if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then
precison="int8"
fi
_save_log_path="${_log_path}/cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_precision_${precision}_batchsize_${batch_size}.log"
set_infer_data=$(func_set_params "${cpp_image_dir_key}" "${_img_dir}")
set_benchmark=$(func_set_params "${cpp_benchmark_key}" "${cpp_benchmark_value}")
set_batchsize=$(func_set_params "${cpp_batch_size_key}" "${batch_size}")
set_cpu_threads=$(func_set_params "${cpp_cpu_threads_key}" "${threads}")
set_model_dir=$(func_set_params "${cpp_infer_model_key}" "${_model_dir}")
set_infer_params1=$(func_set_params "${cpp_infer_key1}" "${cpp_infer_value1}")
command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${cpp_use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 "
eval $command
_save_log_path="${_log_path}/shitu_cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type shitu --batch_size ${batch_size} --mkldnn ${use_mkldnn} --gpu ${use_gpu} --cpu_thread ${threads} --tensorrt False --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --det_model_dir ${cpp_det_infer_model_dir} --gpu_id ${GPUID}"
eval $command
eval $transform_index_cmd
command="${_script} 2>&1|tee ${_save_log_path}"
eval $command
last_status=${PIPESTATUS[0]}
eval "cat ${_save_log_path}"
status_check $last_status "${command}" "${status_log}"
done
done
......@@ -88,20 +82,75 @@ function func_cpp_inference(){
continue
fi
for batch_size in ${cpp_batch_size_list[*]}; do
_save_log_path="${_log_path}/cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log"
set_infer_data=$(func_set_params "${cpp_image_dir_key}" "${_img_dir}")
set_benchmark=$(func_set_params "${cpp_benchmark_key}" "${cpp_benchmark_value}")
set_batchsize=$(func_set_params "${cpp_batch_size_key}" "${batch_size}")
set_tensorrt=$(func_set_params "${cpp_use_trt_key}" "${use_trt}")
set_precision=$(func_set_params "${cpp_precision_key}" "${precision}")
set_model_dir=$(func_set_params "${cpp_infer_model_key}" "${_model_dir}")
set_infer_params1=$(func_set_params "${cpp_infer_key1}" "${cpp_infer_value1}")
command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 "
_save_log_path="${_log_path}/shitu_cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type shitu --batch_size ${batch_size} --mkldnn False --gpu ${use_gpu} --cpu_thread 1 --tensorrt ${use_trt} --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --det_model_dir ${cpp_det_infer_model_dir} --gpu_id ${GPUID}"
eval $command
eval $transform_index_cmd
command="${_script} 2>&1|tee ${_save_log_path}"
eval $command
last_status=${PIPESTATUS[0]}
status_check $last_status "${_script}" "${status_log}"
done
done
done
else
echo "Does not support hardware other than CPU and GPU Currently!"
fi
done
}
function func_cls_cpp_inference(){
IFS='|'
_script=$1
_model_dir=$2
_log_path=$3
_img_dir=$4
_flag_quant=$5
# inference
for use_gpu in ${cpp_use_gpu_list[*]}; do
if [ ${use_gpu} = "False" ] || [ ${use_gpu} = "cpu" ]; then
for use_mkldnn in ${cpp_use_mkldnn_list[*]}; do
if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then
continue
fi
for threads in ${cpp_cpu_threads_list[*]}; do
for batch_size in ${cpp_batch_size_list[*]}; do
precision="fp32"
if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then
precison="int8"
fi
_save_log_path="${_log_path}/cls_cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type cls --batch_size ${batch_size} --mkldnn ${use_mkldnn} --gpu ${use_gpu} --cpu_thread ${threads} --tensorrt False --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --gpu_id ${GPUID}"
eval $command
command1="${_script} 2>&1|tee ${_save_log_path}"
eval ${command1}
last_status=${PIPESTATUS[0]}
status_check $last_status "${command1}" "${status_log}"
done
done
done
elif [ ${use_gpu} = "True" ] || [ ${use_gpu} = "gpu" ]; then
for use_trt in ${cpp_use_trt_list[*]}; do
for precision in ${cpp_precision_list[*]}; do
if [[ ${_flag_quant} = "False" ]] && [[ ${precision} =~ "int8" ]]; then
continue
fi
if [[ ${precision} =~ "fp16" || ${precision} =~ "int8" ]] && [ ${use_trt} = "False" ]; then
continue
fi
if [[ ${use_trt} = "False" || ${precision} =~ "int8" ]] && [ ${_flag_quant} = "True" ]; then
continue
fi
for batch_size in ${cpp_batch_size_list[*]}; do
_save_log_path="${_log_path}/cls_cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type cls --batch_size ${batch_size} --mkldnn False --gpu ${use_gpu} --cpu_thread 1 --tensorrt ${use_trt} --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --gpu_id ${GPUID}"
eval $command
command="${_script} 2>&1|tee ${_save_log_path}"
eval $command
last_status=${PIPESTATUS[0]}
eval "cat ${_save_log_path}"
status_check $last_status "${command}" "${status_log}"
done
done
done
......@@ -112,24 +161,56 @@ function func_cpp_inference(){
}
cd deploy/cpp_infer
if [ ${use_opencv} = "True" ]; then
if [ -d "opencv-3.4.7/opencv3/" ] && [ $(md5sum opencv-3.4.7.tar.gz | awk -F ' ' '{print $1}') = "faa2b5950f8bee3f03118e600c74746a" ];then
echo "################### build opencv skipped ###################"
else
echo "################### build opencv ###################"
rm -rf opencv-3.4.7.tar.gz opencv-3.4.7/
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/opencv-3.4.7.tar.gz
tar -xf opencv-3.4.7.tar.gz
if [[ $cpp_infer_type == "cls" ]]; then
cd deploy/cpp
elif [[ $cpp_infer_type == "shitu" ]]; then
cd deploy/cpp_shitu
else
echo "Only support cls and shitu"
exit 0
fi
if [[ $cpp_infer_type == "shitu" ]]; then
echo "################### update cmake ###################"
wget -nc https://github.com/Kitware/CMake/releases/download/v3.22.0/cmake-3.22.0.tar.gz
tar xf cmake-3.22.0.tar.gz
cd ./cmake-3.22.0
export root_path=$PWD
export install_path=${root_path}/cmake
eval "./bootstrap --prefix=${install_path}"
make -j
make install
export PATH=${install_path}/bin:$PATH
cd ..
echo "################### update cmake done ###################"
cd opencv-3.4.7/
install_path=$(pwd)/opencv3
echo "################### build faiss ###################"
apt-get install -y libopenblas-dev
git clone https://github.com/facebookresearch/faiss.git
cd faiss
export faiss_install_path=$PWD/faiss_install
eval "cmake -B build . -DFAISS_ENABLE_PYTHON=OFF -DCMAKE_INSTALL_PREFIX=${faiss_install_path}"
make -C build -j faiss
make -C build install
cd ..
fi
if [ -d "opencv-3.4.7/opencv3/" ] && [ $(md5sum opencv-3.4.7.tar.gz | awk -F ' ' '{print $1}') = "faa2b5950f8bee3f03118e600c74746a" ];then
echo "################### build opencv skipped ###################"
else
echo "################### build opencv ###################"
rm -rf opencv-3.4.7.tar.gz opencv-3.4.7/
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/opencv-3.4.7.tar.gz
tar -xf opencv-3.4.7.tar.gz
rm -rf build
mkdir build
cd build
cd opencv-3.4.7/
install_path=$(pwd)/opencv3
cmake .. \
rm -rf build
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=${install_path} \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
......@@ -147,20 +228,15 @@ if [ ${use_opencv} = "True" ]; then
-DWITH_TIFF=ON \
-DBUILD_TIFF=ON
make -j
make install
cd ../
echo "################### build opencv finished ###################"
fi
make -j
make install
cd ../../
echo "################### build opencv finished ###################"
fi
echo "################### build PaddleOCR demo ####################"
if [ ${use_opencv} = "True" ]; then
OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/
else
OPENCV_DIR=''
fi
echo "################### build PaddleClas demo ####################"
OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/
# LIB_DIR=/work/project/project/test/paddle_inference/
LIB_DIR=$(pwd)/Paddle/build/paddle_inference_install_dir/
CUDA_LIB_DIR=$(dirname `find /usr -name libcudart.so`)
CUDNN_LIB_DIR=$(dirname `find /usr -name libcudnn.so`)
......@@ -169,40 +245,59 @@ BUILD_DIR=build
rm -rf ${BUILD_DIR}
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
cmake .. \
-DPADDLE_LIB=${LIB_DIR} \
-DWITH_MKL=ON \
-DWITH_GPU=OFF \
-DWITH_STATIC_LIB=OFF \
-DWITH_TENSORRT=OFF \
-DOPENCV_DIR=${OPENCV_DIR} \
-DCUDNN_LIB=${CUDNN_LIB_DIR} \
-DCUDA_LIB=${CUDA_LIB_DIR} \
-DTENSORRT_DIR=${TENSORRT_DIR} \
if [[ $cpp_infer_type == cls ]]; then
cmake .. \
-DPADDLE_LIB=${LIB_DIR} \
-DWITH_MKL=ON \
-DWITH_GPU=ON \
-DWITH_STATIC_LIB=OFF \
-DWITH_TENSORRT=OFF \
-DOPENCV_DIR=${OPENCV_DIR} \
-DCUDNN_LIB=${CUDNN_LIB_DIR} \
-DCUDA_LIB=${CUDA_LIB_DIR} \
-DTENSORRT_DIR=${TENSORRT_DIR}
else
cmake ..\
-DPADDLE_LIB=${LIB_DIR} \
-DWITH_MKL=ON \
-DWITH_GPU=ON \
-DWITH_STATIC_LIB=OFF \
-DWITH_TENSORRT=OFF \
-DOPENCV_DIR=${OPENCV_DIR} \
-DCUDNN_LIB=${CUDNN_LIB_DIR} \
-DCUDA_LIB=${CUDA_LIB_DIR} \
-DTENSORRT_DIR=${TENSORRT_DIR} \
-DFAISS_DIR=${faiss_install_path} \
-DFAISS_WITH_MKL=OFF
fi
make -j
cd ../../../
echo "################### build PaddleOCR demo finished ###################"
# cd ../../
echo "################### build PaddleClas demo finished ###################"
# set cuda device
GPUID=$2
if [ ${#GPUID} -le 0 ];then
env=" "
else
env="export CUDA_VISIBLE_DEVICES=${GPUID}"
fi
set CUDA_VISIBLE_DEVICES
eval $env
# GPUID=$2
# if [ ${#GPUID} -le 0 ];then
# env="export CUDA_VISIBLE_DEVICES=0"
# else
# env="export CUDA_VISIBLE_DEVICES=${GPUID}"
# fi
# set CUDA_VISIBLE_DEVICES
# eval $env
echo "################### run test ###################"
export Count=0
IFS="|"
infer_quant_flag=(${cpp_infer_is_quant})
for infer_model in ${cpp_infer_model_dir_list[*]}; do
for infer_model in ${cpp_infer_model_dir[*]}; do
#run inference
is_quant=${infer_quant_flag[Count]}
func_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_infer_img_dir}" ${is_quant}
if [[ $cpp_infer_type == "cls" ]]; then
func_cls_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_image_dir_value}" ${is_quant}
else
func_shitu_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_image_dir_value}" ${is_quant}
fi
Count=$(($Count + 1))
done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册