FastDeploy  latest
Fast & Easy to Deploy!
cls_preprocessor.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/vision/common/processors/transform.h"
17 #include "fastdeploy/vision/common/processors/manager.h"
18 #include "fastdeploy/vision/common/result.h"
19 
20 namespace fastdeploy {
21 namespace vision {
22 
23 namespace ocr {
26 class FASTDEPLOY_DECL ClassifierPreprocessor : public ProcessorManager {
27  public:
36  bool Run(std::vector<FDMat>* images, std::vector<FDTensor>* outputs,
37  size_t start_index, size_t end_index);
38 
47  virtual bool Apply(FDMatBatch* image_batch, std::vector<FDTensor>* outputs);
48 
52  void SetNormalize(const std::vector<float>& mean,
53  const std::vector<float>& std,
54  bool is_scale) {
55  normalize_op_ = std::make_shared<Normalize>(mean, std, is_scale);
56  }
57 
59  void SetClsImageShape(const std::vector<int>& cls_image_shape) {
60  cls_image_shape_ = cls_image_shape;
61  }
63  std::vector<int> GetClsImageShape() const { return cls_image_shape_; }
64 
66  void DisableNormalize() { disable_permute_ = true; }
68  void DisablePermute() { disable_normalize_ = true; }
69 
70  private:
71  void OcrClassifierResizeImage(FDMat* mat,
72  const std::vector<int>& cls_image_shape);
73  // for recording the switch of hwc2chw
74  bool disable_permute_ = false;
75  // for recording the switch of normalize
76  bool disable_normalize_ = false;
77  std::vector<int> cls_image_shape_ = {3, 48, 192};
78 
79  std::shared_ptr<Resize> resize_op_;
80  std::shared_ptr<Pad> pad_op_;
81  std::shared_ptr<Normalize> normalize_op_;
82  std::shared_ptr<HWC2CHW> hwc2chw_op_;
83 };
84 
85 } // namespace ocr
86 } // namespace vision
87 } // namespace fastdeploy
void DisablePermute()
This function will disable hwc2chw in preprocessing step.
Definition: cls_preprocessor.h:68
bool Run(std::vector< FDMat > *images, std::vector< FDTensor > *outputs)
Process the input images and prepare input tensors for runtime.
Definition: manager.cc:91
Definition: float16.h:572
void SetNormalize(const std::vector< float > &mean, const std::vector< float > &std, bool is_scale)
Definition: cls_preprocessor.h:52
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
Preprocessor object for Classifier serials model.
Definition: cls_preprocessor.h:26
FDMatBatch contains batch data for preprocess.
Definition: mat_batch.h:28
void SetClsImageShape(const std::vector< int > &cls_image_shape)
Set cls_image_shape for the classification preprocess.
Definition: cls_preprocessor.h:59
ProcessorManager for Preprocess.
Definition: manager.h:27
void DisableNormalize()
This function will disable normalize in preprocessing step.
Definition: cls_preprocessor.h:66
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
std::vector< int > GetClsImageShape() const
Get cls_image_shape for the classification preprocess.
Definition: cls_preprocessor.h:63