2 #ifndef _NNDEPLOY_CLASSIFICATION_CLASSIFICATION_H_
3 #define _NNDEPLOY_CLASSIFICATION_CLASSIFICATION_H_
29 namespace classification {
34 bool is_softmax_ =
true;
39 rapidjson::Document::AllocatorType &allocator);
47 key_ =
"nndeploy::classification::ClassificationPostProcess";
48 desc_ =
"Classification postprocess[device::Tensor->ClassificationResult]";
49 param_ = std::make_shared<ClassificationPostParam>();
50 this->setInputTypeInfo<device::Tensor>();
51 this->setOutputTypeInfo<ClassificationResult>();
54 std::vector<dag::Edge *> inputs,
55 std::vector<dag::Edge *> outputs)
56 : dag::Node(name, inputs, outputs) {
57 key_ =
"nndeploy::classification::ClassificationPostProcess";
58 desc_ =
"Classification postprocess[device::Tensor->ClassificationResult]";
59 param_ = std::make_shared<ClassificationPostParam>();
60 this->setInputTypeInfo<device::Tensor>();
61 this->setOutputTypeInfo<ClassificationResult>();
79 key_ =
"nndeploy::classification::ClassificationGraph";
82 "graph[cv::Mat->preprocess->infer->postprocess->ClassificationResult]";
83 this->setInputTypeInfo<cv::Mat>();
84 this->setOutputTypeInfo<ClassificationResult>();
86 this->createNode<preprocess::CvtResizeCropNormTrans>(
"preprocess"));
88 dynamic_cast<infer::Infer *
>(this->createNode<infer::Infer>(
"infer"));
90 this->createNode<ClassificationPostProcess>(
"postprocess"));
93 std::vector<dag::Edge *> outputs)
94 : dag::Graph(name, inputs, outputs) {
95 key_ =
"nndeploy::classification::ClassificationGraph";
98 "graph[cv::Mat->preprocess->infer->postprocess->ClassificationResult]";
99 this->setInputTypeInfo<cv::Mat>();
100 this->setOutputTypeInfo<ClassificationResult>();
102 this->createNode<preprocess::CvtResizeCropNormTrans>(
"preprocess"));
104 dynamic_cast<infer::Infer *
>(this->createNode<infer::Infer>(
"infer"));
106 this->createNode<ClassificationPostProcess>(
"postprocess"));
136 pre_param->
mean_[0] = 0.485;
137 pre_param->
mean_[1] = 0.456;
138 pre_param->
mean_[2] = 0.406;
139 pre_param->
std_[0] = 0.229;
140 pre_param->
std_[1] = 0.224;
141 pre_param->
std_[2] = 0.225;
147 post_param->
topk_ = 1;
156 this->setNodeDesc(pre_, pre_desc);
157 this->setNodeDesc(infer_, infer_desc);
158 this->setNodeDesc(post_, post_desc);
159 this->defaultParam();
160 base::Status status = infer_->setInferenceType(inference_type);
169 base::Status status = infer_->setInferenceType(inference_type);
179 std::vector<std::string> &model_value) {
183 param->model_type_ = model_type;
184 param->is_path_ = is_path;
185 param->model_value_ = model_value;
216 std::vector<dag::Edge *>
forward(std::vector<dag::Edge *> inputs) {
217 inputs = (*pre_)(inputs);
218 inputs = (*infer_)(inputs);
219 std::vector<dag::Edge *> outputs = (*post_)(inputs);
240 key_ =
"nndeploy::classification::ResnetGraph";
243 "graph[cv::Mat->preprocess->infer->postprocess->ClassificationResult]";
244 this->setInputTypeInfo<cv::Mat>();
245 this->setOutputTypeInfo<ClassificationResult>();
247 this->createNode<preprocess::CvtResizeNormTrans>(
"preprocess"));
249 dynamic_cast<infer::Infer *
>(this->createNode<infer::Infer>(
"infer"));
251 this->createNode<ClassificationPostProcess>(
"postprocess"));
253 ResnetGraph(
const std::string &name, std::vector<dag::Edge *> inputs,
254 std::vector<dag::Edge *> outputs)
255 : dag::Graph(name, inputs, outputs) {
256 key_ =
"nndeploy::classification::ClassificationGraph";
259 "graph[cv::Mat->preprocess->infer->postprocess->ClassificationResult]";
260 this->setInputTypeInfo<cv::Mat>();
261 this->setOutputTypeInfo<ClassificationResult>();
263 this->createNode<preprocess::CvtResizeNormTrans>(
"preprocess"));
265 dynamic_cast<infer::Infer *
>(this->createNode<infer::Infer>(
"infer"));
267 this->createNode<ClassificationPostProcess>(
"postprocess"));
280 pre_param->
mean_[0] = 0.485;
281 pre_param->
mean_[1] = 0.456;
282 pre_param->
mean_[2] = 0.406;
283 pre_param->
std_[0] = 0.229;
284 pre_param->
std_[1] = 0.224;
285 pre_param->
std_[2] = 0.225;
289 post_param->
topk_ = 1;
298 this->setNodeDesc(pre_, pre_desc);
299 this->setNodeDesc(infer_, infer_desc);
300 this->setNodeDesc(post_, post_desc);
301 this->defaultParam();
302 base::Status status = infer_->setInferenceType(inference_type);
311 base::Status status = infer_->setInferenceType(inference_type);
321 std::vector<std::string> &model_value) {
325 param->model_type_ = model_type;
326 param->is_path_ = is_path;
327 param->model_value_ = model_value;
357 std::vector<dag::Edge *>
forward(std::vector<dag::Edge *> inputs) {
358 inputs = (*pre_)(inputs);
359 inputs = (*infer_)(inputs);
360 std::vector<dag::Edge *> outputs = (*post_)(inputs);
virtual base::Status deserialize(rapidjson::Value &json)
virtual std::string serialize()
Implementation of ResNet classification network graph structure.
virtual base::Status defaultParam()
Set default parameters.
base::Status setInferenceType(base::InferenceType inference_type)
base::Status setInferParam(base::DeviceType device_type, base::ModelType model_type, bool is_path, std::vector< std::string > &model_value)
base::Status setTopk(int topk)
base::Status setSoftmax(bool is_softmax)
std::vector< dag::Edge * > forward(std::vector< dag::Edge * > inputs)
base::Status make(const dag::NodeDesc &pre_desc, const dag::NodeDesc &infer_desc, base::InferenceType inference_type, const dag::NodeDesc &post_desc)
base::Status setSrcPixelType(base::PixelType pixel_type)
Set preprocessing parameters.
ClassificationGraph(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
ClassificationGraph(const std::string &name)
virtual ~ClassificationGraph()
virtual base::Status deserialize(rapidjson::Value &json)
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
ClassificationPostProcess(const std::string &name)
virtual ~ClassificationPostProcess()
virtual base::Status run()
Run node (pure virtual function)
ClassificationPostProcess(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
Implementation of ResNet classification network graph structure.
base::Status setSoftmax(bool is_softmax)
base::Status setInferenceType(base::InferenceType inference_type)
virtual base::Status defaultParam()
Set default parameters.
std::vector< dag::Edge * > forward(std::vector< dag::Edge * > inputs)
ResnetGraph(const std::string &name)
base::Status setSrcPixelType(base::PixelType pixel_type)
Set preprocessing parameters.
base::Status make(const dag::NodeDesc &pre_desc, const dag::NodeDesc &infer_desc, base::InferenceType inference_type, const dag::NodeDesc &post_desc)
ResnetGraph(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
base::Status setTopk(int topk)
base::Status setInferParam(base::DeviceType device_type, base::ModelType model_type, bool is_path, std::vector< std::string > &model_value)
Directed Acyclic Graph Node.
InferenceParam is the base class of all inference param.
base::DeviceType device_type_
base::InterpType interp_type_
base::PixelType dst_pixel_type_
base::PixelType src_pixel_type_
base::PixelType dst_pixel_type_
base::InterpType interp_type_
base::PixelType src_pixel_type_
#define NNDEPLOY_LOGE(fmt,...)
#define NNDEPLOY_CC_API
api