Skip to content

Commit 91adfce

Browse files
committed
remove raw pointer
1 parent 037e03c commit 91adfce

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

yolox_ros_cpp/yolox_cpp/include/yolox_cpp/yolox_tensorrt.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace yolox_cpp{
4040
std::vector<Object> inference(const cv::Mat& frame) override;
4141

4242
private:
43-
void doInference(float* input, float* output);
43+
void doInference(const float* input, float* output);
4444

4545
int DEVICE_ = 0;
4646
Logger gLogger_;
@@ -51,8 +51,10 @@ namespace yolox_cpp{
5151
const int inputIndex_ = 0;
5252
const int outputIndex_ = 1;
5353
void *inference_buffers_[2];
54+
std::vector<float> input_blob_;
55+
std::vector<float> output_blob_;
5456

5557
};
5658
} // namespace yolox_cpp
5759

58-
#endif
60+
#endif

yolox_ros_cpp/yolox_cpp/src/yolox_tensorrt.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)