From 212c9f18fa5baa0f64b81522f11bedf66cb861ed Mon Sep 17 00:00:00 2001 From: jario Date: Fri, 19 Jan 2024 21:12:13 +0800 Subject: [PATCH] fix model manager with various batchsize --- .../common_det/cuda/common_det_cuda_impl.cpp | 12 +++++++++--- .../common_det/intel/common_det_intel_impl.cpp | 7 ++++--- algorithm/sv_algorithm_base.cpp | 16 ++++++++++++++++ include/sv_algorithm_base.h | 4 ++++ params/a-params/sv_algorithm_params.json | 4 +++- .../sv_algorithm_params_1280_wo_mask.json | 4 +++- .../a-params/sv_algorithm_params_640_w_mask.json | 4 +++- .../sv_algorithm_params_640_wo_mask.json | 4 +++- .../a-params/sv_algorithm_params_coco_1280.json | 4 +++- .../a-params/sv_algorithm_params_coco_640.json | 4 +++- params/a-params/sv_algorithm_params_csrt.json | 4 +++- params/a-params/sv_algorithm_params_kcf.json | 4 +++- params/a-params/sv_algorithm_params_nano.json | 4 +++- params/a-params/sv_algorithm_params_siamrpn.json | 4 +++- scripts/model_sync.py | 12 +++++++++--- 15 files changed, 72 insertions(+), 19 deletions(-) diff --git a/algorithm/common_det/cuda/common_det_cuda_impl.cpp b/algorithm/common_det/cuda/common_det_cuda_impl.cpp index 44c503b..11b24a4 100644 --- a/algorithm/common_det/cuda/common_det_cuda_impl.cpp +++ b/algorithm/common_det/cuda/common_det_cuda_impl.cpp @@ -363,10 +363,16 @@ bool CommonObjectDetectorCUDAImpl::cudaSetup(CommonObjectDetectorBase* base_, bo bool with_segmentation = base_->withSegmentation(); double thrs_conf = base_->getThrsConf(); double thrs_nms = base_->getThrsNms(); + std::string model = base_->getModel(); + int bs = base_->getBatchSize(); + char bs_c[8]; + itoa(bs, bs_c, 10); + std::string bs_s(bs_c); std::string engine_fn = get_home() + SV_MODEL_DIR + dataset + ".engine"; std::vector files; - _list_dir(get_home() + SV_MODEL_DIR, files, "-online.engine", "Nv-" + dataset + "-yolov5s_c"); + + _list_dir(get_home() + SV_MODEL_DIR, files, "-online.engine", "Nv-" + dataset + "-yolov5" + model + "_b" + bs_s + "_c"); if (files.size() > 0) { std::sort(files.rbegin(), files.rend(), _comp_str_lesser); @@ -376,7 +382,7 @@ bool CommonObjectDetectorCUDAImpl::cudaSetup(CommonObjectDetectorBase* base_, bo if (input_w == 1280) { files.clear(); - _list_dir(get_home() + SV_MODEL_DIR, files, "-online.engine", "Nv-" + dataset + "-yolov5s6_"); + _list_dir(get_home() + SV_MODEL_DIR, files, "-online.engine", "Nv-" + dataset + "-yolov5" + model + "6_b" + bs_s + "_c"); if (files.size() > 0) { std::sort(files.rbegin(), files.rend(), _comp_str_lesser); @@ -392,7 +398,7 @@ bool CommonObjectDetectorCUDAImpl::cudaSetup(CommonObjectDetectorBase* base_, bo base_->setInputH(640); base_->setInputW(640); files.clear(); - _list_dir(get_home() + SV_MODEL_DIR, files, "-online.engine", "Nv-" + dataset + "-yolov5s_seg_"); + _list_dir(get_home() + SV_MODEL_DIR, files, "-online.engine", "Nv-" + dataset + "-yolov5" + model + "_seg_b" + bs_s + "_c"); if (files.size() > 0) { std::sort(files.rbegin(), files.rend(), _comp_str_lesser); diff --git a/algorithm/common_det/intel/common_det_intel_impl.cpp b/algorithm/common_det/intel/common_det_intel_impl.cpp index 2ca25cb..1cbb6ef 100644 --- a/algorithm/common_det/intel/common_det_intel_impl.cpp +++ b/algorithm/common_det/intel/common_det_intel_impl.cpp @@ -125,10 +125,11 @@ namespace sv inpHeight = base_->getInputH(); inpWidth = base_->getInputW(); with_segmentation = base_->withSegmentation(); + std::string model = base_->getModel(); std::string openvino_fn = get_home() + SV_MODEL_DIR + dataset + ".onnx"; std::vector files; - _list_dir(get_home() + SV_MODEL_DIR, files, "-online.onnx", "Int-" + dataset + "-yolov5s_c"); + _list_dir(get_home() + SV_MODEL_DIR, files, "-online.onnx", "Int-" + dataset + "-yolov5" + model + "_c"); if (files.size() > 0) { std::sort(files.rbegin(), files.rend(), _comp_str_lesser); @@ -138,7 +139,7 @@ namespace sv if (inpWidth == 1280) { files.clear(); - _list_dir(get_home() + SV_MODEL_DIR, files, "-online.onnx", "Int-" + dataset + "-yolov5s6_"); + _list_dir(get_home() + SV_MODEL_DIR, files, "-online.onnx", "Int-" + dataset + "-yolov5" + model + "6_c"); if (files.size() > 0) { std::sort(files.rbegin(), files.rend(), _comp_str_lesser); @@ -154,7 +155,7 @@ namespace sv base_->setInputH(640); base_->setInputW(640); files.clear(); - _list_dir(get_home() + SV_MODEL_DIR, files, "-online.onnx", "Int-" + dataset + "-yolov5s_seg_"); + _list_dir(get_home() + SV_MODEL_DIR, files, "-online.onnx", "Int-" + dataset + "-yolov5" + model + "_seg_c"); if (files.size() > 0) { std::sort(files.rbegin(), files.rend(), _comp_str_lesser); diff --git a/algorithm/sv_algorithm_base.cpp b/algorithm/sv_algorithm_base.cpp index 840e26e..d94a336 100644 --- a/algorithm/sv_algorithm_base.cpp +++ b/algorithm/sv_algorithm_base.cpp @@ -916,6 +916,14 @@ void CommonObjectDetectorBase::setInputW(int w_) { this->_input_w = w_; } +std::string CommonObjectDetectorBase::getModel() +{ + return this->_model; +} +int CommonObjectDetectorBase::getBatchSize() +{ + return this->_batch_size; +} void CommonObjectDetectorBase::warmUp() { @@ -1082,6 +1090,8 @@ void CommonObjectDetectorBase::_load() this->_thrs_nms = 0.6; this->_thrs_conf = 0.4; this->_use_width_or_height = 0; + this->_batch_size = 1; + this->_model = "s"; for (auto i : detector_params_value) { @@ -1089,6 +1099,12 @@ void CommonObjectDetectorBase::_load() this->_dataset = i->value.toString(); std::cout << "dataset: " << this->_dataset << std::endl; } + else if ("batchSize" == std::string(i->key)) { + this->_batch_size = i->value.toNumber(); + } + else if ("model" == std::string(i->key)) { + this->_model = i->value.toString(); + } else if ("inputSize" == std::string(i->key)) { // std::cout << "inputSize (old, new): " << this->_input_w << ", " << i->value.toNumber() << std::endl; this->_input_w = i->value.toNumber(); diff --git a/include/sv_algorithm_base.h b/include/sv_algorithm_base.h index 249ffdd..5822f4e 100644 --- a/include/sv_algorithm_base.h +++ b/include/sv_algorithm_base.h @@ -140,6 +140,8 @@ public: double getThrsConf(); int useWidthOrHeight(); bool withSegmentation(); + std::string getModel(); + int getBatchSize(); protected: virtual bool setupImpl(); virtual void detectImpl( @@ -166,6 +168,8 @@ protected: double _thrs_conf; int _use_width_or_height; bool _with_segmentation; + std::string _model; + int _batch_size; }; diff --git a/params/a-params/sv_algorithm_params.json b/params/a-params/sv_algorithm_params.json index 6d2bd9d..3098866 100644 --- a/params/a-params/sv_algorithm_params.json +++ b/params/a-params/sv_algorithm_params.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": true, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": true, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_1280_wo_mask.json b/params/a-params/sv_algorithm_params_1280_wo_mask.json index 1aa6685..0afd703 100644 --- a/params/a-params/sv_algorithm_params_1280_wo_mask.json +++ b/params/a-params/sv_algorithm_params_1280_wo_mask.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 1280, + "withSegmentation": false, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": false, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_640_w_mask.json b/params/a-params/sv_algorithm_params_640_w_mask.json index 8d07775..b8bc3f6 100644 --- a/params/a-params/sv_algorithm_params_640_w_mask.json +++ b/params/a-params/sv_algorithm_params_640_w_mask.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": true, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": true, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_640_wo_mask.json b/params/a-params/sv_algorithm_params_640_wo_mask.json index f87fb59..3d2297c 100644 --- a/params/a-params/sv_algorithm_params_640_wo_mask.json +++ b/params/a-params/sv_algorithm_params_640_wo_mask.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": false, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": false, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_coco_1280.json b/params/a-params/sv_algorithm_params_coco_1280.json index 1aa6685..0afd703 100644 --- a/params/a-params/sv_algorithm_params_coco_1280.json +++ b/params/a-params/sv_algorithm_params_coco_1280.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 1280, + "withSegmentation": false, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": false, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_coco_640.json b/params/a-params/sv_algorithm_params_coco_640.json index 8d07775..3d2297c 100644 --- a/params/a-params/sv_algorithm_params_coco_640.json +++ b/params/a-params/sv_algorithm_params_coco_640.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": false, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": true, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_csrt.json b/params/a-params/sv_algorithm_params_csrt.json index e45bda2..04397af 100644 --- a/params/a-params/sv_algorithm_params_csrt.json +++ b/params/a-params/sv_algorithm_params_csrt.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": true, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": true, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_kcf.json b/params/a-params/sv_algorithm_params_kcf.json index b9baa2d..015f718 100644 --- a/params/a-params/sv_algorithm_params_kcf.json +++ b/params/a-params/sv_algorithm_params_kcf.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": true, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": true, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_nano.json b/params/a-params/sv_algorithm_params_nano.json index 816504d..1c6770e 100644 --- a/params/a-params/sv_algorithm_params_nano.json +++ b/params/a-params/sv_algorithm_params_nano.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": true, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": true, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/params/a-params/sv_algorithm_params_siamrpn.json b/params/a-params/sv_algorithm_params_siamrpn.json index 8d07775..b8bc3f6 100644 --- a/params/a-params/sv_algorithm_params_siamrpn.json +++ b/params/a-params/sv_algorithm_params_siamrpn.json @@ -1,11 +1,13 @@ { "CommonObjectDetector": { "dataset": "COCO", + "model": "s", + "batchSize": 1, "inputSize": 640, + "withSegmentation": true, "nmsThrs": 0.6, "scoreThrs": 0.4, "useWidthOrHeight": 1, - "withSegmentation": true, "datasetPersonVehicle": { "person": [0.5, 1.8], "car": [4.1, 1.5], diff --git a/scripts/model_sync.py b/scripts/model_sync.py index 5ae669c..4fa40b5 100644 --- a/scripts/model_sync.py +++ b/scripts/model_sync.py @@ -51,10 +51,16 @@ def main(): if os.path.exists(model_file): print("[1] Model:", line, "EXIST!") if line.startswith('Nv'): - engine_fn = os.path.splitext(model_file)[0] + '.engine' - online_fn = os.path.splitext(model_file)[0] + '-online.engine' + net = line.split('-')[2] + if len(net.split('_')) == 3: + name, seg, ncls = net.split('_') + engine_fn = os.path.splitext(model_file)[0].replace(net, name + "_" + seg + '_b1_' + ncls) + '.engine' + online_fn = os.path.splitext(model_file)[0].replace(net, name + "_" + seg + '_b1_' + ncls) + '-online.engine' + else: + name, ncls = net.split('_') + engine_fn = os.path.splitext(model_file)[0].replace(net, name + '_b1_' + ncls) + '.engine' + online_fn = os.path.splitext(model_file)[0].replace(net, name + '_b1_' + ncls) + '-online.engine' if not os.path.exists(engine_fn) and not os.path.exists(online_fn): - net = line.split('-')[2] if net.startswith("yolov5"): if len(net.split('_')) == 3: name, seg, ncls = net.split('_')