提交 de726400 编写于 作者: D dongshuilong

code format

上级 87873447
...@@ -215,9 +215,9 @@ cp ../configs/inference_cls.yaml tools/ ...@@ -215,9 +215,9 @@ cp ../configs/inference_cls.yaml tools/
#### 2.3.2 执行 #### 2.3.2 执行
```shell ```shell
./build/clas_system -c inference_cls.yaml ./build/clas_system -c tools/inference_cls.yaml
# or # or
./build/clas_system -config inference_cls.yaml ./build/clas_system -config tools/inference_cls.yaml
``` ```
最终屏幕上会输出结果,如下图所示。 最终屏幕上会输出结果,如下图所示。
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace Feature { namespace Feature {
void FeatureExtracter::LoadModel(const std::string &model_path, void FeatureExtracter::LoadModel(const std::string &model_path,
const std::string &params_path) { const std::string &params_path) {
paddle_infer::Config config; paddle_infer::Config config;
config.SetModel(model_path, params_path); config.SetModel(model_path, params_path);
...@@ -52,9 +52,9 @@ void FeatureExtracter::LoadModel(const std::string &model_path, ...@@ -52,9 +52,9 @@ void FeatureExtracter::LoadModel(const std::string &model_path,
config.DisableGlogInfo(); config.DisableGlogInfo();
this->predictor_ = CreatePredictor(config); this->predictor_ = CreatePredictor(config);
} }
void FeatureExtracter::Run(cv::Mat &img, std::vector<float> &out_data, void FeatureExtracter::Run(cv::Mat &img, std::vector<float> &out_data,
std::vector<double> &times) { std::vector<double> &times) {
cv::Mat resize_img; cv::Mat resize_img;
std::vector<double> time; std::vector<double> time;
...@@ -108,12 +108,12 @@ void FeatureExtracter::Run(cv::Mat &img, std::vector<float> &out_data, ...@@ -108,12 +108,12 @@ void FeatureExtracter::Run(cv::Mat &img, std::vector<float> &out_data,
times[0] += time[0]; times[0] += time[0];
times[1] += time[1]; times[1] += time[1];
times[2] += time[2]; times[2] += time[2];
} }
void FeatureExtracter::FeatureNorm(std::vector<float> &featuer) { void FeatureExtracter::FeatureNorm(std::vector<float> &featuer) {
float featuer_sqrt = std::sqrt(std::inner_product( float featuer_sqrt = std::sqrt(std::inner_product(
featuer.begin(), featuer.end(), featuer.begin(), 0.0f)); featuer.begin(), featuer.end(), featuer.begin(), 0.0f));
for (int i = 0; i < featuer.size(); ++i) for (int i = 0; i < featuer.size(); ++i)
featuer[i] /= featuer_sqrt; featuer[i] /= featuer_sqrt;
} }
} // namespace Feature } // namespace Feature
...@@ -37,13 +37,15 @@ ...@@ -37,13 +37,15 @@
using namespace std; using namespace std;
using namespace cv; using namespace cv;
DEFINE_string(config, "", "Path of yaml file"); DEFINE_string(config,
DEFINE_string(c, "", "Path of yaml file"); "", "Path of yaml file");
DEFINE_string(c,
"", "Path of yaml file");
void DetPredictImage(const std::vector<cv::Mat> &batch_imgs, void DetPredictImage(const std::vector <cv::Mat> &batch_imgs,
const std::vector<std::string> &all_img_paths, const std::vector <std::string> &all_img_paths,
const int batch_size, Detection::ObjectDetector *det, const int batch_size, Detection::ObjectDetector *det,
std::vector<Detection::ObjectResult> &im_result, std::vector <Detection::ObjectResult> &im_result,
std::vector<int> &im_bbox_num, std::vector<double> &det_t, std::vector<int> &im_bbox_num, std::vector<double> &det_t,
const bool visual_det = false, const bool visual_det = false,
const bool run_benchmark = false, const bool run_benchmark = false,
...@@ -63,7 +65,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs, ...@@ -63,7 +65,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs,
// } // }
// Store all detected result // Store all detected result
std::vector<Detection::ObjectResult> result; std::vector <Detection::ObjectResult> result;
std::vector<int> bbox_num; std::vector<int> bbox_num;
std::vector<double> det_times; std::vector<double> det_times;
bool is_rbox = false; bool is_rbox = false;
...@@ -134,7 +136,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs, ...@@ -134,7 +136,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs,
} }
void PrintResult(std::string &img_path, void PrintResult(std::string &img_path,
std::vector<Detection::ObjectResult> &det_result, std::vector <Detection::ObjectResult> &det_result,
std::vector<int> &indeices, VectorSearch &vector_search, std::vector<int> &indeices, VectorSearch &vector_search,
SearchResult &search_result) { SearchResult &search_result) {
printf("%s:\n", img_path.c_str()); printf("%s:\n", img_path.c_str());
...@@ -194,9 +196,9 @@ int main(int argc, char **argv) { ...@@ -194,9 +196,9 @@ int main(int argc, char **argv) {
// load image_file_path // load image_file_path
std::string path = std::string path =
config.config_file["Global"]["infer_imgs"].as<std::string>(); config.config_file["Global"]["infer_imgs"].as<std::string>();
std::vector<std::string> img_files_list; std::vector <std::string> img_files_list;
if (cv::utils::fs::isDirectory(path)) { if (cv::utils::fs::isDirectory(path)) {
std::vector<cv::String> filenames; std::vector <cv::String> filenames;
cv::glob(path, filenames); cv::glob(path, filenames);
for (auto f : filenames) { for (auto f : filenames) {
img_files_list.push_back(f); img_files_list.push_back(f);
...@@ -211,10 +213,10 @@ int main(int argc, char **argv) { ...@@ -211,10 +213,10 @@ int main(int argc, char **argv) {
std::vector<double> search_times = {0, 0, 0}; std::vector<double> search_times = {0, 0, 0};
int instance_num = 0; int instance_num = 0;
// for read images // for read images
std::vector<cv::Mat> batch_imgs; std::vector <cv::Mat> batch_imgs;
std::vector<std::string> img_paths; std::vector <std::string> img_paths;
// for detection // for detection
std::vector<Detection::ObjectResult> det_result; std::vector <Detection::ObjectResult> det_result;
std::vector<int> det_bbox_num; std::vector<int> det_bbox_num;
// for vector search // for vector search
std::vector<float> features; std::vector<float> features;
...@@ -318,7 +320,7 @@ int main(int argc, char **argv) { ...@@ -318,7 +320,7 @@ int main(int argc, char **argv) {
config.config_file["Global"]["cpu_num_threads"].as<int>(); config.config_file["Global"]["cpu_num_threads"].as<int>();
int batch_size = config.config_file["Global"]["batch_size"].as<int>(); int batch_size = config.config_file["Global"]["batch_size"].as<int>();
std::vector<int> shape = std::vector<int> shape =
config.config_file["Global"]["image_shape"].as<std::vector<int>>(); config.config_file["Global"]["image_shape"].as < std::vector < int >> ();
std::string det_shape = std::to_string(shape[0]); std::string det_shape = std::to_string(shape[0]);
for (int i = 1; i < shape.size(); ++i) for (int i = 1; i < shape.size(); ++i)
det_shape = det_shape + ", " + std::to_string(shape[i]); det_shape = det_shape + ", " + std::to_string(shape[i]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册