提交 e1716ded 编写于 作者: D dongshuilong

code format for cls class_infer

上级 3e302147
......@@ -35,8 +35,8 @@ using namespace paddle_infer;
namespace PaddleClas {
class Classifier {
public:
class Classifier {
public:
explicit Classifier(const ClsConfig &config) {
this->use_gpu_ = config.use_gpu;
this->gpu_id_ = config.gpu_id;
......@@ -61,8 +61,8 @@ public:
void Run(cv::Mat &img, std::vector<float> &out_data, std::vector<int> &idx,
std::vector<double> &times);
private:
std::shared_ptr<Predictor> predictor_;
private:
std::shared_ptr <Predictor> predictor_;
bool use_gpu_ = false;
int gpu_id_ = 0;
......@@ -85,6 +85,6 @@ private:
Normalize normalize_op_;
Permute permute_op_;
CenterCropImg crop_op_;
};
};
} // namespace PaddleClas
......@@ -31,8 +31,8 @@
namespace PaddleClas {
class ClsConfig {
public:
class ClsConfig {
public:
explicit ClsConfig(const std::string &path) {
ReadYamlConfig(path);
this->infer_imgs =
......@@ -72,10 +72,10 @@ public:
.as<float>();
this->mean = this->config_file["PreProcess"]["transform_ops"][2]
["NormalizeImage"]["mean"]
.as<std::vector<float>>();
.as < std::vector < float >> ();
this->std = this->config_file["PreProcess"]["transform_ops"][2]
["NormalizeImage"]["std"]
.as<std::vector<float>>();
.as < std::vector < float >> ();
if (this->config_file["Global"]["benchmark"].IsDefined())
this->benchmark = this->config_file["Global"]["benchmark"].as<bool>();
else
......@@ -125,7 +125,9 @@ public:
std::string label_save_dir;
void PrintConfigInfo();
void ReadLabelMap();
void ReadYamlConfig(const std::string &path);
};
};
} // namespace PaddleClas
......@@ -209,7 +209,7 @@ cp ../configs/inference_cls.yaml tools/
根据[python预测推理](../../docs/zh_CN/inference_deployment/python_deploy.md)`图像分类推理`部分修改好`tools`目录下`inference_cls.yaml`文件。`yaml`文件的参数说明详见[python预测推理](../../docs/zh_CN/inference_deployment/python_deploy.md)
请根据实际存放文件,修改好`Global.infer_imgs``Global.inference_model_dir`等参数。
请根据实际存放文件,修改好`Global.infer_imgs``Global.inference_model_dir``PostProcess.Topk.topk``PostProcess.Topk.class_id_map_file`等参数。
#### 2.3.2 执行
......
......@@ -18,7 +18,7 @@
namespace PaddleClas {
void Classifier::LoadModel(const std::string &model_path,
void Classifier::LoadModel(const std::string &model_path,
const std::string &params_path) {
paddle_infer::Config config;
config.SetModel(model_path, params_path);
......@@ -52,9 +52,9 @@ void Classifier::LoadModel(const std::string &model_path,
config.DisableGlogInfo();
this->predictor_ = CreatePredictor(config);
}
}
void Classifier::Run(cv::Mat &img, std::vector<float> &out_data,
void Classifier::Run(cv::Mat &img, std::vector<float> &out_data,
std::vector<int> &idx, std::vector<double> &times) {
cv::Mat srcimg;
cv::Mat resize_img;
......@@ -112,5 +112,5 @@ void Classifier::Run(cv::Mat &img, std::vector<float> &out_data,
/* std::cout << "\tclass id: " << maxPosition << std::endl; */
/* std::cout << std::fixed << std::setprecision(10) */
/* << "\tscore: " << double(out_data[maxPosition]) << std::endl; */
}
}
} // namespace PaddleClas
......@@ -17,13 +17,13 @@
namespace PaddleClas {
void ClsConfig::PrintConfigInfo() {
void ClsConfig::PrintConfigInfo() {
std::cout << "=======Paddle Class inference config======" << std::endl;
std::cout << this->config_file << std::endl;
std::cout << "=======End of Paddle Class inference config======" << std::endl;
}
}
void ClsConfig::ReadYamlConfig(const std::string &path) {
void ClsConfig::ReadYamlConfig(const std::string &path) {
try {
this->config_file = YAML::LoadFile(path);
......@@ -32,9 +32,9 @@ void ClsConfig::ReadYamlConfig(const std::string &path) {
<< std::endl;
exit(1);
}
}
}
void ClsConfig::ReadLabelMap() {
void ClsConfig::ReadLabelMap() {
if (this->class_id_map_path.empty()) {
std::cout << "The Class Label file dose not input" << std::endl;
return;
......@@ -48,5 +48,5 @@ void ClsConfig::ReadLabelMap() {
line.substr(split_flag + 1, line.size());
}
}
}
}
}; // namespace PaddleClas
......@@ -36,8 +36,10 @@ using namespace std;
using namespace cv;
using namespace PaddleClas;
DEFINE_string(config, "", "Path of yaml file");
DEFINE_string(c, "", "Path of yaml file");
DEFINE_string(config,
"", "Path of yaml file");
DEFINE_string(c,
"", "Path of yaml file");
int main(int argc, char **argv) {
google::ParseCommandLineFlags(&argc, &argv, true);
......@@ -58,9 +60,9 @@ int main(int argc, char **argv) {
std::string path(config.infer_imgs);
std::vector<std::string> img_files_list;
std::vector <std::string> img_files_list;
if (cv::utils::fs::isDirectory(path)) {
std::vector<cv::String> filenames;
std::vector <cv::String> filenames;
cv::glob(path, filenames);
for (auto f : filenames) {
img_files_list.push_back(f);
......
......@@ -20,10 +20,10 @@
namespace PaddleClas {
std::vector<std::string> Utility::ReadDict(const std::string &path) {
std::vector <std::string> Utility::ReadDict(const std::string &path) {
std::ifstream in(path);
std::string line;
std::vector<std::string> m_vec;
std::vector <std::string> m_vec;
if (in) {
while (getline(in, line)) {
m_vec.push_back(line);
......@@ -34,6 +34,6 @@ std::vector<std::string> Utility::ReadDict(const std::string &path) {
exit(1);
}
return m_vec;
}
}
} // namespace PaddleClas
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册