FastDeploy  latest
Fast & Easy to Deploy!
model.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/classification/ppcls/preprocessor.h"
18 #include "fastdeploy/vision/classification/ppcls/postprocessor.h"
19 
20 namespace fastdeploy {
21 namespace vision {
25 namespace classification {
28 class FASTDEPLOY_DECL PaddleClasModel : public FastDeployModel {
29  public:
38  PaddleClasModel(const std::string& model_file, const std::string& params_file,
39  const std::string& config_file,
40  const RuntimeOption& custom_option = RuntimeOption(),
41  const ModelFormat& model_format = ModelFormat::PADDLE);
42 
47  virtual std::unique_ptr<PaddleClasModel> Clone() const;
48 
50  virtual std::string ModelName() const { return "PaddleClas/Model"; }
51 
58  virtual bool Predict(cv::Mat* im, ClassifyResult* result, int topk = 1);
59 
60 
67  virtual bool Predict(const cv::Mat& img, ClassifyResult* result);
68 
75  virtual bool BatchPredict(const std::vector<cv::Mat>& imgs,
76  std::vector<ClassifyResult>* results);
77 
84  virtual bool Predict(const FDMat& mat, ClassifyResult* result);
85 
92  virtual bool BatchPredict(const std::vector<FDMat>& mats,
93  std::vector<ClassifyResult>* results);
94 
97  return preprocessor_;
98  }
99 
102  return postprocessor_;
103  }
104 
105  protected:
106  bool Initialize();
107  PaddleClasPreprocessor preprocessor_;
108  PaddleClasPostprocessor postprocessor_;
109 };
110 
111 typedef PaddleClasModel PPLCNet;
112 typedef PaddleClasModel PPLCNetv2;
114 typedef PaddleClasModel GhostNet;
121 typedef PaddleClasModel PPHGNet;
124 } // namespace classification
125 } // namespace vision
126 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
Preprocessor object for PaddleClas serials model.
Definition: preprocessor.h:26
ModelFormat
Definition: enum_variables.h:67
Postprocessor object for PaddleClas serials model.
Definition: postprocessor.h:25
virtual PaddleClasPreprocessor & GetPreprocessor()
Get preprocessor reference of PaddleClasModel.
Definition: model.h:96
PaddleClas serials model object used when to load a PaddleClas model exported by PaddleClas repositor...
Definition: model.h:28
Classify result structure for all the image classify models.
Definition: result.h:46
virtual PaddleClasPostprocessor & GetPostprocessor()
Get postprocessor reference of PaddleClasModel.
Definition: model.h:101
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
Model with paddlepaddle format.
Definition: enum_variables.h:69
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
virtual std::string ModelName() const
Get model&#39;s name.
Definition: model.h:50