From bd5aee152106cbf62611683cba8675da6f4a7333 Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Tue, 10 May 2022 13:09:56 +0800 Subject: [PATCH] change labe_list to label_list --- deploy/configs/inference_cartoon.yaml | 2 +- deploy/configs/inference_det.yaml | 2 +- deploy/configs/inference_drink.yaml | 2 +- deploy/configs/inference_general.yaml | 2 +- deploy/configs/inference_general_binary.yaml | 2 +- deploy/configs/inference_logo.yaml | 2 +- deploy/configs/inference_product.yaml | 2 +- deploy/configs/inference_vehicle.yaml | 2 +- deploy/cpp_shitu/include/object_detector.h | 194 +++++++++---------- deploy/lite_shitu/generate_json_config.py | 2 +- deploy/python/predict_det.py | 2 +- 11 files changed, 107 insertions(+), 107 deletions(-) diff --git a/deploy/configs/inference_cartoon.yaml b/deploy/configs/inference_cartoon.yaml index 7d93d98c..e79da550 100644 --- a/deploy/configs/inference_cartoon.yaml +++ b/deploy/configs/inference_cartoon.yaml @@ -8,7 +8,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 5 - labe_list: + label_list: - foreground use_gpu: True diff --git a/deploy/configs/inference_det.yaml b/deploy/configs/inference_det.yaml index c809a025..dab7908e 100644 --- a/deploy/configs/inference_det.yaml +++ b/deploy/configs/inference_det.yaml @@ -5,7 +5,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 1 - labe_list: + label_list: - foreground # inference engine config diff --git a/deploy/configs/inference_drink.yaml b/deploy/configs/inference_drink.yaml index d044965f..1c3e2c29 100644 --- a/deploy/configs/inference_drink.yaml +++ b/deploy/configs/inference_drink.yaml @@ -8,7 +8,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 5 - labe_list: + label_list: - foreground use_gpu: True diff --git a/deploy/configs/inference_general.yaml b/deploy/configs/inference_general.yaml index 6b397b50..8fb8ae3a 100644 --- a/deploy/configs/inference_general.yaml +++ b/deploy/configs/inference_general.yaml @@ -8,7 +8,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 5 - labe_list: + label_list: - foreground use_gpu: True diff --git a/deploy/configs/inference_general_binary.yaml b/deploy/configs/inference_general_binary.yaml index d76dae8f..72ec31fc 100644 --- a/deploy/configs/inference_general_binary.yaml +++ b/deploy/configs/inference_general_binary.yaml @@ -8,7 +8,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 5 - labe_list: + label_list: - foreground use_gpu: True diff --git a/deploy/configs/inference_logo.yaml b/deploy/configs/inference_logo.yaml index f78ca25a..2b8228ea 100644 --- a/deploy/configs/inference_logo.yaml +++ b/deploy/configs/inference_logo.yaml @@ -8,7 +8,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 5 - labe_list: + label_list: - foreground use_gpu: True diff --git a/deploy/configs/inference_product.yaml b/deploy/configs/inference_product.yaml index e7b494c3..78ba3206 100644 --- a/deploy/configs/inference_product.yaml +++ b/deploy/configs/inference_product.yaml @@ -8,7 +8,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 5 - labe_list: + label_list: - foreground # inference engine config diff --git a/deploy/configs/inference_vehicle.yaml b/deploy/configs/inference_vehicle.yaml index d99f42ad..e289e9f5 100644 --- a/deploy/configs/inference_vehicle.yaml +++ b/deploy/configs/inference_vehicle.yaml @@ -8,7 +8,7 @@ Global: image_shape: [3, 640, 640] threshold: 0.2 max_det_results: 5 - labe_list: + label_list: - foreground use_gpu: True diff --git a/deploy/cpp_shitu/include/object_detector.h b/deploy/cpp_shitu/include/object_detector.h index 5bfc5625..6855a0dc 100644 --- a/deploy/cpp_shitu/include/object_detector.h +++ b/deploy/cpp_shitu/include/object_detector.h @@ -33,106 +33,106 @@ using namespace paddle_infer; namespace Detection { // Object Detection Result - struct ObjectResult { - // Rectangle coordinates of detected object: left, right, top, down - std::vector rect; - // Class id of detected object - int class_id; - // Confidence of detected object - float confidence; - }; +struct ObjectResult { + // Rectangle coordinates of detected object: left, right, top, down + std::vector rect; + // Class id of detected object + int class_id; + // Confidence of detected object + float confidence; +}; // Generate visualization colormap for each class - std::vector GenerateColorMap(int num_class); +std::vector GenerateColorMap(int num_class); // Visualiztion Detection Result - cv::Mat VisualizeResult(const cv::Mat &img, - const std::vector &results, - const std::vector &lables, - const std::vector &colormap, const bool is_rbox); - - class ObjectDetector { - public: - explicit ObjectDetector(const YAML::Node &config_file) { - this->use_gpu_ = config_file["Global"]["use_gpu"].as(); - if (config_file["Global"]["gpu_id"].IsDefined()) - this->gpu_id_ = config_file["Global"]["gpu_id"].as(); - this->gpu_mem_ = config_file["Global"]["gpu_mem"].as(); - this->cpu_math_library_num_threads_ = - config_file["Global"]["cpu_num_threads"].as(); - this->use_mkldnn_ = config_file["Global"]["enable_mkldnn"].as(); - this->use_tensorrt_ = config_file["Global"]["use_tensorrt"].as(); - this->use_fp16_ = config_file["Global"]["use_fp16"].as(); - this->model_dir_ = - config_file["Global"]["det_inference_model_dir"].as(); - this->threshold_ = config_file["Global"]["threshold"].as(); - this->max_det_results_ = config_file["Global"]["max_det_results"].as(); - this->image_shape_ = - config_file["Global"]["image_shape"].as < std::vector < int >> (); - this->label_list_ = - config_file["Global"]["labe_list"].as < std::vector < std::string >> (); - this->ir_optim_ = config_file["Global"]["ir_optim"].as(); - this->batch_size_ = config_file["Global"]["batch_size"].as(); - - preprocessor_.Init(config_file["DetPreProcess"]["transform_ops"]); - LoadModel(model_dir_, batch_size_, run_mode); - } - - // Load Paddle inference model - void LoadModel(const std::string &model_dir, const int batch_size = 1, - const std::string &run_mode = "fluid"); - - // Run predictor - void Predict(const std::vector imgs, const int warmup = 0, - const int repeats = 1, - std::vector *result = nullptr, - std::vector *bbox_num = nullptr, - std::vector *times = nullptr); - - const std::vector &GetLabelList() const { - return this->label_list_; - } - - const float &GetThreshold() const { return this->threshold_; } - - private: - bool use_gpu_ = true; - int gpu_id_ = 0; - int gpu_mem_ = 800; - int cpu_math_library_num_threads_ = 6; - std::string run_mode = "fluid"; - bool use_mkldnn_ = false; - bool use_tensorrt_ = false; - bool batch_size_ = 1; - bool use_fp16_ = false; - std::string model_dir_; - float threshold_ = 0.5; - float max_det_results_ = 5; - std::vector image_shape_ = {3, 640, 640}; - std::vector label_list_; - bool ir_optim_ = true; - bool det_permute_ = true; - bool det_postprocess_ = true; - int min_subgraph_size_ = 30; - bool use_dynamic_shape_ = false; - int trt_min_shape_ = 1; - int trt_max_shape_ = 1280; - int trt_opt_shape_ = 640; - bool trt_calib_mode_ = false; - - // Preprocess image and copy data to input buffer - void Preprocess(const cv::Mat &image_mat); - - // Postprocess result - void Postprocess(const std::vector mats, - std::vector *result, std::vector bbox_num, - bool is_rbox); - - std::shared_ptr predictor_; - Preprocessor preprocessor_; - ImageBlob inputs_; - std::vector output_data_; - std::vector out_bbox_num_data_; - }; +cv::Mat VisualizeResult(const cv::Mat &img, + const std::vector &results, + const std::vector &lables, + const std::vector &colormap, const bool is_rbox); + +class ObjectDetector { +public: + explicit ObjectDetector(const YAML::Node &config_file) { + this->use_gpu_ = config_file["Global"]["use_gpu"].as(); + if (config_file["Global"]["gpu_id"].IsDefined()) + this->gpu_id_ = config_file["Global"]["gpu_id"].as(); + this->gpu_mem_ = config_file["Global"]["gpu_mem"].as(); + this->cpu_math_library_num_threads_ = + config_file["Global"]["cpu_num_threads"].as(); + this->use_mkldnn_ = config_file["Global"]["enable_mkldnn"].as(); + this->use_tensorrt_ = config_file["Global"]["use_tensorrt"].as(); + this->use_fp16_ = config_file["Global"]["use_fp16"].as(); + this->model_dir_ = + config_file["Global"]["det_inference_model_dir"].as(); + this->threshold_ = config_file["Global"]["threshold"].as(); + this->max_det_results_ = config_file["Global"]["max_det_results"].as(); + this->image_shape_ = + config_file["Global"]["image_shape"].as>(); + this->label_list_ = + config_file["Global"]["label_list"].as>(); + this->ir_optim_ = config_file["Global"]["ir_optim"].as(); + this->batch_size_ = config_file["Global"]["batch_size"].as(); + + preprocessor_.Init(config_file["DetPreProcess"]["transform_ops"]); + LoadModel(model_dir_, batch_size_, run_mode); + } + + // Load Paddle inference model + void LoadModel(const std::string &model_dir, const int batch_size = 1, + const std::string &run_mode = "fluid"); + + // Run predictor + void Predict(const std::vector imgs, const int warmup = 0, + const int repeats = 1, + std::vector *result = nullptr, + std::vector *bbox_num = nullptr, + std::vector *times = nullptr); + + const std::vector &GetLabelList() const { + return this->label_list_; + } + + const float &GetThreshold() const { return this->threshold_; } + +private: + bool use_gpu_ = true; + int gpu_id_ = 0; + int gpu_mem_ = 800; + int cpu_math_library_num_threads_ = 6; + std::string run_mode = "fluid"; + bool use_mkldnn_ = false; + bool use_tensorrt_ = false; + bool batch_size_ = 1; + bool use_fp16_ = false; + std::string model_dir_; + float threshold_ = 0.5; + float max_det_results_ = 5; + std::vector image_shape_ = {3, 640, 640}; + std::vector label_list_; + bool ir_optim_ = true; + bool det_permute_ = true; + bool det_postprocess_ = true; + int min_subgraph_size_ = 30; + bool use_dynamic_shape_ = false; + int trt_min_shape_ = 1; + int trt_max_shape_ = 1280; + int trt_opt_shape_ = 640; + bool trt_calib_mode_ = false; + + // Preprocess image and copy data to input buffer + void Preprocess(const cv::Mat &image_mat); + + // Postprocess result + void Postprocess(const std::vector mats, + std::vector *result, std::vector bbox_num, + bool is_rbox); + + std::shared_ptr predictor_; + Preprocessor preprocessor_; + ImageBlob inputs_; + std::vector output_data_; + std::vector out_bbox_num_data_; +}; } // namespace Detection diff --git a/deploy/lite_shitu/generate_json_config.py b/deploy/lite_shitu/generate_json_config.py index 1525cdab..184d500e 100644 --- a/deploy/lite_shitu/generate_json_config.py +++ b/deploy/lite_shitu/generate_json_config.py @@ -95,7 +95,7 @@ def main(): config_json["Global"]["det_model_path"] = args.det_model_path config_json["Global"]["rec_model_path"] = args.rec_model_path config_json["Global"]["rec_label_path"] = args.rec_label_path - config_json["Global"]["label_list"] = config_yaml["Global"]["labe_list"] + config_json["Global"]["label_list"] = config_yaml["Global"]["label_list"] config_json["Global"]["rec_nms_thresold"] = config_yaml["Global"][ "rec_nms_thresold"] config_json["Global"]["max_det_results"] = config_yaml["Global"][ diff --git a/deploy/python/predict_det.py b/deploy/python/predict_det.py index e4e0a24a..1a96a8aa 100644 --- a/deploy/python/predict_det.py +++ b/deploy/python/predict_det.py @@ -134,7 +134,7 @@ class DetPredictor(Predictor): results = self.parse_det_results(results, self.config["Global"]["threshold"], - self.config["Global"]["labe_list"]) + self.config["Global"]["label_list"]) return results -- GitLab