33namespace yolox_cpp
44{
55
6- YoloXTflite::YoloXTflite (file_name_t path_to_model, int num_threads,
7- float nms_th, float conf_th, std::string model_version,
6+ YoloXTflite::YoloXTflite (const file_name_t & path_to_model, int num_threads,
7+ float nms_th, float conf_th, const std::string & model_version,
88 int num_classes, bool p6, bool is_nchw)
99 : AbcYoloX(nms_th, conf_th, model_version, num_classes, p6), is_nchw_(is_nchw)
1010 {
@@ -25,8 +25,8 @@ namespace yolox_cpp
2525 status = this ->interpreter_ ->SetNumThreads (num_threads);
2626 if (status != TfLiteStatus::kTfLiteOk )
2727 {
28- std::cerr << " Failed to SetNumThreads." << std::endl ;
29- exit ( 1 );
28+ std::string msg = " Failed to SetNumThreads." ;
29+ throw std::runtime_error (msg. c_str () );
3030 }
3131
3232 // XNNPACK Delegate
@@ -36,8 +36,8 @@ namespace yolox_cpp
3636 status = this ->interpreter_ ->ModifyGraphWithDelegate (this ->delegate_ );
3737 if (status != TfLiteStatus::kTfLiteOk )
3838 {
39- std::cerr << " Failed to ModifyGraphWithDelegate." << std::endl ;
40- exit ( 1 );
39+ std::string msg = " Failed to ModifyGraphWithDelegate." ;
40+ throw std::runtime_error (msg. c_str () );
4141 }
4242
4343 // // GPU Delegate
@@ -67,8 +67,8 @@ namespace yolox_cpp
6767
6868 if (this ->interpreter_ ->AllocateTensors () != TfLiteStatus::kTfLiteOk )
6969 {
70- std::cerr << " Failed to allocate tensors." << std::endl ;
71- exit ( 1 );
70+ std::string msg = " Failed to allocate tensors." ;
71+ throw std::runtime_error (msg. c_str () );
7272 }
7373
7474 {
@@ -97,7 +97,7 @@ namespace yolox_cpp
9797 {
9898 this ->input_size_ = sizeof (float );
9999 }
100- for (size_t i = 0 ; i < tensor->dims ->size ; i++)
100+ for (int i = 0 ; i < tensor->dims ->size ; i++)
101101 {
102102 this ->input_size_ *= tensor->dims ->data [i];
103103 std::cout << " - " << tensor->dims ->data [i] << std::endl;
@@ -120,7 +120,7 @@ namespace yolox_cpp
120120 {
121121 this ->output_size_ = sizeof (float );
122122 }
123- for (size_t i = 0 ; i < tensor->dims ->size ; i++)
123+ for (int i = 0 ; i < tensor->dims ->size ; i++)
124124 {
125125 this ->output_size_ *= tensor->dims ->data [i];
126126 std::cout << " - " << tensor->dims ->data [i] << std::endl;
@@ -166,10 +166,15 @@ namespace yolox_cpp
166166 }
167167
168168 // postprocess
169+ const float scale = std::min (
170+ static_cast <float >(this ->input_w_ ) / static_cast <float >(frame.cols ),
171+ static_cast <float >(this ->input_h_ ) / static_cast <float >(frame.rows )
172+ );
169173 std::vector<Object> objects;
170- float scale = std::min (this ->input_w_ / (frame.cols * 1.0 ), this ->input_h_ / (frame.rows * 1.0 ));
171- float *output_blob = this ->interpreter_ ->typed_output_tensor <float >(0 );
172- decode_outputs (output_blob, this ->grid_strides_ , objects, this ->bbox_conf_thresh_ , scale, frame.cols , frame.rows );
174+ decode_outputs (
175+ this ->interpreter_ ->typed_output_tensor <float >(0 ),
176+ this ->grid_strides_ , objects,
177+ this ->bbox_conf_thresh_ , scale, frame.cols , frame.rows );
173178
174179 return objects;
175180 }
0 commit comments