Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
WenmuZhou committed Sep 20, 2022
1 parent b913f66 commit dd9f48d
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 266 deletions.
16 changes: 1 addition & 15 deletions deploy/cpp_infer/include/ocr_cls.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,12 @@

#pragma once

#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/preprocess_op.h>
#include <include/utility.h>

using namespace paddle_infer;

namespace PaddleOCR {

class Classifier {
Expand Down Expand Up @@ -66,7 +52,7 @@ class Classifier {
std::vector<float> &cls_scores, std::vector<double> &times);

private:
std::shared_ptr<Predictor> predictor_;
std::shared_ptr<paddle_infer::Predictor> predictor_;

bool use_gpu_ = false;
int gpu_id_ = 0;
Expand Down
20 changes: 3 additions & 17 deletions deploy/cpp_infer/include/ocr_det.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,20 @@

#pragma once

#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/postprocess_op.h>
#include <include/preprocess_op.h>

using namespace paddle_infer;

namespace PaddleOCR {

class DBDetector {
public:
explicit DBDetector(const std::string &model_dir, const bool &use_gpu,
const int &gpu_id, const int &gpu_mem,
const int &cpu_math_library_num_threads,
const bool &use_mkldnn, const string &limit_type,
const bool &use_mkldnn, const std::string &limit_type,
const int &limit_side_len, const double &det_db_thresh,
const double &det_db_box_thresh,
const double &det_db_unclip_ratio,
Expand Down Expand Up @@ -77,15 +63,15 @@ class DBDetector {
std::vector<double> &times);

private:
std::shared_ptr<Predictor> predictor_;
std::shared_ptr<paddle_infer::Predictor> predictor_;

bool use_gpu_ = false;
int gpu_id_ = 0;
int gpu_mem_ = 4000;
int cpu_math_library_num_threads_ = 4;
bool use_mkldnn_ = false;

string limit_type_ = "max";
std::string limit_type_ = "max";
int limit_side_len_ = 960;

double det_db_thresh_ = 0.3;
Expand Down
19 changes: 2 additions & 17 deletions deploy/cpp_infer/include/ocr_rec.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,20 @@

#pragma once

#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_cls.h>
#include <include/preprocess_op.h>
#include <include/utility.h>

using namespace paddle_infer;

namespace PaddleOCR {

class CRNNRecognizer {
public:
explicit CRNNRecognizer(const std::string &model_dir, const bool &use_gpu,
const int &gpu_id, const int &gpu_mem,
const int &cpu_math_library_num_threads,
const bool &use_mkldnn, const string &label_path,
const bool &use_mkldnn, const std::string &label_path,
const bool &use_tensorrt,
const std::string &precision,
const int &rec_batch_num, const int &rec_img_h,
Expand Down Expand Up @@ -75,7 +60,7 @@ class CRNNRecognizer {
std::vector<float> &rec_text_scores, std::vector<double> &times);

private:
std::shared_ptr<Predictor> predictor_;
std::shared_ptr<paddle_infer::Predictor> predictor_;

bool use_gpu_ = false;
int gpu_id_ = 0;
Expand Down
19 changes: 0 additions & 19 deletions deploy/cpp_infer/include/paddleocr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,9 @@

#pragma once

#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_cls.h>
#include <include/ocr_det.h>
#include <include/ocr_rec.h>
#include <include/preprocess_op.h>
#include <include/utility.h>

using namespace paddle_infer;

namespace PaddleOCR {

Expand Down
19 changes: 0 additions & 19 deletions deploy/cpp_infer/include/paddlestructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,9 @@

#pragma once

#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/paddleocr.h>
#include <include/preprocess_op.h>
#include <include/structure_layout.h>
#include <include/structure_table.h>
#include <include/utility.h>

using namespace paddle_infer;

namespace PaddleOCR {

Expand Down
41 changes: 2 additions & 39 deletions deploy/cpp_infer/include/postprocess_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,9 @@

#pragma once

#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include <chrono>
#include <iomanip>
#include <iostream>
#include <ostream>
#include <vector>

#include <cstring>
#include <fstream>
#include <numeric>

#include "include/clipper.h"
#include "include/utility.h"

using namespace std;

namespace PaddleOCR {

class DBPostProcessor {
Expand Down Expand Up @@ -92,23 +77,7 @@ class DBPostProcessor {

class TablePostProcessor {
public:
void init(std::string label_path, bool merge_no_span_structure = true) {
this->label_list_ = Utility::ReadDict(label_path);
if (merge_no_span_structure) {
this->label_list_.push_back("<td></td>");
std::vector<std::string>::iterator it;
for (it = this->label_list_.begin(); it != this->label_list_.end();) {
if (*it == "<td>") {
it = this->label_list_.erase(it);
} else {
++it;
}
}
}
// add_special_char
this->label_list_.insert(this->label_list_.begin(), this->beg);
this->label_list_.push_back(this->end);
}
void init(std::string label_path, bool merge_no_span_structure = true);
void Run(std::vector<float> &loc_preds, std::vector<float> &structure_probs,
std::vector<float> &rec_scores, std::vector<int> &loc_preds_shape,
std::vector<int> &structure_probs_shape,
Expand All @@ -126,13 +95,7 @@ class PicodetPostProcessor {
public:
void init(std::string label_path, const double score_threshold = 0.4,
const double nms_threshold = 0.5,
const std::vector<int> &fpn_stride = {8, 16, 32, 64}) {
this->label_list_ = Utility::ReadDict(label_path);
this->score_threshold_ = score_threshold;
this->nms_threshold_ = nms_threshold;
this->num_class_ = label_list_.size();
this->fpn_stride_ = fpn_stride;
}
const std::vector<int> &fpn_stride = {8, 16, 32, 64});
void Run(std::vector<StructurePredictResult> &results,
std::vector<std::vector<float>> outs, std::vector<int> ori_shape,
std::vector<int> resize_shape, int eg_max);
Expand Down
21 changes: 6 additions & 15 deletions deploy/cpp_infer/include/preprocess_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,12 @@

#pragma once

#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include <chrono>
#include <iomanip>
#include <iostream>
#include <ostream>
#include <vector>

#include <cstring>
#include <fstream>
#include <numeric>

using namespace std;
using namespace paddle;
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"

namespace PaddleOCR {

Expand All @@ -51,9 +42,9 @@ class PermuteBatch {

class ResizeImgType0 {
public:
virtual void Run(const cv::Mat &img, cv::Mat &resize_img, string limit_type,
int limit_side_len, float &ratio_h, float &ratio_w,
bool use_tensorrt);
virtual void Run(const cv::Mat &img, cv::Mat &resize_img,
std::string limit_type, int limit_side_len, float &ratio_h,
float &ratio_w, bool use_tensorrt);
};

class CrnnResizeImg {
Expand Down
19 changes: 2 additions & 17 deletions deploy/cpp_infer/include/structure_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,11 @@

#pragma once

#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/postprocess_op.h>
#include <include/preprocess_op.h>
#include <include/utility.h>

using namespace paddle_infer;

namespace PaddleOCR {

Expand All @@ -42,7 +27,7 @@ class StructureLayoutRecognizer {
explicit StructureLayoutRecognizer(
const std::string &model_dir, const bool &use_gpu, const int &gpu_id,
const int &gpu_mem, const int &cpu_math_library_num_threads,
const bool &use_mkldnn, const string &label_path,
const bool &use_mkldnn, const std::string &label_path,
const bool &use_tensorrt, const std::string &precision,
const double &layout_score_threshold,
const double &layout_nms_threshold) {
Expand All @@ -66,7 +51,7 @@ class StructureLayoutRecognizer {
std::vector<double> &times);

private:
std::shared_ptr<Predictor> predictor_;
std::shared_ptr<paddle_infer::Predictor> predictor_;

bool use_gpu_ = false;
int gpu_id_ = 0;
Expand Down
19 changes: 2 additions & 17 deletions deploy/cpp_infer/include/structure_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,11 @@

#pragma once

#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/postprocess_op.h>
#include <include/preprocess_op.h>
#include <include/utility.h>

using namespace paddle_infer;

namespace PaddleOCR {

Expand All @@ -42,7 +27,7 @@ class StructureTableRecognizer {
explicit StructureTableRecognizer(
const std::string &model_dir, const bool &use_gpu, const int &gpu_id,
const int &gpu_mem, const int &cpu_math_library_num_threads,
const bool &use_mkldnn, const string &label_path,
const bool &use_mkldnn, const std::string &label_path,
const bool &use_tensorrt, const std::string &precision,
const int &table_batch_num, const int &table_max_len,
const bool &merge_no_span_structure) {
Expand Down Expand Up @@ -70,7 +55,7 @@ class StructureTableRecognizer {
std::vector<double> &times);

private:
std::shared_ptr<Predictor> predictor_;
std::shared_ptr<paddle_infer::Predictor> predictor_;

bool use_gpu_ = false;
int gpu_id_ = 0;
Expand Down
Loading

0 comments on commit dd9f48d

Please sign in to comment.