add mkldnn config
This commit is contained in:
parent
7b876e0e65
commit
77d9683c28
|
@ -39,6 +39,8 @@ public:
|
||||||
this->cpu_math_library_num_threads =
|
this->cpu_math_library_num_threads =
|
||||||
stoi(config_map_["cpu_math_library_num_threads"]);
|
stoi(config_map_["cpu_math_library_num_threads"]);
|
||||||
|
|
||||||
|
this->use_mkldnn = bool(stoi(config_map_["use_mkldnn"]));
|
||||||
|
|
||||||
this->max_side_len = stoi(config_map_["max_side_len"]);
|
this->max_side_len = stoi(config_map_["max_side_len"]);
|
||||||
|
|
||||||
this->det_db_thresh = stod(config_map_["det_db_thresh"]);
|
this->det_db_thresh = stod(config_map_["det_db_thresh"]);
|
||||||
|
@ -64,6 +66,8 @@ public:
|
||||||
|
|
||||||
int cpu_math_library_num_threads = 1;
|
int cpu_math_library_num_threads = 1;
|
||||||
|
|
||||||
|
bool use_mkldnn = false;
|
||||||
|
|
||||||
int max_side_len = 960;
|
int max_side_len = 960;
|
||||||
|
|
||||||
double det_db_thresh = 0.3;
|
double det_db_thresh = 0.3;
|
||||||
|
|
|
@ -39,7 +39,8 @@ public:
|
||||||
explicit DBDetector(const std::string &model_dir, const bool &use_gpu,
|
explicit DBDetector(const std::string &model_dir, const bool &use_gpu,
|
||||||
const int &gpu_id, const int &gpu_mem,
|
const int &gpu_id, const int &gpu_mem,
|
||||||
const int &cpu_math_library_num_threads,
|
const int &cpu_math_library_num_threads,
|
||||||
const int &max_side_len, const double &det_db_thresh,
|
const bool &use_mkldnn, const int &max_side_len,
|
||||||
|
const double &det_db_thresh,
|
||||||
const double &det_db_box_thresh,
|
const double &det_db_box_thresh,
|
||||||
const double &det_db_unclip_ratio,
|
const double &det_db_unclip_ratio,
|
||||||
const bool &visualize) {
|
const bool &visualize) {
|
||||||
|
@ -47,6 +48,7 @@ public:
|
||||||
this->gpu_id_ = gpu_id;
|
this->gpu_id_ = gpu_id;
|
||||||
this->gpu_mem_ = gpu_mem;
|
this->gpu_mem_ = gpu_mem;
|
||||||
this->cpu_math_library_num_threads_ = cpu_math_library_num_threads;
|
this->cpu_math_library_num_threads_ = cpu_math_library_num_threads;
|
||||||
|
this->use_mkldnn_ = use_mkldnn;
|
||||||
|
|
||||||
this->max_side_len_ = max_side_len;
|
this->max_side_len_ = max_side_len;
|
||||||
|
|
||||||
|
@ -72,6 +74,7 @@ private:
|
||||||
int gpu_id_ = 0;
|
int gpu_id_ = 0;
|
||||||
int gpu_mem_ = 4000;
|
int gpu_mem_ = 4000;
|
||||||
int cpu_math_library_num_threads_ = 4;
|
int cpu_math_library_num_threads_ = 4;
|
||||||
|
bool use_mkldnn_ = false;
|
||||||
|
|
||||||
int max_side_len_ = 960;
|
int max_side_len_ = 960;
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,12 @@ public:
|
||||||
explicit CRNNRecognizer(const std::string &model_dir, const bool &use_gpu,
|
explicit CRNNRecognizer(const std::string &model_dir, const bool &use_gpu,
|
||||||
const int &gpu_id, const int &gpu_mem,
|
const int &gpu_id, const int &gpu_mem,
|
||||||
const int &cpu_math_library_num_threads,
|
const int &cpu_math_library_num_threads,
|
||||||
const string &label_path) {
|
const bool &use_mkldnn, const string &label_path) {
|
||||||
this->use_gpu_ = use_gpu;
|
this->use_gpu_ = use_gpu;
|
||||||
this->gpu_id_ = gpu_id;
|
this->gpu_id_ = gpu_id;
|
||||||
this->gpu_mem_ = gpu_mem;
|
this->gpu_mem_ = gpu_mem;
|
||||||
this->cpu_math_library_num_threads_ = cpu_math_library_num_threads;
|
this->cpu_math_library_num_threads_ = cpu_math_library_num_threads;
|
||||||
|
this->use_mkldnn_ = use_mkldnn;
|
||||||
|
|
||||||
this->label_list_ = Utility::ReadDict(label_path);
|
this->label_list_ = Utility::ReadDict(label_path);
|
||||||
|
|
||||||
|
@ -61,6 +62,7 @@ private:
|
||||||
int gpu_id_ = 0;
|
int gpu_id_ = 0;
|
||||||
int gpu_mem_ = 4000;
|
int gpu_mem_ = 4000;
|
||||||
int cpu_math_library_num_threads_ = 4;
|
int cpu_math_library_num_threads_ = 4;
|
||||||
|
bool use_mkldnn_ = false;
|
||||||
|
|
||||||
std::vector<std::string> label_list_;
|
std::vector<std::string> label_list_;
|
||||||
|
|
||||||
|
|
|
@ -50,12 +50,12 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
DBDetector det(config.det_model_dir, config.use_gpu, config.gpu_id,
|
DBDetector det(config.det_model_dir, config.use_gpu, config.gpu_id,
|
||||||
config.gpu_mem, config.cpu_math_library_num_threads,
|
config.gpu_mem, config.cpu_math_library_num_threads,
|
||||||
config.max_side_len, config.det_db_thresh,
|
config.use_mkldnn, config.max_side_len, config.det_db_thresh,
|
||||||
config.det_db_box_thresh, config.det_db_unclip_ratio,
|
config.det_db_box_thresh, config.det_db_unclip_ratio,
|
||||||
config.visualize);
|
config.visualize);
|
||||||
CRNNRecognizer rec(config.rec_model_dir, config.use_gpu, config.gpu_id,
|
CRNNRecognizer rec(config.rec_model_dir, config.use_gpu, config.gpu_id,
|
||||||
config.gpu_mem, config.cpu_math_library_num_threads,
|
config.gpu_mem, config.cpu_math_library_num_threads,
|
||||||
config.char_list_file);
|
config.use_mkldnn, config.char_list_file);
|
||||||
|
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
std::vector<std::vector<std::vector<int>>> boxes;
|
std::vector<std::vector<std::vector<int>>> boxes;
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <include/ocr_det.h>
|
#include <include/ocr_det.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
namespace PaddleOCR {
|
namespace PaddleOCR {
|
||||||
|
|
||||||
|
@ -25,7 +24,9 @@ void DBDetector::LoadModel(const std::string &model_dir) {
|
||||||
config.EnableUseGpu(this->gpu_mem_, this->gpu_id_);
|
config.EnableUseGpu(this->gpu_mem_, this->gpu_id_);
|
||||||
} else {
|
} else {
|
||||||
config.DisableGpu();
|
config.DisableGpu();
|
||||||
// config.EnableMKLDNN(); // not sugesteed to use for now
|
if (this->use_mkldnn_) {
|
||||||
|
config.EnableMKLDNN();
|
||||||
|
}
|
||||||
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,21 +12,6 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "opencv2/core.hpp"
|
|
||||||
#include "opencv2/imgcodecs.hpp"
|
|
||||||
#include "opencv2/imgproc.hpp"
|
|
||||||
#include "paddle_api.h"
|
|
||||||
#include "paddle_inference_api.h"
|
|
||||||
#include <chrono>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
|
||||||
#include <ostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <fstream>
|
|
||||||
#include <numeric>
|
|
||||||
|
|
||||||
#include <include/ocr_rec.h>
|
#include <include/ocr_rec.h>
|
||||||
|
|
||||||
namespace PaddleOCR {
|
namespace PaddleOCR {
|
||||||
|
@ -128,7 +113,9 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
|
||||||
config.EnableUseGpu(this->gpu_mem_, this->gpu_id_);
|
config.EnableUseGpu(this->gpu_mem_, this->gpu_id_);
|
||||||
} else {
|
} else {
|
||||||
config.DisableGpu();
|
config.DisableGpu();
|
||||||
// config.EnableMKLDNN(); // not sugesteed to use for now
|
if (this->use_mkldnn_) {
|
||||||
|
config.EnableMKLDNN();
|
||||||
|
}
|
||||||
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ use_gpu 0
|
||||||
gpu_id 0
|
gpu_id 0
|
||||||
gpu_mem 4000
|
gpu_mem 4000
|
||||||
cpu_math_library_num_threads 10
|
cpu_math_library_num_threads 10
|
||||||
|
use_mkldnn 0
|
||||||
|
|
||||||
# det config
|
# det config
|
||||||
max_side_len 960
|
max_side_len 960
|
||||||
|
|
Loading…
Reference in New Issue