MCPcopy Create free account
hub / github.com/OAID/Tengine / run_PNet

Method run_PNet

examples/mtcnn/mtcnn.cpp:92–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92int mtcnn::run_PNet(image img, scale_window& win, std::vector<face_box>& box_list)
93{
94 int scale_h = win.h;
95
96 int scale_w = win.w;
97 float scale = win.scale;
98 static bool first_run = true;
99 image resImg = resize_image(img, scale_w, scale_h);
100
101 /* input */
102 tensor_t input_tensor = get_graph_tensor(PNet_graph, "data");
103 int dims[] = {1, 3, scale_h, scale_w};
104 set_tensor_shape(input_tensor, dims, 4);
105 int in_mem = sizeof(float) * scale_h * scale_w * 3;
106 // std::cout<<"mem "<<in_mem<<"\n";
107 float* input_data = ( float* )malloc(in_mem);
108
109 memcpy(input_data, resImg.data, sizeof(float) * 3 * scale_h * scale_w);
110
111 set_tensor_buffer(input_tensor, input_data, in_mem);
112
113 if(first_run)
114 {
115 if(prerun_graph(PNet_graph) != 0)
116 {
117 std::cout << "Prerun PNet graph failed, errno: " << get_tengine_errno() << "\n";
118 return 1;
119 }
120 first_run = false;
121 }
122
123 if(run_graph(PNet_graph, 1) != 0)
124 {
125 std::cout << "Run PNet graph failed, errno: " << get_tengine_errno() << "\n";
126 return 1;
127 }
128 free(input_data);
129 /* output */
130 tensor_t tensor = get_graph_tensor(PNet_graph, "conv4-2");
131 get_tensor_shape(tensor, dims, 4);
132 float* reg_data = ( float* )get_tensor_buffer(tensor);
133 int feature_h = dims[2];
134 int feature_w = dims[3];
135
136 tensor = get_graph_tensor(PNet_graph, "prob1");
137 float* prob_data = ( float* )get_tensor_buffer(tensor);
138 std::vector<face_box> candidate_boxes;
139 generate_bounding_box(prob_data, reg_data, scale, conf_p_threshold_, feature_h, feature_w, candidate_boxes, true);
140
141 release_graph_tensor(input_tensor);
142 release_graph_tensor(tensor);
143
144 nms_boxes(candidate_boxes, nms_p_threshold_, NMS_UNION, box_list);
145 return 0;
146}
147
148int mtcnn::run_RNet(image img, std::vector<face_box>& pnet_boxes, std::vector<face_box>& output_boxes)
149{

Callers

nothing calls this directly

Calls 12

resize_imageFunction · 0.85
get_graph_tensorFunction · 0.85
set_tensor_shapeFunction · 0.85
set_tensor_bufferFunction · 0.85
prerun_graphFunction · 0.85
get_tengine_errnoFunction · 0.85
run_graphFunction · 0.85
get_tensor_shapeFunction · 0.85
get_tensor_bufferFunction · 0.85
release_graph_tensorFunction · 0.85
generate_bounding_boxFunction · 0.70
nms_boxesFunction · 0.70

Tested by

no test coverage detected