MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / modelToNetwork

Function modelToNetwork

samples/common/sampleEngines.cpp:239–357  ·  view source on GitHub ↗

\brief Generate a network definition for a given model \param[in] model Model options for this network \param[in,out] network Network storing the parsed results \param[in,out] err Error stream \param[out] vcPluginLibrariesUsed If not nullptr, will be populated with paths to VC plugin libraries required by the parsed network. \return Parser The parser used to initialize the network and that holds

Source from the content-addressed store, hash-verified

237//! \see Parser::operator bool()
238//!
239Parser modelToNetwork(ModelOptions const& model, BuildOptions const& build, nvinfer1::INetworkDefinition& network,
240 std::ostream& err, std::vector<std::string>* vcPluginLibrariesUsed)
241{
242 sample::gLogInfo << "Start parsing network model." << std::endl;
243 auto const tBegin = std::chrono::high_resolution_clock::now();
244
245 Parser parser;
246 std::string const& modelName = model.baseModel.model;
247 switch (model.baseModel.format)
248 {
249 case ModelFormat::kCAFFE:
250 {
251 using namespace nvcaffeparser1;
252 parser.caffeParser.reset(sampleCreateCaffeParser());
253 CaffeBufferShutter bufferShutter;
254 auto const* const blobNameToTensor = parser.caffeParser->parse(
255 model.prototxt.c_str(), modelName.empty() ? nullptr : modelName.c_str(), network, DataType::kFLOAT);
256 if (!blobNameToTensor)
257 {
258 err << "Failed to parse caffe model or prototxt, tensors blob not found" << std::endl;
259 parser.caffeParser.reset();
260 break;
261 }
262
263 for (auto const& s : model.outputs)
264 {
265 if (blobNameToTensor->find(s.c_str()) == nullptr)
266 {
267 err << "Could not find output blob " << s << std::endl;
268 parser.caffeParser.reset();
269 break;
270 }
271 network.markOutput(*blobNameToTensor->find(s.c_str()));
272 }
273 break;
274 }
275 case ModelFormat::kUFF:
276 {
277 using namespace nvuffparser;
278 parser.uffParser.reset(sampleCreateUffParser());
279 UffBufferShutter bufferShutter;
280 for (auto const& s : model.uffInputs.inputs)
281 {
282 if (!parser.uffParser->registerInput(
283 s.first.c_str(), s.second, model.uffInputs.NHWC ? UffInputOrder::kNHWC : UffInputOrder::kNCHW))
284 {
285 err << "Failed to register input " << s.first << std::endl;
286 parser.uffParser.reset();
287 break;
288 }
289 }
290
291 for (auto const& s : model.outputs)
292 {
293 if (!parser.uffParser->registerOutput(s.c_str()))
294 {
295 err << "Failed to register output " << s << std::endl;
296 parser.uffParser.reset();

Callers 1

modelToBuildEnvFunction · 0.85

Calls 12

c_strMethod · 0.80
markOutputMethod · 0.80
setFlagsMethod · 0.80
sampleCreateCaffeParserFunction · 0.70
sampleCreateUffParserFunction · 0.70
createONNXParserFunction · 0.70
resetMethod · 0.45
parseMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
getReportableSeverityMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected