@@ -83,7 +83,6 @@ namespace PaddleSolution {
83
83
84
84
int blob_out_len = length;
85
85
int seg_out_len = eval_height * eval_width * eval_num_class;
86
-
87
86
if (blob_out_len != seg_out_len) {
88
87
LOG (ERROR) << " [FATAL] unequal: input vs output [" <<
89
88
seg_out_len << " |" << blob_out_len << " ]" << std::endl;
@@ -99,23 +98,20 @@ namespace PaddleSolution {
99
98
std::string nname (fname);
100
99
auto pos = fname.rfind (" ." );
101
100
nname[pos] = ' _' ;
102
- std::string mask_save_name = nname + " .png" ;
101
+ std::string mask_save_name = nname + " _mask .png" ;
103
102
cv::imwrite (mask_save_name, mask_png);
104
103
cv::Mat scoremap_png = cv::Mat (eval_height, eval_width, CV_8UC1);
105
104
scoremap_png.data = _scoremap.data ();
106
- std::string scoremap_save_name = nname
107
- + std::string (" _scoremap.png" );
105
+ std::string scoremap_save_name = nname + std::string (" _scoremap.png" );
108
106
cv::imwrite (scoremap_save_name, scoremap_png);
109
107
std::cout << " save mask of [" << fname << " ] done" << std::endl;
110
108
111
109
if (height && width) {
112
110
int recover_height = *height;
113
111
int recover_width = *width;
114
- cv::Mat recover_png = cv::Mat (recover_height,
115
- recover_width, CV_8UC1);
112
+ cv::Mat recover_png = cv::Mat (recover_height, recover_width, CV_8UC1);
116
113
cv::resize (scoremap_png, recover_png,
117
- cv::Size (recover_width, recover_height),
118
- 0 , 0 , cv::INTER_CUBIC);
114
+ cv::Size (recover_width, recover_height), 0 , 0 , cv::INTER_CUBIC);
119
115
std::string recover_name = nname + std::string (" _recover.png" );
120
116
cv::imwrite (recover_name, recover_png);
121
117
}
@@ -176,8 +172,13 @@ namespace PaddleSolution {
176
172
}
177
173
paddle::PaddleTensor im_tensor;
178
174
im_tensor.name = " image" ;
179
- im_tensor.shape = std::vector<int >{ batch_size, channels,
180
- eval_height, eval_width };
175
+ if (!_model_config._use_pr ) {
176
+ im_tensor.shape = std::vector<int >{ batch_size, channels,
177
+ eval_height, eval_width };
178
+ } else {
179
+ im_tensor.shape = std::vector<int >{ batch_size, eval_height,
180
+ eval_width, channels};
181
+ }
181
182
im_tensor.data .Reset (input_buffer.data (),
182
183
real_buffer_size * sizeof (float ));
183
184
im_tensor.dtype = paddle::PaddleDType::FLOAT32;
@@ -202,19 +203,45 @@ namespace PaddleSolution {
202
203
std::cout << _outputs[0 ].shape [j] << " ," ;
203
204
}
204
205
std::cout << " )" << std::endl;
205
- const size_t nums = _outputs.front ().data .length ()
206
- / sizeof (float );
207
- if (out_num % batch_size != 0 || out_num != nums) {
208
- LOG (ERROR) << " outputs data size mismatch with shape size." ;
206
+
207
+ size_t nums = _outputs.front ().data .length () / sizeof (float );
208
+ if (_model_config._use_pr ) {
209
+ nums = _outputs.front ().data .length () / sizeof (int64_t );
210
+ }
211
+ // size mismatch checking
212
+ bool size_mismatch = out_num % batch_size;
213
+ size_mismatch |= (!_model_config._use_pr ) && (nums != out_num);
214
+ size_mismatch |= _model_config._use_pr && (nums != eval_height * eval_width);
215
+ if (size_mismatch) {
216
+ LOG (ERROR) << " output with a unexpected size" ;
209
217
return -1 ;
210
218
}
211
219
220
+ if (_model_config._use_pr ) {
221
+ std::vector<uchar> out_data;
222
+ out_data.resize (out_num);
223
+ auto addr = reinterpret_cast <int64_t *>(_outputs[0 ].data .data ());
224
+ for (int r = 0 ; r < out_num; ++r) {
225
+ out_data[r] = (int )(addr[r]);
226
+ }
227
+ for (int r = 0 ; r < batch_size; ++r) {
228
+ cv::Mat mask_png = cv::Mat (eval_height, eval_width, CV_8UC1);
229
+ mask_png.data = out_data.data () + eval_height*eval_width*r;
230
+ auto name = imgs_batch[r];
231
+ auto pos = name.rfind (" ." );
232
+ name[pos] = ' _' ;
233
+ std::string mask_save_name = name + " _mask.png" ;
234
+ cv::imwrite (mask_save_name, mask_png);
235
+ }
236
+ continue ;
237
+ }
238
+
212
239
for (int i = 0 ; i < batch_size; ++i) {
213
240
float * output_addr = reinterpret_cast <float *>(
214
241
_outputs[0 ].data .data ())
215
- + i * (out_num / batch_size);
242
+ + i * (nums / batch_size);
216
243
output_mask (imgs_batch[i], output_addr,
217
- out_num / batch_size,
244
+ nums / batch_size,
218
245
&org_height[i],
219
246
&org_width[i]);
220
247
}
@@ -278,8 +305,14 @@ namespace PaddleSolution {
278
305
return -1 ;
279
306
}
280
307
auto im_tensor = _main_predictor->GetInputTensor (" image" );
281
- im_tensor->Reshape ({ batch_size, channels,
308
+ if (!_model_config._use_pr ) {
309
+ im_tensor->Reshape ({ batch_size, channels,
282
310
eval_height, eval_width });
311
+ } else {
312
+ im_tensor->Reshape ({ batch_size, eval_height,
313
+ eval_width, channels});
314
+ }
315
+
283
316
im_tensor->copy_from_cpu (input_buffer.data ());
284
317
285
318
auto t1 = std::chrono::high_resolution_clock::now ();
@@ -292,7 +325,6 @@ namespace PaddleSolution {
292
325
auto output_names = _main_predictor->GetOutputNames ();
293
326
auto output_t = _main_predictor->GetOutputTensor (
294
327
output_names[0 ]);
295
- std::vector<float > out_data;
296
328
std::vector<int > output_shape = output_t ->shape ();
297
329
298
330
int out_num = 1 ;
@@ -303,6 +335,30 @@ namespace PaddleSolution {
303
335
}
304
336
std::cout << " )" << std::endl;
305
337
338
+ if (_model_config._use_pr ) {
339
+ std::vector<int64_t > out_data;
340
+ out_data.resize (out_num);
341
+ output_t ->copy_to_cpu (out_data.data ());
342
+
343
+ std::vector<uchar> mask_data;
344
+ mask_data.resize (out_num);
345
+ auto addr = reinterpret_cast <int64_t *>(out_data.data ());
346
+ for (int r = 0 ; r < out_num; ++r) {
347
+ mask_data[r] = (int )(addr[r]);
348
+ }
349
+ for (int r = 0 ; r < batch_size; ++r) {
350
+ cv::Mat mask_png = cv::Mat (eval_height, eval_width, CV_8UC1);
351
+ mask_png.data = mask_data.data () + eval_height*eval_width*r;
352
+ auto name = imgs_batch[r];
353
+ auto pos = name.rfind (" ." );
354
+ name[pos] = ' _' ;
355
+ std::string mask_save_name = name + " _mask.png" ;
356
+ cv::imwrite (mask_save_name, mask_png);
357
+ }
358
+ continue ;
359
+ }
360
+
361
+ std::vector<float > out_data;
306
362
out_data.resize (out_num);
307
363
output_t ->copy_to_cpu (out_data.data ());
308
364
for (int i = 0 ; i < batch_size; ++i) {
0 commit comments