FastDeploy  latest
Fast & Easy to Deploy!
classifier.h
1 // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 #include "fastdeploy/fastdeploy_model.h"
17 #include "fastdeploy/vision/common/processors/transform.h"
18 #include "fastdeploy/vision/common/result.h"
19 #include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h"
20 #include "fastdeploy/vision/ocr/ppocr/cls_postprocessor.h"
21 #include "fastdeploy/vision/ocr/ppocr/cls_preprocessor.h"
22 #include "fastdeploy/utils/unique_ptr.h"
23 
24 namespace fastdeploy {
25 namespace vision {
29 namespace ocr {
32 class FASTDEPLOY_DECL Classifier : public FastDeployModel {
33  public:
34  Classifier();
42  Classifier(const std::string& model_file, const std::string& params_file = "",
43  const RuntimeOption& custom_option = RuntimeOption(),
44  const ModelFormat& model_format = ModelFormat::PADDLE);
45 
50  virtual std::unique_ptr<Classifier> Clone() const;
51 
53  std::string ModelName() const { return "ppocr/ocr_cls"; }
54 
62  virtual bool Predict(const cv::Mat& img,
63  int32_t* cls_label, float* cls_score);
64 
71  virtual bool Predict(const cv::Mat& img, vision::OCRResult* ocr_result);
72 
79  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
80  vision::OCRResult* ocr_result);
81 
89  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
90  std::vector<int32_t>* cls_labels,
91  std::vector<float>* cls_scores);
92  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
93  std::vector<int32_t>* cls_labels,
94  std::vector<float>* cls_scores,
95  size_t start_index, size_t end_index);
96 
99  return preprocessor_;
100  }
101 
104  return postprocessor_;
105  }
106 
107  private:
108  bool Initialize();
109  ClassifierPreprocessor preprocessor_;
110  ClassifierPostprocessor postprocessor_;
111 };
112 
113 } // namespace ocr
114 } // namespace vision
115 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
Classifier object is used to load the classification model provided by PaddleOCR. ...
Definition: classifier.h:32
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
ModelFormat
Definition: enum_variables.h:67
Postprocessor object for Classifier serials model.
Definition: cls_postprocessor.h:26
Preprocessor object for Classifier serials model.
Definition: cls_preprocessor.h:26
virtual ClassifierPostprocessor & GetPostprocessor()
Get postprocessor reference of ClassifierPostprocessor.
Definition: classifier.h:103
Model with paddlepaddle format.
Definition: enum_variables.h:69
std::string ModelName() const
Get model&#39;s name.
Definition: classifier.h:53
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
virtual ClassifierPreprocessor & GetPreprocessor()
Get preprocessor reference of ClassifierPreprocessor.
Definition: classifier.h:98