diff --git a/apps/model-diagnostics/model_diagnostics.cpp b/apps/model-diagnostics/model_diagnostics.cpp index 70f88f27ca..8a550f2e5d 100644 --- a/apps/model-diagnostics/model_diagnostics.cpp +++ b/apps/model-diagnostics/model_diagnostics.cpp @@ -98,12 +98,12 @@ int main( int argc, const char** argv ) std::string input4_name = argParser.get("input4_name"); std::string input4_shape = argParser.get("input4_shape"); - dnn::EngineType engine = dnn::ENGINE_NEW; + dnn::EngineType engine = dnn::ENGINE_OPENCV; if (argParser.has("engine")) { std::string eng_name = argParser.get("engine"); if(eng_name == "new") - engine = dnn::ENGINE_NEW; + engine = dnn::ENGINE_OPENCV; else if(eng_name == "ort") engine = dnn::ENGINE_ORT; else diff --git a/docs_sphinx/conf_helpers/postprocess.py b/docs_sphinx/conf_helpers/postprocess.py index 43e1d9e911..6112cea406 100644 --- a/docs_sphinx/conf_helpers/postprocess.py +++ b/docs_sphinx/conf_helpers/postprocess.py @@ -678,9 +678,8 @@ def _redirect_orphan_duplicates(app, out_dir: pathlib.Path) -> None: _DNN_ENGINE_LINKS = { "readNet": "dnn.html#readnet", "readNetFromONNX": "dnn.html#readnetfromonnx", - "ENGINE_NEW": "dnn.html#enginetype", - "ENGINE_CLASSIC": "dnn.html#enginetype", "ENGINE_AUTO": "dnn.html#enginetype", + "ENGINE_OPENCV": "dnn.html#enginetype", "ENGINE_ORT": "dnn.html#enginetype", "EngineType": "dnn.html#enginetype", "DNN_BACKEND_CUDA": "dnn.html#backend", diff --git a/modules/dnn/doc/dnn_engine.markdown b/modules/dnn/doc/dnn_engine.markdown index f72ae1d5ca..a1c628fdd5 100644 --- a/modules/dnn/doc/dnn_engine.markdown +++ b/modules/dnn/doc/dnn_engine.markdown @@ -6,31 +6,27 @@ OpenCV 5 introduces a selectable inference backend for the DNN module, referred The engine is specified at model-load time and cannot be changed after the model has been loaded, as each engine uses a different internal graph representation. -### ENGINE_NEW - -`ENGINE_NEW` is a ground-up rewrite of the DNN inference graph, introduced in OpenCV 5. It is built around a typed operation graph with shape inference, constant folding, and operator fusion, covering approximately 75-80% of the ONNX operator specification. Models that failed to load under OpenCV 4.x due to dynamic shapes or unsupported operators will typically load and run correctly under this engine. - -The engine performs automatic attention fusion: the `MatMul` → `Softmax` → `MatMul` subgraph common to transformer architectures is recognised and collapsed into a single fused operation at load time, with no changes required to the model or calling code. - -`ENGINE_NEW` also introduces native support for Large Language Models and Vision-Language Models. Built-in tokenizers, attention layers, decoding blocks, and KV-caching allow models such as Qwen, Gemma, and PaliGemma to run end-to-end through the standard `Net` API, with no external runtime required. - -In OpenCV 5.0, `ENGINE_NEW` runs on CPU only. Support for CUDA and other non-CPU backends is planned for a subsequent release. Users requiring GPU acceleration should use `ENGINE_CLASSIC` or `ENGINE_ORT`. - -### ENGINE_CLASSIC - -`ENGINE_CLASSIC` is the inference engine carried over from OpenCV 4.x. It supports the full set of DNN backends and hardware targets, including `DNN_BACKEND_CUDA` for NVIDIA GPUs, `DNN_BACKEND_OPENVINO` for Intel hardware, and FP16 inference targets. Its ONNX operator coverage is approximately 22% of the specification. Models with dynamic shapes or transformer-style subgraphs will generally not load under this engine. - -@note The Darknet and Caffe parsers have been removed in OpenCV 5; ONNX is the recommended format for all engines. TFLite models are still supported and currently executed via `ENGINE_CLASSIC`. - ### ENGINE_AUTO -`ENGINE_AUTO` is the default value for the engine parameter on all `readNet*()` functions. When active, OpenCV first attempts to load the model with `ENGINE_NEW`. If the model cannot be loaded - for example, because it uses an operator not yet implemented in the new engine - the load is automatically retried with `ENGINE_CLASSIC`. +`ENGINE_AUTO` is the default value for the engine parameter on all `readNet*()` functions. It lets OpenCV pick the engine: it currently resolves to `ENGINE_OPENCV`. The resolution is intentionally an implementation detail and may change as more engines are added, so code that does not need a specific engine should leave the default in place. Because `ENGINE_AUTO` is the default, existing code that does not pass an engine argument requires no modification. +### ENGINE_OPENCV + +`ENGINE_OPENCV` is OpenCV's built-in DNN engine, a ground-up rewrite of the inference graph introduced in OpenCV 5. It is built around a typed operation graph with shape inference, constant folding, and operator fusion, covering approximately 75-80% of the ONNX operator specification. Models that failed to load under OpenCV 4.x due to dynamic shapes or unsupported operators will typically load and run correctly under this engine. + +The engine performs automatic attention fusion: the `MatMul` → `Softmax` → `MatMul` subgraph common to transformer architectures is recognised and collapsed into a single fused operation at load time, with no changes required to the model or calling code. + +`ENGINE_OPENCV` also introduces native support for Large Language Models and Vision-Language Models. Built-in tokenizers, attention layers, decoding blocks, and KV-caching allow models such as Qwen, Gemma, and PaliGemma to run end-to-end through the standard `Net` API, with no external runtime required. + +In OpenCV 5.0, `ENGINE_OPENCV` runs on CPU only. Support for CUDA and other non-CPU backends is planned for a subsequent release. Users requiring GPU acceleration should use `ENGINE_ORT`. + +@note The Darknet and Caffe parsers have been removed in OpenCV 5; ONNX is the recommended format. TFLite and TensorFlow models are still supported and are executed via `ENGINE_OPENCV`. + ### ENGINE_ORT -`ENGINE_ORT` routes inference through a bundled ONNX Runtime (ORT) wrapper. OpenCV uses its own ONNX parser to construct the ORT graph internally, so only the ORT library is required at runtime, not the standalone onnx package. +`ENGINE_ORT` routes inference through a bundled ONNX Runtime (ORT) wrapper. OpenCV uses its own ONNX parser to construct the ORT graph internally, so only the ORT library is required at runtime, not the standalone onnx package. It applies to ONNX models only. `ENGINE_ORT` must be enabled at compile time: @@ -42,7 +38,7 @@ cmake -DWITH_ONNXRUNTIME=ON .. cmake -DWITH_ONNXRUNTIME=ON -DDOWNLOAD_ONNXRUNTIME_GPU=ON .. ``` -ORT execution providers are supported, including CUDA for NVIDIA hardware. This makes `ENGINE_ORT` the recommended choice for GPU-accelerated inference on models that `ENGINE_CLASSIC` cannot load, while native GPU support for `ENGINE_NEW` is still in development. +ORT execution providers are supported, including CUDA for NVIDIA hardware. This makes `ENGINE_ORT` the recommended choice for GPU-accelerated inference while native GPU support for `ENGINE_OPENCV` is still in development. ### Selecting an Engine @@ -50,18 +46,13 @@ The engine parameter is accepted by the `readNet*()` family of functions. @add_toggle_cpp @code{.cpp} -// ENGINE_AUTO is the default +// ENGINE_AUTO is the default (resolves to ENGINE_OPENCV) cv::dnn::Net net = cv::dnn::readNetFromONNX("model.onnx"); -// Force the new engine -cv::dnn::Net net = cv::dnn::readNetFromONNX("model.onnx", cv::dnn::ENGINE_NEW); +// Explicitly select OpenCV's built-in engine +cv::dnn::Net net = cv::dnn::readNetFromONNX("model.onnx", cv::dnn::ENGINE_OPENCV); -// Force the classic engine with CUDA backend -cv::dnn::Net net = cv::dnn::readNetFromONNX("model.onnx", cv::dnn::ENGINE_CLASSIC); -net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); -net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); - -// Use ONNX Runtime +// Use ONNX Runtime (ONNX models only, requires WITH_ONNXRUNTIME=ON) cv::dnn::Net net = cv::dnn::readNetFromONNX("model.onnx", cv::dnn::ENGINE_ORT); @endcode @end_toggle @@ -70,18 +61,13 @@ cv::dnn::Net net = cv::dnn::readNetFromONNX("model.onnx", cv::dnn::ENGINE_ORT); @code{.py} import cv2 -# ENGINE_AUTO is the default +# ENGINE_AUTO is the default (resolves to ENGINE_OPENCV) net = cv2.dnn.readNetFromONNX("model.onnx") -# Force the new engine -net = cv2.dnn.readNetFromONNX("model.onnx", engine=cv2.dnn.ENGINE_NEW) +# Explicitly select OpenCV's built-in engine +net = cv2.dnn.readNetFromONNX("model.onnx", engine=cv2.dnn.ENGINE_OPENCV) -# Force the classic engine with CUDA backend -net = cv2.dnn.readNetFromONNX("model.onnx", engine=cv2.dnn.ENGINE_CLASSIC) -net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) -net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA) - -# Use ONNX Runtime +# Use ONNX Runtime (ONNX models only, requires WITH_ONNXRUNTIME=ON) net = cv2.dnn.readNetFromONNX("model.onnx", engine=cv2.dnn.ENGINE_ORT) @endcode @end_toggle @@ -90,7 +76,7 @@ The engine cannot be changed after a model has been loaded. To use a different e ### Engine Selection via Environment Variable -The engine can be overridden at the process level using the `OPENCV_FORCE_DNN_ENGINE` environment variable. The integer values correspond directly to the `EngineType` enum: 1 for `ENGINE_CLASSIC`, 2 for `ENGINE_NEW`, 3 for `ENGINE_AUTO`, and 4 for `ENGINE_ORT`. +The engine can be overridden at the process level using the `OPENCV_FORCE_DNN_ENGINE` environment variable. The integer values correspond directly to the `EngineType` enum: 0 for `ENGINE_AUTO`, 1 for `ENGINE_OPENCV`, and 2 for `ENGINE_ORT`. Leaving the variable unset (or set to `ENGINE_AUTO`) does not force any engine, so the value passed to `readNet*()` is honored. ```bash # Linux / macOS diff --git a/modules/dnn/include/opencv2/dnn/dnn.hpp b/modules/dnn/include/opencv2/dnn/dnn.hpp index f290b81e93..defdf59046 100644 --- a/modules/dnn/include/opencv2/dnn/dnn.hpp +++ b/modules/dnn/include/opencv2/dnn/dnn.hpp @@ -835,7 +835,7 @@ CV__DNN_INLINE_NS_BEGIN */ CV_WRAP void setParam(int layer, int numParam, CV_ND const Mat &blob); /** @brief Sets the parameter blob of a layer identified by its name or output tensor name. - * @param layerName raw ONNX output tensor name (ENGINE_NEW). + * @param layerName raw ONNX output tensor name (ENGINE_OPENCV). * @param numParam index of the constant weight input to update (0 = kernel, 1 = bias, etc.). * @param blob the new parameter value. */ @@ -1083,8 +1083,9 @@ CV__DNN_INLINE_NS_BEGIN enum EngineType { - ENGINE_NEW=2, //!< Use the new dnn engine. This is the only supported engine. The engine does not support non CPU back-ends for now. - ENGINE_ORT=4 //!< Try to use ONNX Runtime wrapper (ONNX only, requires build with WITH_ONNXRUNTIME=ON). + ENGINE_AUTO=0, //!< Automatically select the engine. Currently resolves to ENGINE_OPENCV; the mapping may change as more engines are added. + ENGINE_OPENCV=1, //!< Use OpenCV's built-in DNN engine. Does not support non-CPU back-ends for now. + ENGINE_ORT=2 //!< Use the ONNX Runtime wrapper (ONNX only, requires build with WITH_ONNXRUNTIME=ON). }; /** @brief Reads a network model stored in TensorFlow framework's format. @@ -1099,7 +1100,7 @@ CV__DNN_INLINE_NS_BEGIN */ CV_EXPORTS_W Net readNetFromTensorflow(CV_WRAP_FILE_PATH const String &model, CV_WRAP_FILE_PATH const String &config = String(), - int engine=ENGINE_NEW, + int engine=ENGINE_AUTO, const std::vector& extraOutputs = std::vector()); /** @brief Reads a network model stored in TensorFlow framework's format. @@ -1112,7 +1113,7 @@ CV__DNN_INLINE_NS_BEGIN */ CV_EXPORTS_W Net readNetFromTensorflow(const std::vector& bufferModel, const std::vector& bufferConfig = std::vector(), - int engine=ENGINE_NEW, + int engine=ENGINE_AUTO, const std::vector& extraOutputs = std::vector()); /** @brief Reads a network model stored in TensorFlow framework's format. @@ -1128,34 +1129,34 @@ CV__DNN_INLINE_NS_BEGIN */ CV_EXPORTS Net readNetFromTensorflow(const char *bufferModel, size_t lenModel, const char *bufferConfig = NULL, size_t lenConfig = 0, - int engine=ENGINE_NEW, + int engine=ENGINE_AUTO, const std::vector& extraOutputs = std::vector()); /** @brief Reads a network model stored in TFLite framework's format. * @param model path to the .tflite file with binary flatbuffers description of the network architecture - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Net object. */ - CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_NEW); + CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_AUTO); /** @brief Reads a network model stored in TFLite framework's format. * @param bufferModel buffer containing the content of the tflite file - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Net object. */ - CV_EXPORTS_W Net readNetFromTFLite(const std::vector& bufferModel, int engine=ENGINE_NEW); + CV_EXPORTS_W Net readNetFromTFLite(const std::vector& bufferModel, int engine=ENGINE_AUTO); /** @brief Reads a network model stored in TFLite framework's format. * @details This is an overloaded member function, provided for convenience. * It differs from the above function only in what argument(s) it accepts. * @param bufferModel buffer containing the content of the tflite file * @param lenModel length of bufferModel - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * Please pay attention that the new DNN does not support non-CPU back-ends for now. */ - CV_EXPORTS Net readNetFromTFLite(const char *bufferModel, size_t lenModel, int engine=ENGINE_NEW); + CV_EXPORTS Net readNetFromTFLite(const char *bufferModel, size_t lenModel, int engine=ENGINE_AUTO); /** * @brief Read deep learning network represented in one of the supported formats. @@ -1169,7 +1170,7 @@ CV__DNN_INLINE_NS_BEGIN * * `*.pbtxt` (TensorFlow, https://www.tensorflow.org/) * * `*.xml` (OpenVINO, https://software.intel.com/openvino-toolkit) * @param[in] framework Explicit framework name tag to determine a format. - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Net object. * @@ -1180,7 +1181,7 @@ CV__DNN_INLINE_NS_BEGIN CV_EXPORTS_W Net readNet(CV_WRAP_FILE_PATH const String& model, CV_WRAP_FILE_PATH const String& config = "", const String& framework = "", - int engine = ENGINE_NEW); + int engine = ENGINE_AUTO); /** * @brief Read deep learning network represented in one of the supported formats. @@ -1189,13 +1190,13 @@ CV__DNN_INLINE_NS_BEGIN * @param[in] framework Name of origin framework. * @param[in] bufferModel A buffer with a content of binary file with weights * @param[in] bufferConfig A buffer with a content of text file contains network configuration. - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Net object. */ CV_EXPORTS_W Net readNet(const String& framework, const std::vector& bufferModel, const std::vector& bufferConfig = std::vector(), - int engine = ENGINE_NEW); + int engine = ENGINE_AUTO); /** @brief Load a network from Intel's Model Optimizer intermediate representation. * @param[in] xml XML configuration file with network's topology. @@ -1233,31 +1234,31 @@ CV__DNN_INLINE_NS_BEGIN /** @brief Reads a network model ONNX. * @param onnxFile path to the .onnx file with text description of the network architecture. - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Network object that ready to do forward, throw an exception in failure cases. */ - CV_EXPORTS_W Net readNetFromONNX(CV_WRAP_FILE_PATH const String &onnxFile, int engine=ENGINE_NEW); + CV_EXPORTS_W Net readNetFromONNX(CV_WRAP_FILE_PATH const String &onnxFile, int engine=ENGINE_AUTO); /** @brief Reads a network model from ONNX * in-memory buffer. * @param buffer memory address of the first byte of the buffer. * @param sizeBuffer size of the buffer. - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * @returns Network object that ready to do forward, throw an exception * in failure cases. */ - CV_EXPORTS Net readNetFromONNX(const char* buffer, size_t sizeBuffer, int engine=ENGINE_NEW); + CV_EXPORTS Net readNetFromONNX(const char* buffer, size_t sizeBuffer, int engine=ENGINE_AUTO); /** @brief Reads a network model from ONNX * in-memory buffer. * @param buffer in-memory buffer that stores the ONNX model bytes. - * @param engine select DNN engine to be used. Only ENGINE_NEW (the default) and ENGINE_ORT are supported. + * @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV; ENGINE_ORT selects the ONNX Runtime wrapper (ONNX models only, requires WITH_ONNXRUNTIME=ON). * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Network object that ready to do forward, throw an exception * in failure cases. */ - CV_EXPORTS_W Net readNetFromONNX(const std::vector& buffer, int engine=ENGINE_NEW); + CV_EXPORTS_W Net readNetFromONNX(const std::vector& buffer, int engine=ENGINE_AUTO); /** @brief Creates blob from .pb file. * @param path to the .pb file with input tensor. diff --git a/modules/dnn/misc/java/test/DnnForwardAndRetrieve.java b/modules/dnn/misc/java/test/DnnForwardAndRetrieve.java index 326c670b97..9b0eb5b7a7 100644 --- a/modules/dnn/misc/java/test/DnnForwardAndRetrieve.java +++ b/modules/dnn/misc/java/test/DnnForwardAndRetrieve.java @@ -45,7 +45,7 @@ public class DnnForwardAndRetrieve extends OpenCVTestCase { public void testForwardAndRetrieve() { // Verifies forwardAndRetrieve nested list marshalling using a small ONNX model instead of the removed Caffe importer. - Net net = Dnn.readNetFromONNX(modelFileName, Dnn.ENGINE_NEW); + Net net = Dnn.readNetFromONNX(modelFileName, Dnn.ENGINE_OPENCV); net.setPreferableBackend(Dnn.DNN_BACKEND_OPENCV); // split_0.onnx declares a single 4D input named "image" of shape [1, 3, 2, 2]. diff --git a/modules/dnn/misc/python/test/test_dnn.py b/modules/dnn/misc/python/test/test_dnn.py index 8f45a82947..4d2d9d5367 100755 --- a/modules/dnn/misc/python/test/test_dnn.py +++ b/modules/dnn/misc/python/test/test_dnn.py @@ -366,7 +366,7 @@ class dnn_test(NewOpenCVTests): for backend, target in self.dnnBackendsAndTargets: printParams(backend, target) - net = cv.dnn.readNet(model, engine=cv.dnn.ENGINE_NEW) + net = cv.dnn.readNet(model, engine=cv.dnn.ENGINE_OPENCV) net.setPreferableBackend(backend) net.setPreferableTarget(target) @@ -415,7 +415,7 @@ class dnn_test(NewOpenCVTests): for backend, target in self.dnnBackendsAndTargets: printParams(backend, target) - net = cv.dnn.readNet(model_path, "", "", engine=cv.dnn.ENGINE_NEW) + net = cv.dnn.readNet(model_path, "", "", engine=cv.dnn.ENGINE_OPENCV) node_name = net.getLayerNames()[0] w = net.getParam(node_name, 0) # returns the original tensor of three-dimensional shape diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 8b966c68ca..e009a3b30b 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -54,19 +54,22 @@ CV__DNN_INLINE_NS_BEGIN #ifdef HAVE_PROTOBUF -// ENGINE_CLASSIC/ENGINE_AUTO have been removed. Resolve any engine request to a -// supported one (ENGINE_NEW or ENGINE_ORT), honoring the OPENCV_FORCE_DNN_ENGINE override. +// Resolve an engine request to a concrete supported engine (ENGINE_OPENCV or ENGINE_ORT). +// ENGINE_AUTO resolves to ENGINE_OPENCV. The OPENCV_FORCE_DNN_ENGINE override, when set to a +// concrete engine, wins over the caller's choice; left unset (ENGINE_AUTO) it does not force. static int resolveOnnxEngine(int engine) { static const int engine_forced = - (int)utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_NEW); - if (engine_forced == ENGINE_NEW || engine_forced == ENGINE_ORT) + (int)utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO); + if (engine_forced == ENGINE_OPENCV || engine_forced == ENGINE_ORT) engine = engine_forced; - if (engine != ENGINE_NEW && engine != ENGINE_ORT) + if (engine == ENGINE_AUTO) + engine = ENGINE_OPENCV; + if (engine != ENGINE_OPENCV && engine != ENGINE_ORT) { - CV_LOG_WARNING(NULL, "DNN/ONNX: only ENGINE_NEW and ENGINE_ORT are supported; " - "ENGINE_CLASSIC/ENGINE_AUTO are deprecated, falling back to ENGINE_NEW."); - engine = ENGINE_NEW; + CV_LOG_WARNING(NULL, "DNN/ONNX: only ENGINE_AUTO, ENGINE_OPENCV and ENGINE_ORT are supported; " + "falling back to ENGINE_OPENCV."); + engine = ENGINE_OPENCV; } return engine; } @@ -83,7 +86,7 @@ Net readNetFromONNX(const String& onnxFile, int engine) CV_Error(Error::StsError, "DNN/ONNX/ORT: ONNX Runtime model metadata was not initialized"); return net; #else - CV_LOG_WARNING(NULL, "DNN/ONNX/ORT: OpenCV was built without ONNX Runtime (WITH_ONNXRUNTIME=OFF). Falling back to ENGINE_NEW."); + CV_LOG_WARNING(NULL, "DNN/ONNX/ORT: OpenCV was built without ONNX Runtime (WITH_ONNXRUNTIME=OFF). Falling back to ENGINE_OPENCV."); #endif } return readNetFromONNX2(onnxFile); @@ -96,7 +99,7 @@ Net readNetFromONNX(const char* buffer, size_t sizeBuffer, int engine) #ifdef HAVE_ONNXRUNTIME CV_Error(Error::StsNotImplemented, "DNN/ONNX/ORT: loading from memory buffer is not supported"); #else - CV_LOG_WARNING(NULL, "DNN/ONNX/ORT: OpenCV was built without ONNX Runtime (WITH_ONNXRUNTIME=OFF). Falling back to ENGINE_NEW."); + CV_LOG_WARNING(NULL, "DNN/ONNX/ORT: OpenCV was built without ONNX Runtime (WITH_ONNXRUNTIME=OFF). Falling back to ENGINE_OPENCV."); #endif } return readNetFromONNX2(buffer, sizeBuffer); @@ -109,7 +112,7 @@ Net readNetFromONNX(const std::vector& buffer, int engine) #ifdef HAVE_ONNXRUNTIME CV_Error(Error::StsNotImplemented, "DNN/ONNX/ORT: loading from memory buffer is not supported"); #else - CV_LOG_WARNING(NULL, "DNN/ONNX/ORT: OpenCV was built without ONNX Runtime (WITH_ONNXRUNTIME=OFF). Falling back to ENGINE_NEW."); + CV_LOG_WARNING(NULL, "DNN/ONNX/ORT: OpenCV was built without ONNX Runtime (WITH_ONNXRUNTIME=OFF). Falling back to ENGINE_OPENCV."); #endif } return readNetFromONNX2(buffer); diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index 0204c6b1a5..441d73004b 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -3263,16 +3263,16 @@ void TFLayerHandler::handleFailed(const tensorflow::NodeDef& layer) } // namespace -// ENGINE_CLASSIC/ENGINE_AUTO have been removed; the TensorFlow importer always uses the new engine. +// The TensorFlow importer always runs on the OpenCV engine; ENGINE_AUTO resolves to it. static void warnIfUnsupportedTfEngine(int engine) { static const int engine_forced = - (int)utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_NEW); - if (engine_forced == ENGINE_NEW) + (int)utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO); + if (engine_forced == ENGINE_OPENCV) engine = engine_forced; - if (engine != ENGINE_NEW) - CV_LOG_WARNING(NULL, "DNN/TF: only ENGINE_NEW is supported; " - "ENGINE_CLASSIC/ENGINE_AUTO are deprecated, using ENGINE_NEW."); + if (engine != ENGINE_AUTO && engine != ENGINE_OPENCV) + CV_LOG_WARNING(NULL, "DNN/TF: only ENGINE_AUTO and ENGINE_OPENCV are supported; " + "using ENGINE_OPENCV."); } Net readNetFromTensorflow(const String &model, const String &config, int engine, diff --git a/modules/dnn/src/tflite/tflite_importer.cpp b/modules/dnn/src/tflite/tflite_importer.cpp index b2235428a7..9239edac41 100644 --- a/modules/dnn/src/tflite/tflite_importer.cpp +++ b/modules/dnn/src/tflite/tflite_importer.cpp @@ -1503,16 +1503,16 @@ void TFLiteImporter::getQuantParams(const Operator& op, float& inpScale, int& in } } -// ENGINE_CLASSIC/ENGINE_AUTO have been removed; the TFLite importer always uses the new engine. +// The TFLite importer always runs on the OpenCV engine; ENGINE_AUTO resolves to it. static void warnIfUnsupportedTFLiteEngine(int engine) { static const int engine_forced = - (int)utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_NEW); - if (engine_forced == ENGINE_NEW) + (int)utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO); + if (engine_forced == ENGINE_OPENCV) engine = engine_forced; - if (engine != ENGINE_NEW) - CV_LOG_WARNING(NULL, "DNN/TFLite: only ENGINE_NEW is supported; " - "ENGINE_CLASSIC/ENGINE_AUTO are deprecated, using ENGINE_NEW."); + if (engine != ENGINE_AUTO && engine != ENGINE_OPENCV) + CV_LOG_WARNING(NULL, "DNN/TFLite: only ENGINE_AUTO and ENGINE_OPENCV are supported; " + "using ENGINE_OPENCV."); } Net readNetFromTFLite(const String &modelPath, int engine) { diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index 27f2f69610..7c8968d66e 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -2252,7 +2252,7 @@ TEST(Layer_If, resize) const std::string imgname = findDataFile("cv/shared/lena.png", true); const std::string modelname = findDataFile("dnn/onnx/models/if_layer.onnx", true); - dnn::Net net = dnn::readNetFromONNX(modelname, ENGINE_NEW); + dnn::Net net = dnn::readNetFromONNX(modelname, ENGINE_OPENCV); Mat src = imread(imgname), blob; dnn::blobFromImage(src, blob, 1.0, cv::Size(), cv::Scalar(), false, false); @@ -2276,7 +2276,7 @@ TEST(Layer_If, resize) TEST(Layer_If, subgraph_name_scoping) { const std::string modelname = findDataFile("dnn/onnx/models/subgraph_name_scoping.onnx", true); - dnn::Net net = dnn::readNetFromONNX(modelname, ENGINE_NEW); + dnn::Net net = dnn::readNetFromONNX(modelname, ENGINE_OPENCV); int xshape[1] = {2}; Mat x(1, xshape, CV_32F); @@ -2313,7 +2313,7 @@ TEST(Layer_If, subgraph_name_scoping) TEST(Layer_Size, onnx_1d) { const std::string modelname = findDataFile("dnn/onnx/models/test_size_1d_model.onnx", true); - cv::dnn::Net net = cv::dnn::readNetFromONNX(modelname, ENGINE_NEW); + cv::dnn::Net net = cv::dnn::readNetFromONNX(modelname, ENGINE_OPENCV); int sz1d[1] = {7}; cv::Mat x(1, sz1d, CV_32F); @@ -2332,7 +2332,7 @@ TEST(Layer_Size, onnx_1d) TEST(Layer_Size, onnx_0d_scalar) { const std::string modelname = findDataFile("dnn/onnx/models/test_size_0d_model.onnx", true); - cv::dnn::Net net = cv::dnn::readNetFromONNX(modelname, ENGINE_NEW); + cv::dnn::Net net = cv::dnn::readNetFromONNX(modelname, ENGINE_OPENCV); cv::Mat x(1, 1, CV_32F); x.at(0, 0) = 3.14f; @@ -2397,9 +2397,9 @@ public: { std::string model_path = "dnn/onnx/models/test_attention_kv_cache_" + layout + ".onnx"; - Net netWithKVCache = readNetFromONNX(findDataFile(model_path, true), cv::dnn::ENGINE_NEW); + Net netWithKVCache = readNetFromONNX(findDataFile(model_path, true), cv::dnn::ENGINE_OPENCV); netWithKVCache.enableKVCache(); - Net netWithoutKVCache = readNetFromONNX(findDataFile(model_path, true), cv::dnn::ENGINE_NEW); + Net netWithoutKVCache = readNetFromONNX(findDataFile(model_path, true), cv::dnn::ENGINE_OPENCV); int T = 523, Nq = 8, Nkv = 4, D = 256; // Keep the prefill larger than one cache page, then exercise generation diff --git a/modules/dnn/test/test_model.cpp b/modules/dnn/test/test_model.cpp index 6111b232b7..81be489d98 100644 --- a/modules/dnn/test/test_model.cpp +++ b/modules/dnn/test/test_model.cpp @@ -825,7 +825,7 @@ TEST_P(Reproducibility_ViT_ONNX, Accuracy) topK(out, res, K); ASSERT_EQ(int(res.size()), K); - // Reference top-5 captured from the ONNX Runtime engine (OPENCV_FORCE_DNN_ENGINE=4). + // Reference top-5 captured from the ONNX Runtime engine (OPENCV_FORCE_DNN_ENGINE=2, ENGINE_ORT). std::vector > ref = { {285, 7.683f}, {282, 7.182f}, {281, 6.894f}, {287, 3.623f}, {283, 3.287f} }; @@ -1352,7 +1352,7 @@ TEST_P(Reproducibility_SwinIR_ONNX, Accuracy) applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_LONG); std::string modelname = _tf("onnx/models/swinir_x4_gan.onnx", false); - Net net = readNetFromONNX(modelname, ENGINE_NEW); + Net net = readNetFromONNX(modelname, ENGINE_OPENCV); ASSERT_FALSE(net.empty()); net.setPreferableBackend(DNN_BACKEND_OPENCV); diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index fdbee029e3..5b35d9dd20 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -3758,7 +3758,7 @@ INSTANTIATE_TEST_CASE_P(/**/, Test_ONNX_nets, dnnBackendsAndTargets()); TEST_P(Test_ONNX_layers, getUnconnectedOutLayers) { auto engine_forced = static_cast( - cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_NEW)); + cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO)); if (engine_forced == cv::dnn::ENGINE_ORT) applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER); diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index 443b4a0f89..8b93269c74 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -1813,7 +1813,7 @@ TEST_P(Test_TensorFlow_nets, Mask_RCNN) outNames[0] = "detection_out_final"; outNames[1] = "detection_masks"; - Net net = readNetFromTensorflow(model, proto, ENGINE_NEW, outNames); + Net net = readNetFromTensorflow(model, proto, ENGINE_OPENCV, outNames); Mat refDetections = blobFromNPY(path("mask_rcnn_inception_v2_coco_2018_01_28.detection_out.npy")); Mat refMasks = blobFromNPY(path("mask_rcnn_inception_v2_coco_2018_01_28.detection_masks.npy")); Mat blob = blobFromImage(img, 1.0f, Size(800, 800), Scalar(), true, false); diff --git a/modules/features/include/opencv2/features.hpp b/modules/features/include/opencv2/features.hpp index f9d14e5b51..db3b1e5a13 100644 --- a/modules/features/include/opencv2/features.hpp +++ b/modules/features/include/opencv2/features.hpp @@ -859,7 +859,7 @@ public: CV_WRAP Params(); CV_PROP_RW Size inputSize; //!< Input image size for the network, default 640x640 CV_PROP_RW bool normalizeDescriptors; //!< Whether to L2-normalize descriptors, default true - CV_PROP_RW int engine; //!< DNN engine type (dnn::EngineType), default ENGINE_NEW + CV_PROP_RW int engine; //!< DNN engine type (dnn::EngineType), default ENGINE_AUTO CV_PROP_RW int backend; //!< DNN backend, default DNN_BACKEND_DEFAULT CV_PROP_RW int target; //!< DNN target, default DNN_TARGET_CPU }; diff --git a/modules/features/src/feature2d_aliked.cpp b/modules/features/src/feature2d_aliked.cpp index 1a80b00eae..be496f0af8 100644 --- a/modules/features/src/feature2d_aliked.cpp +++ b/modules/features/src/feature2d_aliked.cpp @@ -20,7 +20,7 @@ ALIKED::Params::Params() inputSize = Size(640, 640); normalizeDescriptors = true; #ifdef HAVE_OPENCV_DNN - engine = dnn::ENGINE_NEW; + engine = dnn::ENGINE_AUTO; backend = dnn::DNN_BACKEND_DEFAULT; target = dnn::DNN_TARGET_CPU; #else diff --git a/samples/cpp/macbeth_chart_detection.cpp b/samples/cpp/macbeth_chart_detection.cpp index 3308caf4df..fa83f12a3b 100644 --- a/samples/cpp/macbeth_chart_detection.cpp +++ b/samples/cpp/macbeth_chart_detection.cpp @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) Ptr detector; #ifdef HAVE_OPENCV_DNN if (model_path != "" && pbtxt_path != ""){ - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; Net net = readNetFromTensorflow(model_path, pbtxt_path, engine); net.setPreferableBackend(getBackendID(backend)); net.setPreferableTarget(getTargetID(target)); diff --git a/samples/dnn/alpha_matting.cpp b/samples/dnn/alpha_matting.cpp index a6a2bba0a0..a7c4b39205 100644 --- a/samples/dnn/alpha_matting.cpp +++ b/samples/dnn/alpha_matting.cpp @@ -165,7 +165,7 @@ int main(int argc, char **argv) parser.about(about); - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; Net net; loadModel(model, backend, target, net, engine); diff --git a/samples/dnn/alpha_matting.py b/samples/dnn/alpha_matting.py index 61be31bedd..7bb2fff50b 100644 --- a/samples/dnn/alpha_matting.py +++ b/samples/dnn/alpha_matting.py @@ -140,7 +140,7 @@ def apply_modnet(args, model, image): def main(func_args=None): args = get_args_parser(func_args) - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV image = cv.imread(cv.samples.findFile(args.input)) if image is None: diff --git a/samples/dnn/classification.cpp b/samples/dnn/classification.cpp index 7815118e05..417afddfb3 100644 --- a/samples/dnn/classification.cpp +++ b/samples/dnn/classification.cpp @@ -146,7 +146,7 @@ int main(int argc, char** argv) } CV_Assert(!model.empty()); //! [Read and initialize network] - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; Net net = readNetFromONNX(model, engine); net.setPreferableBackend(getBackendID(backend)); net.setPreferableTarget(getTargetID(target)); diff --git a/samples/dnn/classification.py b/samples/dnn/classification.py index 48d7efbfef..0d253a2378 100644 --- a/samples/dnn/classification.py +++ b/samples/dnn/classification.py @@ -83,7 +83,7 @@ def main(func_args=None): labels = f.read().rstrip('\n').split('\n') # Load a network - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV net = cv.dnn.readNetFromONNX(args.model, engine) net.setPreferableBackend(get_backend_id(args.backend)) net.setPreferableTarget(get_target_id(args.target)) diff --git a/samples/dnn/colorization.cpp b/samples/dnn/colorization.cpp index ac0ca26b3c..5dffad98d0 100644 --- a/samples/dnn/colorization.cpp +++ b/samples/dnn/colorization.cpp @@ -83,7 +83,7 @@ int main(int argc, char** argv) { resize(imgL, imgLResized, Size(256, 256), 0, 0, INTER_CUBIC); // Prepare the model - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; dnn::Net net = dnn::readNetFromONNX(onnxModelPath, engine); net.setPreferableBackend(backendId); net.setPreferableTarget(targetId); diff --git a/samples/dnn/colorization.py b/samples/dnn/colorization.py index 6ee7e6c40b..47844eca7c 100644 --- a/samples/dnn/colorization.py +++ b/samples/dnn/colorization.py @@ -44,7 +44,7 @@ if __name__ == '__main__': img_gray_rs *= (100.0 / 255.0) # Scale L channel to 0-100 range onnx_model_path = args.onnx_model_path # Update this path to your ONNX model's path - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV session = cv.dnn.readNetFromONNX(onnx_model_path, engine) session.setPreferableBackend(args.backend) session.setPreferableTarget(args.target) diff --git a/samples/dnn/deblurring.cpp b/samples/dnn/deblurring.cpp index af3ed5e97c..5212440fa2 100644 --- a/samples/dnn/deblurring.cpp +++ b/samples/dnn/deblurring.cpp @@ -95,7 +95,7 @@ int main(int argc, char **argv) bool swapRB = parser.get("rgb"); Scalar mean_v = parser.get("mean"); - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; Net net = readNetFromONNX(modelPath, engine); net.setPreferableBackend(getBackendID(backend)); diff --git a/samples/dnn/deblurring.py b/samples/dnn/deblurring.py index 96cf665b19..13174fdf1b 100644 --- a/samples/dnn/deblurring.py +++ b/samples/dnn/deblurring.py @@ -83,7 +83,7 @@ def main(): args.model = findModel(args.model, args.sha1) - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV net = cv.dnn.readNetFromONNX(args.model, engine) net.setPreferableBackend(get_backend_id(args.backend)) diff --git a/samples/dnn/edge_detection.cpp b/samples/dnn/edge_detection.cpp index 83916e7b76..fbbff0318b 100644 --- a/samples/dnn/edge_detection.cpp +++ b/samples/dnn/edge_detection.cpp @@ -159,7 +159,7 @@ int main(int argc, char** argv) { string method = parser.get("method"); String sha1 = parser.get("sha1"); string model = findModel(parser.get("model"), sha1); - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; parser.about(about); VideoCapture cap; diff --git a/samples/dnn/edge_detection.py b/samples/dnn/edge_detection.py index bbb175bcd2..1ce5228b1a 100644 --- a/samples/dnn/edge_detection.py +++ b/samples/dnn/edge_detection.py @@ -110,7 +110,7 @@ def apply_dexined(model, image): def main(func_args=None): args = get_args_parser(func_args) - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV cap = cv.VideoCapture(cv.samples.findFile(args.input) if args.input else 0) if not cap.isOpened(): diff --git a/samples/dnn/gemma3_inference.py b/samples/dnn/gemma3_inference.py index 362768f03a..6c1ba44d7e 100644 --- a/samples/dnn/gemma3_inference.py +++ b/samples/dnn/gemma3_inference.py @@ -129,7 +129,7 @@ if __name__ == '__main__': print("Preparing Gemma3 model...") tokenizer = cv.dnn.Tokenizer.load(args.tokenizer_path) - net = cv.dnn.readNetFromONNX(args.model, cv.dnn.ENGINE_NEW) + net = cv.dnn.readNetFromONNX(args.model, cv.dnn.ENGINE_OPENCV) gemma3_prompt = build_gemma3_prompt(args.prompt) print(f"Prompt:\n{gemma3_prompt}") diff --git a/samples/dnn/gpt2_inference.py b/samples/dnn/gpt2_inference.py index eaf4c563e8..9b897cfc0e 100644 --- a/samples/dnn/gpt2_inference.py +++ b/samples/dnn/gpt2_inference.py @@ -82,7 +82,7 @@ if __name__ == '__main__': prompt = args.prompt tokenizer_path = args.tokenizer_path - net = cv.dnn.readNetFromONNX(args.model, cv.dnn.ENGINE_NEW) + net = cv.dnn.readNetFromONNX(args.model, cv.dnn.ENGINE_OPENCV) tokenizer = cv.dnn.Tokenizer.load(tokenizer_path) tokens = gpt2_inference(net, prompt, max_length, tokenizer) diff --git a/samples/dnn/inpainting.cpp b/samples/dnn/inpainting.cpp index 164bbfe026..446aff8da9 100644 --- a/samples/dnn/inpainting.cpp +++ b/samples/dnn/inpainting.cpp @@ -129,7 +129,7 @@ int main(int argc, char **argv) cout<<"Model loading..."<("backend")); net.setPreferableBackend(backend); diff --git a/samples/dnn/object_detection.py b/samples/dnn/object_detection.py index e16d5a1692..2f550da686 100644 --- a/samples/dnn/object_detection.py +++ b/samples/dnn/object_detection.py @@ -99,7 +99,7 @@ if args.labels: labels = f.read().rstrip('\n').split('\n') # Load a network -engine = cv.dnn.ENGINE_NEW +engine = cv.dnn.ENGINE_OPENCV net = cv.dnn.readNet(args.model, args.config, "", engine) net.setPreferableBackend(get_backend_id(args.backend)) net.setPreferableTarget(get_target_id(args.target)) diff --git a/samples/dnn/person_reid.cpp b/samples/dnn/person_reid.cpp index 3c55ca0446..d7dc7fb85a 100644 --- a/samples/dnn/person_reid.cpp +++ b/samples/dnn/person_reid.cpp @@ -258,7 +258,7 @@ int main(int argc, char **argv) int fontSize = 50; int fontWeight = 500; - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; Net reidNet = readNetFromONNX(modelPath, engine); reidNet.setPreferableBackend(getBackendID(backend)); reidNet.setPreferableTarget(getTargetID(target)); diff --git a/samples/dnn/person_reid.py b/samples/dnn/person_reid.py index 4d04cdc89a..3369c874fb 100644 --- a/samples/dnn/person_reid.py +++ b/samples/dnn/person_reid.py @@ -183,7 +183,7 @@ def main(): else: args.yolo_model = findModel(args.yolo_model, args.yolo_sha1) - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV yolo_net = cv.dnn.readNetFromONNX(args.yolo_model, engine) reid_net = cv.dnn.readNetFromONNX(args.model, engine) reid_net.setPreferableBackend(get_backend_id(args.backend)) diff --git a/samples/dnn/qwen_inference.py b/samples/dnn/qwen_inference.py index d36e923d4d..5b00efe8e2 100644 --- a/samples/dnn/qwen_inference.py +++ b/samples/dnn/qwen_inference.py @@ -123,7 +123,7 @@ if __name__ == '__main__': print("Preparing Qwen2.5 model...") tokenizer = cv.dnn.Tokenizer.load(args.tokenizer_path) - net = cv.dnn.readNetFromONNX(args.model, cv.dnn.ENGINE_NEW) + net = cv.dnn.readNetFromONNX(args.model, cv.dnn.ENGINE_OPENCV) chatml_prompt = build_chatml_prompt(args.prompt) print(f"Prompt:\n{chatml_prompt}") diff --git a/samples/dnn/segmentation.cpp b/samples/dnn/segmentation.cpp index 1a2ebb2b35..ca424d8d58 100644 --- a/samples/dnn/segmentation.cpp +++ b/samples/dnn/segmentation.cpp @@ -214,7 +214,7 @@ int main(int argc, char **argv) CV_Assert(!model.empty()); //! [Read and initialize network] - EngineType engine = ENGINE_NEW; + EngineType engine = ENGINE_OPENCV; Net net = readNetFromONNX(model, engine); net.setPreferableBackend(getBackendID(backend)); net.setPreferableTarget(getTargetID(target)); diff --git a/samples/dnn/segmentation.py b/samples/dnn/segmentation.py index 7d92fcaed4..9a92e21c7a 100644 --- a/samples/dnn/segmentation.py +++ b/samples/dnn/segmentation.py @@ -100,7 +100,7 @@ def main(func_args=None): colors = [np.array(color.split(' '), np.uint8) for color in f.read().rstrip('\n').split('\n')] # Load a network - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV net = cv.dnn.readNetFromONNX(args.model, engine) net.setPreferableBackend(get_backend_id(args.backend)) net.setPreferableTarget(get_target_id(args.target)) diff --git a/samples/dnn/vlm_inference.py b/samples/dnn/vlm_inference.py index 06d1198f14..be93366203 100644 --- a/samples/dnn/vlm_inference.py +++ b/samples/dnn/vlm_inference.py @@ -117,9 +117,9 @@ if __name__ == '__main__': print("Preparing PaliGemma2 model...") tokenizer = cv.dnn.Tokenizer.load(args.tokenizer_path) - siglip_net = cv.dnn.readNetFromONNX(args.siglip, cv.dnn.ENGINE_NEW) - embed_net = cv.dnn.readNetFromONNX(args.embedding, cv.dnn.ENGINE_NEW) - gemma_net = cv.dnn.readNetFromONNX(args.gemma, cv.dnn.ENGINE_NEW) + siglip_net = cv.dnn.readNetFromONNX(args.siglip, cv.dnn.ENGINE_OPENCV) + embed_net = cv.dnn.readNetFromONNX(args.embedding, cv.dnn.ENGINE_OPENCV) + gemma_net = cv.dnn.readNetFromONNX(args.gemma, cv.dnn.ENGINE_OPENCV) print(f"Prompt:\n{args.prompt}") pixel_values = preprocess_image(args.input) diff --git a/samples/python/color_correction_model.py b/samples/python/color_correction_model.py index 16453d7990..323be151af 100644 --- a/samples/python/color_correction_model.py +++ b/samples/python/color_correction_model.py @@ -122,7 +122,7 @@ def main(func_args=None): # Create color checker detector if args.model and args.config: # Load the DNN from TensorFlow model - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV net = cv.dnn.readNetFromTensorflow(args.model, args.config, engine) net.setPreferableBackend(get_backend_id(args.backend)) net.setPreferableTarget(get_target_id(args.target)) diff --git a/samples/python/macbeth_chart_detection.py b/samples/python/macbeth_chart_detection.py index 88a544bc5f..1bd8857272 100644 --- a/samples/python/macbeth_chart_detection.py +++ b/samples/python/macbeth_chart_detection.py @@ -89,7 +89,7 @@ def main(func_args=None): if args.model and args.config: # Load the DNN from TensorFlow model - engine = cv.dnn.ENGINE_NEW + engine = cv.dnn.ENGINE_OPENCV net = cv.dnn.readNetFromTensorflow(args.model, args.config, engine) net.setPreferableBackend(get_backend_id(args.backend)) net.setPreferableTarget(get_target_id(args.target))