@@ -55,6 +55,8 @@ Net::Net(const std::string & path, bool verbose)
55
55
runtime_ = unique_ptr<nvinfer1::IRuntime>(nvinfer1::createInferRuntime (logger));
56
56
load (path);
57
57
prepare ();
58
+ name_tensor_in_ = engine_->getIOTensorName (0 );
59
+ name_tensor_out_ = engine_->getIOTensorName (engine_->getNbIOTensors () - 1 );
58
60
}
59
61
60
62
Net::~Net ()
@@ -155,6 +157,8 @@ Net::Net(
155
157
std::cout << " Fail to create context" << std::endl;
156
158
return ;
157
159
}
160
+ name_tensor_in_ = engine_->getIOTensorName (0 );
161
+ name_tensor_out_ = engine_->getIOTensorName (engine_->getNbIOTensors () - 1 );
158
162
}
159
163
160
164
void Net::save (const std::string & path)
@@ -164,35 +168,37 @@ void Net::save(const std::string & path)
164
168
file.write (reinterpret_cast <const char *>(plan_->data ()), plan_->size ());
165
169
}
166
170
167
- void Net::infer (std::vector< void *> & buffers, const int batch_size)
171
+ void Net::infer (const int batch_size)
168
172
{
169
173
if (!context_) {
170
174
throw std::runtime_error (" Fail to create context" );
171
175
}
172
- auto input_dims = engine_->getBindingDimensions (0 );
173
- context_->setBindingDimensions (
174
- 0 , nvinfer1::Dims4 (batch_size, input_dims.d [1 ], input_dims.d [2 ], input_dims.d [3 ]));
175
- context_->enqueueV2 (buffers.data (), stream_, nullptr );
176
+ const auto input_dims = engine_->getTensorShape (name_tensor_in_.c_str ());
177
+ context_->setInputShape (
178
+ name_tensor_in_.c_str (),
179
+ nvinfer1::Dims4 (batch_size, input_dims.d [1 ], input_dims.d [2 ], input_dims.d [3 ]));
180
+ context_->enqueueV3 (stream_);
176
181
cudaStreamSynchronize (stream_);
177
182
}
178
183
179
184
std::vector<int > Net::getInputSize ()
180
185
{
181
- auto dims = engine_->getBindingDimensions ( 0 );
186
+ const auto dims = engine_->getTensorShape (name_tensor_in_. c_str () );
182
187
return {dims.d [1 ], dims.d [2 ], dims.d [3 ]};
183
188
}
184
189
185
190
std::vector<int > Net::getOutputScoreSize ()
186
191
{
187
- auto dims = engine_->getBindingDimensions ( 1 );
192
+ const auto dims = engine_->getTensorShape (name_tensor_out_. c_str () );
188
193
return {dims.d [1 ], dims.d [2 ]};
189
194
}
190
195
191
196
int Net::getMaxBatchSize ()
192
197
{
193
- return engine_->getProfileDimensions (0 , 0 , nvinfer1::OptProfileSelector::kMAX ).d [0 ];
198
+ return engine_->getProfileShape (name_tensor_in_.c_str (), 0 , nvinfer1::OptProfileSelector::kMAX )
199
+ .d [0 ];
194
200
}
195
201
196
- int Net::getMaxDetections () { return engine_->getBindingDimensions ( 1 ).d [1 ]; }
202
+ int Net::getMaxDetections () { return engine_->getTensorShape (name_tensor_in_. c_str () ).d [1 ]; }
197
203
198
204
} // namespace ssd
0 commit comments