Skip to content

Commit 4441783

Browse files
author
M. Fatih Cırıt
committed
fix(tensorrt): update tensorrt code of traffic_light_ssd_fine_detector
Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
1 parent 9376697 commit 4441783

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

perception/traffic_light_ssd_fine_detector/lib/include/trt_ssd.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Net
7272
void save(const std::string & path);
7373

7474
// Infer using pre-allocated GPU buffers {data, scores, boxes}
75-
void infer(std::vector<void *> & buffers, const int batch_size);
75+
void infer([[maybe_unused]] std::vector<void *> & buffers, const int batch_size);
7676

7777
// Get (c, h, w) size of the fixed input
7878
std::vector<int> getInputSize();

perception/traffic_light_ssd_fine_detector/lib/src/trt_ssd.cpp

+40-5
Original file line numberDiff line numberDiff line change
@@ -164,35 +164,70 @@ void Net::save(const std::string & path)
164164
file.write(reinterpret_cast<const char *>(plan_->data()), plan_->size());
165165
}
166166

167-
void Net::infer(std::vector<void *> & buffers, const int batch_size)
167+
void Net::infer([[maybe_unused]] std::vector<void *> & buffers, const int batch_size)
168168
{
169169
if (!context_) {
170170
throw std::runtime_error("Fail to create context");
171171
}
172-
auto input_dims = engine_->getBindingDimensions(0);
172+
173+
#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
174+
const auto input_dims = engine_->getTensorShape(engine_->getIOTensorName(0));
175+
context_->setInputShape(
176+
engine_->getIOTensorName(0),
177+
nvinfer1::Dims4(batch_size, input_dims.d[1], input_dims.d[2], input_dims.d[3]));
178+
context_->enqueueV3(stream_);
179+
#else
180+
// Deprecated since 8.5
181+
const auto input_dims = engine_->getBindingDimensions(0);
173182
context_->setBindingDimensions(
174183
0, nvinfer1::Dims4(batch_size, input_dims.d[1], input_dims.d[2], input_dims.d[3]));
175184
context_->enqueueV2(buffers.data(), stream_, nullptr);
185+
#endif
176186
cudaStreamSynchronize(stream_);
177187
}
178188

179189
std::vector<int> Net::getInputSize()
180190
{
181-
auto dims = engine_->getBindingDimensions(0);
191+
#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
192+
const auto dims = engine_->getTensorShape(engine_->getIOTensorName(0));
193+
#else
194+
// Deprecated since 8.5
195+
const auto dims = engine_->getBindingDimensions(0);
196+
#endif
182197
return {dims.d[1], dims.d[2], dims.d[3]};
183198
}
184199

185200
std::vector<int> Net::getOutputScoreSize()
186201
{
187-
auto dims = engine_->getBindingDimensions(1);
202+
#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
203+
const auto dims = engine_->getTensorShape(engine_->getIOTensorName(1));
204+
#else
205+
// Deprecated since 8.5
206+
const auto dims = engine_->getBindingDimensions(1);
207+
#endif
188208
return {dims.d[1], dims.d[2]};
189209
}
190210

191211
int Net::getMaxBatchSize()
192212
{
213+
#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
214+
return engine_
215+
->getProfileShape(engine_->getIOTensorName(0), 0, nvinfer1::OptProfileSelector::kMAX)
216+
.d[0];
217+
#else
218+
// Deprecated since 8.5
193219
return engine_->getProfileDimensions(0, 0, nvinfer1::OptProfileSelector::kMAX).d[0];
220+
#endif
194221
}
195222

196-
int Net::getMaxDetections() { return engine_->getBindingDimensions(1).d[1]; }
223+
int Net::getMaxDetections()
224+
{
225+
#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
226+
return engine_->getTensorShape(engine_->getIOTensorName(1)).d[1];
227+
#else
228+
// Deprecated since 8.5
229+
return engine_->getBindingDimensions(1).d[1];
230+
#endif
231+
}
197232

198233
} // namespace ssd

0 commit comments

Comments
 (0)