FastDeploy  latest
Fast & Easy to Deploy!
resnet.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 
20 // The namespace shoulde be
21 // fastdeploy::vision::classification (fastdeploy::vision::${task})
22 namespace fastdeploy {
23 namespace vision {
27 namespace classification {
30 class FASTDEPLOY_DECL ResNet : public FastDeployModel {
31  public:
39  ResNet(const std::string& model_file,
40  const std::string& params_file = "",
41  const RuntimeOption& custom_option = RuntimeOption(),
42  const ModelFormat& model_format = ModelFormat::ONNX);
43 
44  virtual std::string ModelName() const { return "ResNet"; }
51  virtual bool Predict(cv::Mat* im, ClassifyResult* result, int topk = 1);
55  std::vector<int> size;
59  std::vector<float> mean_vals;
63  std::vector<float> std_vals;
64 
65 
66  private:
69  bool Initialize();
71  bool Preprocess(Mat* mat, FDTensor* outputs);
74  bool Postprocess(FDTensor& infer_result, ClassifyResult* result,
75  int topk = 1);
76 };
77 } // namespace classification
78 } // namespace vision
79 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
Torchvision ResNet series model.
Definition: resnet.h:30
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
ModelFormat
Definition: enum_variables.h:67
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
virtual std::string ModelName() const
Get model&#39;s name.
Definition: resnet.h:44
std::vector< int > size
Argument for image preprocessing step, tuple of (width, height), decide the target size after resize...
Definition: resnet.h:55
Classify result structure for all the image classify models.
Definition: result.h:46
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
Model with ONNX format.
Definition: enum_variables.h:70
std::vector< float > std_vals
Std parameters for normalize, size should be the the same as channels, default std_vals = {0...
Definition: resnet.h:63
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
std::vector< float > mean_vals
Mean parameters for normalize, size should be the the same as channels, default mean_vals = {0...
Definition: resnet.h:59