@@ -90,12 +90,12 @@ namespace test {
9090 MatMap input_mat_map = CreateBlobMatMap (input_blob_map, FLAGS_it);
9191 InitInputMatMap (input_mat_map);
9292 auto input_converters_map = CreateBlobConverterMap (input_blob_map);
93- auto input_params_map = CreateConvertParamMap (input_mat_map);
93+ auto input_params_map = CreateConvertParamMap (input_mat_map, true );
9494
9595 // mat format NCHW_FLOAT
9696 MatMap output_mat_map = CreateBlobMatMap (output_blob_map, 0 );
9797 auto output_converters_map = CreateBlobConverterMap (output_blob_map);
98- auto output_params_map = CreateConvertParamMap (output_mat_map);
98+ auto output_params_map = CreateConvertParamMap (output_mat_map, false );
9999
100100 for (int i = 0 ; i < FLAGS_wc; ++i) {
101101 for (auto element : input_converters_map) {
@@ -132,7 +132,11 @@ namespace test {
132132 return ret;
133133 }
134134 }
135+ #if DUMP_INPUT_BLOB || DUMP_OUTPUT_BLOB
136+ ret = instance->Forward ();
137+ #else
135138 ret = instance->ForwardAsync (nullptr );
139+ #endif
136140 if (!CheckResult (" Forward" , ret)) {
137141 return ret;
138142 }
@@ -204,6 +208,8 @@ namespace test {
204208 printf (" -fc \" <format for compare>\t %s \n " , output_format_cmp_message);
205209 printf (" -nt \" <network type>\t %s \n " , output_format_cmp_message);
206210 printf (" -et \" <enable tune>\t %s \n " , enable_tune_message);
211+ printf (" -sc \" <input scale>\t %s \n " , scale_message);
212+ printf (" -bi \" <input bias>\t %s \n " , bias_message);
207213 }
208214
209215 void SetCpuAffinity () {
@@ -386,7 +392,9 @@ namespace test {
386392 if (mat_type == NCHW_FLOAT) {
387393 input_stream >> reinterpret_cast <float *>(mat_data)[i];
388394 } else {
389- input_stream >> reinterpret_cast <uint8_t *>(mat_data)[i];
395+ int val;
396+ input_stream >> val;
397+ reinterpret_cast <uint8_t *>(mat_data)[i] = (uint8_t )val;
390398 }
391399 }
392400 }
@@ -402,21 +410,60 @@ namespace test {
402410 return converter_map;
403411 }
404412
405- std::map<std::string, MatConvertParam> CreateConvertParamMap (MatMap& mat_map) {
413+ static void SetScaleOrBias (std::vector<float > ¶m, const std::string &message) {
414+ std::string delimiter = " ," ;
415+ std::vector<float > fval;
416+ std::ptrdiff_t p1 = 0 , p2;
417+ while (true ) {
418+ p2 = message.find (delimiter, p1);
419+ if (p2 != std::string::npos) {
420+ fval.push_back (atof (message.substr (p1, p2 - p1).c_str ()));
421+ p1 = p2 + 1 ;
422+ } else {
423+ fval.push_back (atof (message.substr (p1, message.length () - p1).c_str ()));
424+ break ;
425+ }
426+ }
427+ if (fval.size () > param.size ()) {
428+ param = fval;
429+ } else {
430+ for (int i = 0 ; i < fval.size (); ++i) {
431+ param[i] = fval[i];
432+ }
433+ }
434+ }
435+
436+ std::map<std::string, MatConvertParam> CreateConvertParamMap (MatMap& mat_map, bool is_input) {
406437 std::map<std::string, MatConvertParam> param_map;
407438 for (auto iter : mat_map) {
408439 MatConvertParam param;
409440 auto name = iter.first ;
410441 auto mat = iter.second ;
411442 auto mat_type = mat->GetMatType ();
412443 auto dims = mat->GetDims ();
413- if (mat_type != NCHW_FLOAT) {
414- std::fill (param.scale .begin (), param.scale .end (), 1 .0f / 255 .0f );
415- std::fill (param.bias .begin (), param.bias .end (), 0 );
416- } else if (dims[1 ] > 4 ) {
417- param.scale = std::vector<float >(dims[1 ], 1 );
418- param.bias = std::vector<float >(dims[1 ], 0 );
444+
445+ // scale
446+ if (is_input && !FLAGS_sc.empty ()) {
447+ SetScaleOrBias (param.scale , FLAGS_sc);
448+ } else {
449+ if (mat_type != NCHW_FLOAT) {
450+ std::fill (param.scale .begin (), param.scale .end (), 1 .0f / 255 .0f );
451+ } else if (dims[1 ] > 4 ) {
452+ param.scale = std::vector<float >(dims[1 ], 1 );
453+ }
454+ }
455+
456+ // bias
457+ if (is_input && !FLAGS_bi.empty ()) {
458+ SetScaleOrBias (param.bias , FLAGS_bi);
459+ } else {
460+ if (mat_type != NCHW_FLOAT) {
461+ std::fill (param.bias .begin (), param.bias .end (), 0 );
462+ } else if (dims[1 ] > 4 ) {
463+ param.bias = std::vector<float >(dims[1 ], 0 );
464+ }
419465 }
466+
420467 param_map[name] = param;
421468 }
422469 return param_map;
0 commit comments