mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
moved to engine_opencv
This commit is contained in:
@@ -98,12 +98,12 @@ int main( int argc, const char** argv )
|
||||
std::string input4_name = argParser.get<std::string>("input4_name");
|
||||
std::string input4_shape = argParser.get<std::string>("input4_shape");
|
||||
|
||||
dnn::EngineType engine = dnn::ENGINE_NEW;
|
||||
dnn::EngineType engine = dnn::ENGINE_OPENCV;
|
||||
if (argParser.has("engine"))
|
||||
{
|
||||
std::string eng_name = argParser.get<std::string>("engine");
|
||||
if(eng_name == "new")
|
||||
engine = dnn::ENGINE_NEW;
|
||||
engine = dnn::ENGINE_OPENCV;
|
||||
else if(eng_name == "ort")
|
||||
engine = dnn::ENGINE_ORT;
|
||||
else
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <a href="https://www.tensorflow.org/">TensorFlow</a> 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<String>& extraOutputs = std::vector<String>());
|
||||
|
||||
/** @brief Reads a network model stored in <a href="https://www.tensorflow.org/">TensorFlow</a> framework's format.
|
||||
@@ -1112,7 +1113,7 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
*/
|
||||
CV_EXPORTS_W Net readNetFromTensorflow(const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig = std::vector<uchar>(),
|
||||
int engine=ENGINE_NEW,
|
||||
int engine=ENGINE_AUTO,
|
||||
const std::vector<String>& extraOutputs = std::vector<String>());
|
||||
|
||||
/** @brief Reads a network model stored in <a href="https://www.tensorflow.org/">TensorFlow</a> 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<String>& extraOutputs = std::vector<String>());
|
||||
|
||||
/** @brief Reads a network model stored in <a href="https://www.tensorflow.org/lite">TFLite</a> 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 <a href="https://www.tensorflow.org/lite">TFLite</a> 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<uchar>& bufferModel, int engine=ENGINE_NEW);
|
||||
CV_EXPORTS_W Net readNetFromTFLite(const std::vector<uchar>& bufferModel, int engine=ENGINE_AUTO);
|
||||
|
||||
/** @brief Reads a network model stored in <a href="https://www.tensorflow.org/lite">TFLite</a> 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<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig = std::vector<uchar>(),
|
||||
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 <a href="https://onnx.ai/">ONNX</a>.
|
||||
* @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 <a href="https://onnx.ai/">ONNX</a>
|
||||
* 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 <a href="https://onnx.ai/">ONNX</a>
|
||||
* 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<uchar>& buffer, int engine=ENGINE_NEW);
|
||||
CV_EXPORTS_W Net readNetFromONNX(const std::vector<uchar>& buffer, int engine=ENGINE_AUTO);
|
||||
|
||||
/** @brief Creates blob from .pb file.
|
||||
* @param path to the .pb file with input tensor.
|
||||
|
||||
@@ -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].
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<uchar>& 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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<float>(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
|
||||
|
||||
@@ -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<std::pair<int, float> > 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);
|
||||
|
||||
@@ -3758,7 +3758,7 @@ INSTANTIATE_TEST_CASE_P(/**/, Test_ONNX_nets, dnnBackendsAndTargets());
|
||||
TEST_P(Test_ONNX_layers, getUnconnectedOutLayers)
|
||||
{
|
||||
auto engine_forced = static_cast<cv::dnn::EngineType>(
|
||||
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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
|
||||
Ptr<CCheckerDetector> 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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -95,7 +95,7 @@ int main(int argc, char **argv)
|
||||
bool swapRB = parser.get<bool>("rgb");
|
||||
Scalar mean_v = parser.get<Scalar>("mean");
|
||||
|
||||
EngineType engine = ENGINE_NEW;
|
||||
EngineType engine = ENGINE_OPENCV;
|
||||
|
||||
Net net = readNetFromONNX(modelPath, engine);
|
||||
net.setPreferableBackend(getBackendID(backend));
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -159,7 +159,7 @@ int main(int argc, char** argv) {
|
||||
string method = parser.get<String>("method");
|
||||
String sha1 = parser.get<String>("sha1");
|
||||
string model = findModel(parser.get<String>("model"), sha1);
|
||||
EngineType engine = ENGINE_NEW;
|
||||
EngineType engine = ENGINE_OPENCV;
|
||||
parser.about(about);
|
||||
|
||||
VideoCapture cap;
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -129,7 +129,7 @@ int main(int argc, char **argv)
|
||||
|
||||
cout<<"Model loading..."<<endl;
|
||||
|
||||
EngineType engine = ENGINE_NEW;
|
||||
EngineType engine = ENGINE_OPENCV;
|
||||
|
||||
Net net = readNetFromONNX(modelPath, engine);
|
||||
net.setPreferableBackend(getBackendID(backend));
|
||||
|
||||
@@ -114,7 +114,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))
|
||||
|
||||
@@ -355,7 +355,7 @@ class DDIMInpainter(object):
|
||||
decoder_path = findModel(args.decoder_model, args.decoder_sha1)
|
||||
diffusor_path = findModel(args.diffusor_model, args.diffusor_sha1)
|
||||
|
||||
engine = cv.dnn.ENGINE_NEW
|
||||
engine = cv.dnn.ENGINE_OPENCV
|
||||
|
||||
self.encoder = cv.dnn.readNet(encoder_path, "", "", engine)
|
||||
self.diffusor = cv.dnn.readNet(diffusor_path, "", "", engine)
|
||||
|
||||
@@ -220,7 +220,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
//![read_net]
|
||||
EngineType engine = ENGINE_NEW;
|
||||
EngineType engine = ENGINE_OPENCV;
|
||||
Net net = readNet(modelPath, configPath, "", engine);
|
||||
int backend = getBackendID(parser.get<String>("backend"));
|
||||
net.setPreferableBackend(backend);
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user