33 {
34 std::string config_file =
37 AINFO <<
"load proto param failed, root dir: " << config_file;
38 return false;
39 }
40
41 AINFO <<
"denseline param: " << denseline_param_.DebugString();
42
43 const auto model_param = denseline_param_.
model_param();
44 std::string model_path =
GetModelPath(model_param.model_name());
45
46 std::string proto_file =
GetModelFile(model_path, model_param.proto_file());
47 std::string weight_file =
GetModelFile(model_path, model_param.weight_file());
48
49 base_camera_model_ = options.base_camera_model;
50 if (base_camera_model_ == nullptr) {
51 AERROR <<
"options.intrinsic is nullptr!";
52 input_height_ = 1080;
53 input_width_ = 1920;
54 } else {
55 input_height_ = static_cast<uint16_t>(base_camera_model_->get_height());
56 input_width_ = static_cast<uint16_t>(base_camera_model_->get_width());
57 }
58 ACHECK(input_width_ > 0) <<
"input width should be more than 0";
59 ACHECK(input_height_ > 0) <<
"input height should be more than 0";
60
61 AINFO <<
"input_height: " << input_height_;
62 AINFO <<
"input_width: " << input_width_;
63
64 image_scale_ = model_param.resize_scale();
65 input_offset_y_ = static_cast<uint16_t>(model_param.input_offset_y());
66 input_offset_x_ = static_cast<uint16_t>(model_param.input_offset_x());
67 crop_height_ = static_cast<uint16_t>(model_param.crop_height());
68 crop_width_ = static_cast<uint16_t>(model_param.crop_width());
69
70 CHECK_LE(crop_height_, input_height_)
71 << "crop height larger than input height";
72 CHECK_LE(crop_width_, input_width_) << "crop width larger than input width";
73
74 if (model_param.is_bgr()) {
76 image_mean_[0] = model_param.mean_b();
77 image_mean_[1] = model_param.mean_g();
78 image_mean_[2] = model_param.mean_r();
79 } else {
81 image_mean_[0] = model_param.mean_r();
82 image_mean_[1] = model_param.mean_g();
83 image_mean_[2] = model_param.mean_b();
84 }
85 data_provider_image_option_.
do_crop =
true;
86 data_provider_image_option_.
crop_roi.
x = input_offset_x_;
87 data_provider_image_option_.
crop_roi.
y = input_offset_y_;
90
91 cudaDeviceProp prop;
92 cudaGetDeviceProperties(&prop, options.gpu_id);
93 AINFO <<
"GPU: " << prop.name;
94
95 const auto net_param = denseline_param_.
net_param();
96 net_inputs_.push_back(net_param.in_blob());
97 net_outputs_.push_back(net_param.out_blob());
98 std::copy(net_param.internal_blob_int8().begin(),
99 net_param.internal_blob_int8().end(),
100 std::back_inserter(net_outputs_));
101
102 for (auto name : net_inputs_) {
103 AINFO <<
"net input blobs: " << name;
104 }
105 for (auto name : net_outputs_) {
106 AINFO <<
"net output blobs: " << name;
107 }
108
109 const auto &model_type = model_param.model_type();
110 AINFO <<
"model_type: " << model_type;
112 weight_file, net_outputs_,
113 net_inputs_, model_path));
114 ACHECK(rt_net_ !=
nullptr);
115 rt_net_->set_gpu_id(options.gpu_id);
116
117 resize_height_ = static_cast<uint16_t>(crop_height_ * image_scale_);
118 resize_width_ = static_cast<uint16_t>(crop_width_ * image_scale_);
119 ACHECK(resize_width_ > 0) <<
"resize width should be more than 0";
120 ACHECK(resize_height_ > 0) <<
"resize height should be more than 0";
121
122 std::vector<int> shape = {1, 3, resize_height_, resize_width_};
123
124 std::map<std::string, std::vector<int>> input_reshape{
125 {net_inputs_[0], shape}};
126 AINFO <<
"input_reshape: " << input_reshape[net_inputs_[0]][0] <<
", "
127 << input_reshape[net_inputs_[0]][1] << ", "
128 << input_reshape[net_inputs_[0]][2] << ", "
129 << input_reshape[net_inputs_[0]][3];
130 if (!rt_net_->Init(input_reshape)) {
131 AINFO <<
"net init fail.";
132 return false;
133 }
134
135 for (auto &input_blob_name : net_inputs_) {
136 auto input_blob = rt_net_->get_blob(input_blob_name);
137 AINFO << input_blob_name <<
": " << input_blob->channels() <<
" "
138 << input_blob->height() << " " << input_blob->width();
139 }
140
141 for (auto &output_blob_name : net_outputs_) {
142 auto output_blob = rt_net_->get_blob(output_blob_name);
143 AINFO << output_blob_name <<
" : " << output_blob->channels() <<
" "
144 << output_blob->height() << " " << output_blob->width();
145 }
146
147 return true;
148}
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Inference * CreateInferenceByName(const std::string &frame_work, const std::string &proto_file, const std::string &weight_file, const std::vector< std::string > &outputs, const std::vector< std::string > &inputs, const std::string &model_root)
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
optional NetworkParam net_param
optional ModelParam model_param