nndeploy C++ API  0.2.0
nndeploy C++ API
convert_to.h
Go to the documentation of this file.
1 #ifndef _NNDEPLOY_PREPROCESS_CONVERT_TO_H_
2 #define _NNDEPLOY_PREPROCESS_CONVERT_TO_H_
3 
4 #include "nndeploy/base/any.h"
5 #include "nndeploy/base/common.h"
7 #include "nndeploy/base/log.h"
8 #include "nndeploy/base/macro.h"
9 #include "nndeploy/base/object.h"
11 #include "nndeploy/base/status.h"
12 #include "nndeploy/base/string.h"
13 #include "nndeploy/dag/edge.h"
14 #include "nndeploy/dag/node.h"
15 #include "nndeploy/device/buffer.h"
16 #include "nndeploy/device/device.h"
17 #include "nndeploy/device/tensor.h"
18 
19 namespace nndeploy {
20 namespace preprocess {
21 
23  public:
25 
28  rapidjson::Value &json,
29  rapidjson::Document::AllocatorType &allocator) override {
30  json.AddMember(
31  "dst_data_type_",
32  rapidjson::Value(base::dataTypeToString(dst_data_type_).c_str(),
33  base::dataTypeToString(dst_data_type_).length(),
34  allocator),
35  allocator);
36  return base::kStatusCodeOk;
37  }
38 
40  virtual base::Status deserialize(rapidjson::Value &json) override {
41  if (json.HasMember("dst_data_type_") && json["dst_data_type_"].IsString()) {
42  std::string dst_data_type_str = json["dst_data_type_"].GetString();
43  dst_data_type_ = base::stringToDataType(dst_data_type_str);
44  }
45  return base::kStatusCodeOk;
46  }
47 };
48 
50  public:
51  ConvertTo(const std::string &name) : dag::Node(name) {
52  key_ = "nndeploy::preprocess::ConvertTo";
53  desc_ =
54  "Convert the data type of the input tensor to the specified data type";
55  param_ = std::make_shared<ConvertToParam>();
56  this->setInputTypeInfo<device::Tensor>();
57  this->setOutputTypeInfo<device::Tensor>();
58  }
59  ConvertTo(const std::string &name, std::vector<dag::Edge *> inputs,
60  std::vector<dag::Edge *> outputs)
61  : dag::Node(name, inputs, outputs) {
62  key_ = "nndeploy::preprocess::ConvertTo";
63  desc_ =
64  "Convert the data type of the input tensor to the specified data type";
65  param_ = std::make_shared<ConvertToParam>();
66  this->setInputTypeInfo<device::Tensor>();
67  this->setOutputTypeInfo<device::Tensor>();
68  }
69  virtual ~ConvertTo() {}
70 
71  virtual base::Status run();
72 };
73 
74 } // namespace preprocess
75 } // namespace nndeploy
76 
77 #endif /* _NNDEPLOY_PREPROCESS_CONVERT_TO_H_ */
virtual base::Status deserialize(rapidjson::Value &json)
virtual std::string serialize()
Node base class.
Definition: node.h:171
virtual base::Status deserialize(rapidjson::Value &json) override
Definition: convert_to.h:40
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) override
Definition: convert_to.h:27
ConvertTo(const std::string &name)
Definition: convert_to.h:51
ConvertTo(const std::string &name, std::vector< dag::Edge * > inputs, std::vector< dag::Edge * > outputs)
Definition: convert_to.h:59
virtual base::Status run()
Run node (pure virtual function)
#define NNDEPLOY_CC_API
api
Definition: macro.h:29
@ kStatusCodeOk
Definition: status.h:13
DataType stringToDataType(const std::string &str)
std::string dataTypeToString(DataType data_type)
DataType dataTypeOf< float >()