| 224 | |
| 225 | template <typename T> |
| 226 | bool Engine<T>::buildLoadNetwork(std::string onnxModelPath, const std::array<float, 3> &subVals, const std::array<float, 3> &divVals, |
| 227 | bool normalize) { |
| 228 | // Only regenerate the engine file if it has not already been generated for |
| 229 | // the specified options, otherwise load cached version from disk |
| 230 | const auto engineName = serializeEngineOptions(m_options, onnxModelPath); |
| 231 | std::cout << "Searching for engine file with name: " << engineName << std::endl; |
| 232 | |
| 233 | if (Util::doesFileExist(engineName)) { |
| 234 | std::cout << "Engine found, not regenerating..." << std::endl; |
| 235 | } else { |
| 236 | if (!Util::doesFileExist(onnxModelPath)) { |
| 237 | throw std::runtime_error("Could not find onnx model at path: " + onnxModelPath); |
| 238 | } |
| 239 | |
| 240 | // Was not able to find the engine file, generate... |
| 241 | std::cout << "Engine not found, generating. This could take a while..." << std::endl; |
| 242 | |
| 243 | // Build the onnx model into a TensorRT engine |
| 244 | auto ret = build(onnxModelPath, subVals, divVals, normalize); |
| 245 | if (!ret) { |
| 246 | return false; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // Load the TensorRT engine file into memory |
| 251 | return loadNetwork(engineName, subVals, divVals, normalize); |
| 252 | } |
| 253 | |
| 254 | template <typename T> |
| 255 | bool Engine<T>::loadNetwork(std::string trtModelPath, const std::array<float, 3> &subVals, const std::array<float, 3> &divVals, |