@@ -54,6 +54,10 @@ namespace yolox_cpp
5454 this ->output_size_ *= output_dims.d [j];
5555 }
5656
57+ // allocate buffer
58+ this ->input_blob_ .resize (this ->input_h_ * this ->input_w_ * 3 );
59+ this ->output_blob_ .resize (this ->output_size_ );
60+
5761 // Pointers to input and output device buffers to pass to engine.
5862 // Engine requires exactly IEngine::getNbBindings() number of buffers.
5963 assert (this ->engine_ ->getNbIOTensors () == 2 );
@@ -93,24 +97,23 @@ namespace yolox_cpp
9397 {
9498 // preprocess
9599 auto pr_img = static_resize (frame);
96- float *input_blob = new float [pr_img.total () * 3 ];
97- blobFromImage (pr_img, input_blob);
100+ blobFromImage (pr_img, input_blob_.data ());
98101
99102 // inference
100- float *output_blob = new float [this ->output_size_ ];
101- this ->doInference (input_blob, output_blob);
103+ this ->doInference (input_blob_.data (), output_blob_.data ());
102104
103- float scale = std::min (this ->input_w_ / (frame.cols * 1.0 ), this ->input_h_ / (frame.rows * 1.0 ));
105+ const float scale = std::min (
106+ static_cast <float >(this ->input_w_ ) / static_cast <float >(frame.cols ),
107+ static_cast <float >(this ->input_h_ ) / static_cast <float >(frame.rows )
108+ );
104109
105110 std::vector<Object> objects;
106- decode_outputs (output_blob , this ->grid_strides_ , objects, this ->bbox_conf_thresh_ , scale, frame.cols , frame.rows );
111+ decode_outputs (output_blob_. data () , this ->grid_strides_ , objects, this ->bbox_conf_thresh_ , scale, frame.cols , frame.rows );
107112
108- delete input_blob;
109- delete output_blob;
110113 return objects;
111114 }
112115
113- void YoloXTensorRT::doInference (float *input, float *output)
116+ void YoloXTensorRT::doInference (const float *input, float *output)
114117 {
115118 // Create stream
116119 cudaStream_t stream;
0 commit comments