1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00

Merge pull request #28808 from abhishek-gola:engine_issue_fixed

Fixed forcing of ENGINE_AUTO to ORT when built with ONNX Runtime
This commit is contained in:
Alexander Smorkalov
2026-04-15 11:36:29 +03:00
committed by GitHub
5 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ void Net::finalizeNet()
CV_TRACE_FUNCTION();
CV_Assert(impl);
#ifdef HAVE_ONNXRUNTIME
if (impl->mainGraph && impl->modelFormat == DNN_MODEL_ONNX && !impl->modelFileName.empty())
if (impl->useOrtEngine && impl->mainGraph && impl->modelFormat == DNN_MODEL_ONNX && !impl->modelFileName.empty())
{
impl->finalizeOrt();
return;
+2 -1
View File
@@ -258,7 +258,8 @@ struct Net::Impl : public detail::NetImplBase
std::shared_ptr<Ort::Env> ort_env;
std::shared_ptr<Ort::Session> ort_session;
std::shared_ptr<OrtNamesCache> ort_names_cache;
bool ortNeedsReinit = true; // session needs (re)creation on next finalizeNet
bool useOrtEngine = false; // true only when user explicitly selected ENGINE_ORT
bool ortNeedsReinit = false; // session needs (re)creation on next finalizeNet
#endif
void allocateLayer(int lid, const LayersShapesMap& layersShapes);
+4 -4
View File
@@ -619,7 +619,7 @@ void Net::Impl::allocateLayerOutputs(
void Net::Impl::forwardMainGraph(InputArrayOfArrays inputs, OutputArrayOfArrays outputs)
{
#ifdef HAVE_ONNXRUNTIME
if (mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
if (useOrtEngine && mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
finalizeOrt();
if (this->ort_session)
{
@@ -678,7 +678,7 @@ void Net::Impl::forwardMainGraph(InputArrayOfArrays inputs, OutputArrayOfArrays
void Net::Impl::forwardWithSingleOutput(const std::string& outname, OutputArrayOfArrays outputBlobs)
{
#ifdef HAVE_ONNXRUNTIME
if (mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
if (useOrtEngine && mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
finalizeOrt();
if (this->ort_session)
{
@@ -763,7 +763,7 @@ void Net::Impl::forwardWithSingleOutput(const std::string& outname, OutputArrayO
void Net::Impl::forwardWithMultipleOutputs(OutputArrayOfArrays outblobs, const std::vector<std::string>& outnames)
{
#ifdef HAVE_ONNXRUNTIME
if (mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
if (useOrtEngine && mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
finalizeOrt();
if (this->ort_session)
{
@@ -947,7 +947,7 @@ void Net::Impl::traceArg(std::ostream& strm_, const char* prefix, size_t i, Arg
void Net::Impl::setMainGraphInput(InputArray m, const std::string& inpname)
{
#ifdef HAVE_ONNXRUNTIME
if (ortNeedsReinit && mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
if (useOrtEngine && ortNeedsReinit && mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
{
Mat inputMat = m.getMat();
if (inputMat.empty())
+2 -2
View File
@@ -273,7 +273,7 @@ void Net::Impl::setPreferableBackend(Net& net, int backendId)
return;
#ifdef HAVE_ONNXRUNTIME
if (mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
if (useOrtEngine && mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
{
preferableBackend = backendId;
ortNeedsReinit = true; // will be applied on finalizeNet()
@@ -317,7 +317,7 @@ void Net::Impl::setPreferableBackend(Net& net, int backendId)
void Net::Impl::setPreferableTarget(int targetId)
{
#ifdef HAVE_ONNXRUNTIME
if (mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
if (useOrtEngine && mainGraph && modelFormat == DNN_MODEL_ONNX && !modelFileName.empty())
{
int resolved = IS_DNN_CUDA_TARGET(targetId) ? targetId : DNN_TARGET_CPU;
if (preferableTarget != resolved)
+1
View File
@@ -2847,6 +2847,7 @@ Net readNetFromONNX2_ORT(const String& onnxFile)
auto impl = net.getImpl();
impl->modelFileName = onnxFile;
impl->modelFormat = DNN_MODEL_ONNX;
impl->useOrtEngine = true;
impl->ortNeedsReinit = true;
// Create an empty main graph placeholder so that callers can detect