1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #29341 from abhishek-gola/disable_engine_classic

Remove ENGINE CLASSIC, switching to ENGINE NEW as default engine
This commit is contained in:
Abhishek Gola
2026-07-29 13:00:29 +05:30
committed by GitHub
61 changed files with 311 additions and 4702 deletions
+6 -6
View File
@@ -53,7 +53,7 @@ std::string diagnosticKeys =
"{ model m | | Path to the model file. }"
"{ config c | | Path to the model configuration file. }"
"{ framework f | | [Optional] Name of the model framework. }"
"{ engine e | auto | [Optional] Graph negine selector: auto or classic or new}"
"{ engine e | auto | [Optional] DNN engine selector: auto (default), opencv or ort}"
"{ input0_name | | [Optional] Name of input0. Use with input0_shape}"
"{ input0_shape | | [Optional] Shape of input0. Use with input0_name}"
"{ input1_name | | [Optional] Name of input1. Use with input1_shape}"
@@ -104,13 +104,13 @@ int main( int argc, const char** argv )
std::string eng_name = argParser.get<std::string>("engine");
if(eng_name == "auto")
engine = dnn::ENGINE_AUTO;
else if(eng_name == "classic")
engine = dnn::ENGINE_CLASSIC;
else if(eng_name == "new")
engine = dnn::ENGINE_NEW;
else if(eng_name == "opencv")
engine = dnn::ENGINE_OPENCV;
else if(eng_name == "ort")
engine = dnn::ENGINE_ORT;
else
{
std::cerr << "Unknown DNN graph engine \"" << eng_name << "\"\n";
std::cerr << "Unknown DNN graph engine \"" << eng_name << "\" (use 'auto', 'opencv' or 'ort')\n";
return -1;
}
}
+1 -2
View File
@@ -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",
+24 -38
View File
@@ -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
@@ -1123,6 +1123,8 @@ CV__DNN_INLINE_NS_BEGIN
{
public:
static Ptr<Layer> create(const LayerParams& params);
// Set the per-channel slope when it arrives as a second input, not a blob.
virtual void setSlope(const Mat& /*slope*/) {}
};
class CV_EXPORTS ELULayer : public ActivationLayer
+15 -18
View File
@@ -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 layer name (classic engine) or 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,10 +1083,9 @@ CV__DNN_INLINE_NS_BEGIN
enum EngineType
{
ENGINE_CLASSIC=1, //!< Force use the old dnn engine similar to 4.x branch
ENGINE_NEW=2, //!< Force use the new dnn engine. The engine does not support non CPU back-ends for now.
ENGINE_AUTO=3, //!< Try to use the new engine and then fall back to the classic version.
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.
@@ -1094,7 +1093,7 @@ CV__DNN_INLINE_NS_BEGIN
* @param config path to the .pbtxt file that contains text graph definition in protobuf format.
* Resulting Net object is built by text graph using weights from a binary one that
* let us make it more flexible.
* @param engine select DNN engine to be used. With auto selection the new engine is used.
* @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV.
* @param extraOutputs specify model outputs explicitly, in addition to the outputs the graph analyzer finds.
* Please pay attention that the new DNN does not support non-CPU back-ends for now.
* @returns Net object.
@@ -1107,7 +1106,7 @@ CV__DNN_INLINE_NS_BEGIN
/** @brief Reads a network model stored in <a href="https://www.tensorflow.org/">TensorFlow</a> framework's format.
* @param bufferModel buffer containing the content of the pb file
* @param bufferConfig buffer containing the content of the pbtxt file
* @param engine select DNN engine to be used. With auto selection the new engine is used.
* @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV.
* @param extraOutputs specify model outputs explicitly, in addition to the outputs the graph analyzer finds.
* Please pay attention that the new DNN does not support non-CPU back-ends for now.
* @returns Net object.
@@ -1124,7 +1123,7 @@ CV__DNN_INLINE_NS_BEGIN
* @param lenModel length of bufferModel
* @param bufferConfig buffer containing the content of the pbtxt file
* @param lenConfig length of bufferConfig
* @param engine select DNN engine to be used. With auto selection the new engine is used.
* @param engine select DNN engine to be used. ENGINE_AUTO (the default) resolves to ENGINE_OPENCV.
* @param extraOutputs specify model outputs explicitly, in addition to the outputs the graph analyzer finds.
* Please pay attention that the new DNN does not support non-CPU back-ends for now.
*/
@@ -1135,7 +1134,7 @@ CV__DNN_INLINE_NS_BEGIN
/** @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. With auto selection the new engine is used first and falls back to classic.
* @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.
*/
@@ -1143,7 +1142,7 @@ CV__DNN_INLINE_NS_BEGIN
/** @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. With auto selection the new engine is used first and falls back to classic.
* @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.
*/
@@ -1154,7 +1153,7 @@ CV__DNN_INLINE_NS_BEGIN
* 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. With auto selection the new engine is used first and falls back to classic.
* @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_AUTO);
@@ -1171,9 +1170,8 @@ 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[in] engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic.
* @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.
* Use ENGINE_CLASSIC if you want to use other back-ends.
* @returns Net object.
*
* This function automatically detects an origin framework of trained model
@@ -1192,9 +1190,8 @@ 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. With auto selection the new engine is used first and falls back to classic.
* @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.
* Use ENGINE_CLASSIC if you want to use other back-ends.
* @returns Net object.
*/
CV_EXPORTS_W Net readNet(const String& framework, const std::vector<uchar>& bufferModel,
@@ -1237,7 +1234,7 @@ 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. With auto selection the new engine is used first and falls back to classic.
* @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.
*/
@@ -1247,7 +1244,7 @@ CV__DNN_INLINE_NS_BEGIN
* 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. With auto selection the new engine is used first and falls back to classic.
* @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.
*/
@@ -1256,7 +1253,7 @@ CV__DNN_INLINE_NS_BEGIN
/** @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. With auto selection the new engine is used first and falls back to classic.
* @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.
@@ -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_CLASSIC);
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].
+2 -2
View File
@@ -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_CLASSIC)
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_CLASSIC)
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
-6
View File
@@ -145,12 +145,6 @@ PERF_TEST_P_(DNNTestNetwork, SSD)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
// SSD_VGG16's specialized preprocessing is handled by the new engine importer only.
auto engine_forced = static_cast<dnn::EngineType>(
utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", dnn::ENGINE_AUTO));
if (engine_forced == dnn::ENGINE_CLASSIC)
throw SkipTestException("SSD_VGG16 is supported on the new DNN engine only");
processNet("dnn/onnx/models/ssd_vgg16.onnx", "", cv::Size(300, 300));
}
+5
View File
@@ -68,6 +68,7 @@ struct ConstArgs
Conv2Layer* conv = dynamic_cast<Conv2Layer*>(layer_ptr);
ConvTranspose2Layer* deconv = dynamic_cast<ConvTranspose2Layer*>(layer_ptr);
BatchNorm2Layer* bn = dynamic_cast<BatchNorm2Layer*>(layer_ptr);
ChannelsPReLULayer* prelu = dynamic_cast<ChannelsPReLULayer*>(layer_ptr);
//ActivationLayer* activ = dynamic_cast<ActivationLayer*>(layer_ptr);
if (tail_const) {
@@ -88,6 +89,10 @@ struct ConstArgs
} else if (bn && bn->freezeScaleBias()) {
// batch norm with constant parameters
unuse_tail = true;
} else if (prelu && ninputs == 2) {
prelu->setSlope(netimpl->__tensors__[inputs[1].idx]);
prelu->inputs.resize(1);
unuse_tail = true;
}/* else if (activ && dynamic_cast<ReLU6Layer>(activ)) {
// [TODO] ...
unuse_tail = true;
@@ -3742,6 +3742,14 @@ class ChannelsPReLUImpl CV_FINAL : public ElementWiseLayer<ChannelsPReLUFunctor>
public:
using ElementWiseLayer<ChannelsPReLUFunctor>::ElementWiseLayer;
void setSlope(const Mat& slope) CV_OVERRIDE
{
slope.reshape(1, (int)slope.total()).convertTo(func.scale, CV_32F);
#ifdef HAVE_OPENCL
func.scale_umat.release();
#endif
}
void forward(InputArrayOfArrays inputs_arr,
OutputArrayOfArrays outputs_arr,
OutputArrayOfArrays internals_arr) CV_OVERRIDE
@@ -3849,6 +3857,13 @@ private:
Ptr<Layer> ChannelsPReLULayer::create(const LayerParams& params)
{
if (params.blobs.empty())
{
// Slope comes as a second input; constArgs() fills the scale in later.
Ptr<ChannelsPReLUImpl> l(new ChannelsPReLUImpl(ChannelsPReLUFunctor()));
l->setParamsFrom(params);
return l;
}
CV_Assert(params.blobs.size() == 1);
Mat scale = params.blobs[0];
float slope = *scale.ptr<float>();
+21 -35
View File
@@ -254,45 +254,31 @@ class LSTM2LayerImpl CV_FINAL : public LSTM2Layer
batchSize = input[0].size[0];
}
// ONNX LSTM inputs: X(0), W(1), R(2), B(3), sequence_lens(4),
// initial_h(5), initial_c(6), P(7). Inputs 3..7 are optional and
// may be present-but-empty (e.g. CNTK exports keep all 8 slots with
// empties for unused ones). Gather by presence/non-emptiness rather
// than by the raw input count so optional/empty inputs are ignored.
auto hasInput = [&](int idx) {
return idx < numInputs && !input[idx].empty();
};
std::vector<Mat> blobs_;
int hidShape [] = {1 + static_cast<int>(bidirectional), batchSize, numHidden};
int biasShape [] = {1 + static_cast<int>(bidirectional), 8 * numHidden};
blobs_.push_back(input[1].clone());
blobs_.push_back(input[2].clone());
switch (numInputs) {
case 3:
// X, W, R are given
// create bias
blobs_.push_back(Mat::zeros(2, biasShape, input[0].type()));
// create h0, c0
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
break;
case 4:
// X, W, R, B are given
blobs_.push_back(input[3]);
// create h0, c0
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
blobs_.push_back(Mat::zeros(3, hidShape, input[0].type()));
break;
case 7:
// X, W, R, B, h0, c0 are given
blobs_.push_back(input[3]);
blobs_.push_back(input[5]);
blobs_.push_back(input[6]);
break;
case 8:
// X, W, R, B, seqlen, h0, c0, P are given
blobs_.push_back(input[3]);
blobs_.push_back(input[5]);
blobs_.push_back(input[6]);
blobs_.push_back(input[7]);
break;
default:
CV_Error(Error::StsNotImplemented, "Insufficient inputs for LSTM layer. "
"Required inputs: X, W, R, B, seqLen, h0, c0 [, P for peephole]");
}
CV_Assert(numInputs >= 3); // X, W, R are mandatory
blobs_.push_back(input[1].clone()); // W
blobs_.push_back(input[2].clone()); // R
// B
blobs_.push_back(hasInput(3) ? input[3] : Mat::zeros(2, biasShape, input[0].type()));
// initial_h
blobs_.push_back(hasInput(5) ? input[5] : Mat::zeros(3, hidShape, input[0].type()));
// initial_c
blobs_.push_back(hasInput(6) ? input[6] : Mat::zeros(3, hidShape, input[0].type()));
// P (peephole) - only when the layer was configured to use it and the input is present
if (usePeephole && hasInput(7))
blobs_.push_back(input[7]);
// set outputs to 0
for (auto& out : output)
+24 -7
View File
@@ -1196,7 +1196,18 @@ void Net::Impl::forward(std::vector<std::vector<Mat>>& outputBlobs,
FPDenormalsIgnoreHintScope fp_denormals_ignore_scope;
if (mainGraph)
CV_Error(Error::StsNotImplemented, "The new dnn engine doesn't support inference until a specified layer. If you want to run the whole model, please don't set the outputName argument in the forward() call. If you want to run the model until a specified layer, please use the old dnn engine");
{
// In the new engine every requested name maps to a single graph output tensor,
// so each nested list holds exactly one blob.
std::vector<std::string> names(outBlobNames.begin(), outBlobNames.end());
std::vector<Mat> flat;
forwardWithMultipleOutputs(flat, names);
CV_Assert(flat.size() == outBlobNames.size());
outputBlobs.resize(outBlobNames.size());
for (size_t i = 0; i < outBlobNames.size(); i++)
outputBlobs[i].assign(1, flat[i]);
return;
}
std::vector<LayerPin> pins;
for (int i = 0; i < outBlobNames.size(); i++)
@@ -1631,21 +1642,20 @@ void Net::Impl::setInput(InputArray blob, const String& name, double scalefactor
Mat Net::Impl::getParam(int layer, int numParam) const
{
LayerData& ld = getLayerData(layer);
std::vector<Mat>& layerBlobs = getLayerInstance(ld)->blobs;
std::vector<Mat>& layerBlobs = getLayer(layer)->blobs;
CV_Assert(numParam < (int)layerBlobs.size());
return layerBlobs[numParam];
}
void Net::Impl::setParam(int layer, int numParam, const Mat& blob)
{
LayerData& ld = getLayerData(layer);
// FIXIT we should not modify "execution" instance
std::vector<Mat>& layerBlobs = getLayerInstance(ld)->blobs;
std::vector<Mat>& layerBlobs = getLayer(layer)->blobs;
CV_Assert(numParam < (int)layerBlobs.size());
// we don't make strong checks, use this function carefully
layerBlobs[numParam] = blob;
if (mainGraph)
finalizeLayers = true;
}
void Net::Impl::setParam(const std::string& outputTensorName, int numParam, const Mat& blob)
@@ -1657,9 +1667,16 @@ void Net::Impl::setParam(const std::string& outputTensorName, int numParam, cons
if (excl != std::string::npos)
it = argnames.find(outputTensorName.substr(excl + 1));
}
if (it == argnames.end())
if (it == argnames.end()) {
// Not a tensor name; try it as a layer name.
int lid = getLayerId(outputTensorName);
if (lid >= 0) {
setParam(lid, numParam, blob);
return;
}
CV_Error_(Error::StsObjectNotFound,
("DNN: tensor '%s' not found in the graph", outputTensorName.c_str()));
}
int targetIdx = (int)it->second;
const std::vector<Ptr<Layer>>& prog = mainGraph->prog();
+43 -26
View File
@@ -689,6 +689,24 @@ void Net::Impl::forwardMainGraph(InputArrayOfArrays inputs, OutputArrayOfArrays
kvCacheManager.applyRoutes();
}
// Assign a single result to an output array, including a (pre-allocated) vector
// of Mat/UMat, which _OutputArray::assign(Mat) does not handle.
static void assignSingleOutput(OutputArrayOfArrays outputBlobs, const Mat& result)
{
_InputArray::KindFlag k = outputBlobs.kind();
if (k == _InputArray::STD_VECTOR_MAT) {
std::vector<Mat>& v = outputBlobs.getMatVecRef();
v.resize(1);
result.copyTo(v[0]);
} else if (k == _InputArray::STD_VECTOR_UMAT) {
std::vector<UMat>& v = outputBlobs.getUMatVecRef();
v.resize(1);
result.copyTo(v[0]);
} else {
outputBlobs.assign(result);
}
}
void Net::Impl::forwardWithSingleOutput(const std::string& outname, OutputArrayOfArrays outputBlobs)
{
#ifdef HAVE_ONNXRUNTIME
@@ -715,7 +733,7 @@ void Net::Impl::forwardWithSingleOutput(const std::string& outname, OutputArrayO
std::vector<int> outIdxs(1, outIdx);
std::vector<Mat> outs = runOrtSession(netInputLayer->blobs, outIdxs);
CV_Assert(outs.size() == 1);
outputBlobs.assign(outs[0]);
assignSingleOutput(outputBlobs, outs[0]);
return;
}
#endif
@@ -743,7 +761,7 @@ void Net::Impl::forwardWithSingleOutput(const std::string& outname, OutputArrayO
const std::vector<Arg>& gr_outputs = mainGraph->outputs();
for (size_t i = 0; i < gr_outputs.size(); i++) {
if (gr_outputs[i].idx == targetArg.idx) {
outputBlobs.assign(outs[i]);
assignSingleOutput(outputBlobs, outs[i]);
return;
}
}
@@ -760,9 +778,9 @@ void Net::Impl::forwardWithSingleOutput(const std::string& outname, OutputArrayO
if (result.shape().layout == DATA_LAYOUT_BLOCK) {
Mat converted;
transformLayout(result, converted, originalLayout, originalLayout, defaultC0);
outputBlobs.assign(converted);
assignSingleOutput(outputBlobs, converted);
} else {
outputBlobs.assign(result.clone());
assignSingleOutput(outputBlobs, result.clone());
}
return;
}
@@ -771,7 +789,7 @@ void Net::Impl::forwardWithSingleOutput(const std::string& outname, OutputArrayO
std::vector<Mat> inps, outs;
forwardMainGraph(inps, outs);
CV_Assert(!outs.empty());
outputBlobs.assign(outs[0]);
assignSingleOutput(outputBlobs, outs[0]);
}
void Net::Impl::forwardWithMultipleOutputs(OutputArrayOfArrays outblobs, const std::vector<std::string>& outnames)
@@ -848,45 +866,44 @@ void Net::Impl::forwardWithMultipleOutputs(OutputArrayOfArrays outblobs, const s
const std::vector<Arg>& outargs = mainGraph->outputs();
std::vector<int> outidxs;
int i, j, noutputs = (int)outargs.size();
if (!outnames.empty()) {
CV_CheckEQ((int)outnames.size(), noutputs, "the number of requested and actual outputs must be the same");
if (noutputs == 1 && outnames[0].empty())
;
else {
for (i = 0; i < noutputs; i++) {
const std::string& outname = outnames[i];
for (j = 0; j < noutputs; j++) {
const ArgData& adata = args.at(outargs[j].idx);
if (adata.name == outname) {
outidxs.push_back((int)j);
break;
}
}
if (j == noutputs) {
CV_Error_(Error::StsObjectNotFound, ("the required output '%s' is not found", outname.c_str()));
if (outnames.empty() || (noutputs == 1 && outnames.size() == 1 && outnames[0].empty())) {
for (i = 0; i < noutputs; i++)
outidxs.push_back(i);
} else {
for (i = 0; i < (int)outnames.size(); i++) {
const std::string& outname = outnames[i];
for (j = 0; j < noutputs; j++) {
const ArgData& adata = args.at(outargs[j].idx);
if (adata.name == outname) {
outidxs.push_back((int)j);
break;
}
}
if (j == noutputs) {
CV_Error_(Error::StsObjectNotFound, ("the required output '%s' is not found", outname.c_str()));
}
}
}
std::vector<Mat> inps={}, outs;
forwardMainGraph(inps, outs);
CV_Assert(outs.size() == noutputs);
int nout = (int)outidxs.size();
std::vector<Mat>* outMats = nullptr;
std::vector<UMat>* outUMats = nullptr;
_InputArray::KindFlag outKind = outblobs.kind();
if (outKind == _InputArray::STD_VECTOR_MAT) {
outMats = &outblobs.getMatVecRef();
outMats->resize(noutputs);
outMats->resize(nout);
} else if (outKind == _InputArray::STD_VECTOR_UMAT) {
outUMats = &outblobs.getUMatVecRef();
outUMats->resize(noutputs);
outUMats->resize(nout);
} else if (outKind == _InputArray::MAT || outKind == _InputArray::UMAT) {
CV_Assert(noutputs == 1);
CV_Assert(nout == 1);
} else {
CV_Error(Error::StsBadArg, "outputs must be Mat, UMat, a vector of Mat's or a vector of UMat's");
}
for (i = 0; i < noutputs; i++) {
int j = outidxs.empty() ? i : outidxs[i];
for (i = 0; i < nout; i++) {
int j = outidxs[i];
Mat src = outs[j];
if (outMats) {
src.copyTo(outMats->at(i));
File diff suppressed because it is too large Load Diff
+15 -20
View File
@@ -722,7 +722,7 @@ Net ONNXImporter2::parseModel()
sstrm << "DNN/ONNX: the model ";
if (!onnxFilename.empty())
sstrm << "'" << onnxFilename << "' ";
sstrm << "cannot be loaded with the new parser. Trying the older parser. ";
sstrm << "cannot be loaded by the DNN engine.";
if (!missing_ops.empty()) {
sstrm << " Unsupported operations:\n";
auto it = missing_ops.begin();
@@ -777,21 +777,6 @@ bool ONNXImporter2::parseValueInfo(const opencv_onnx::ValueInfoProto& valueInfoP
} else {
// ONNX allows dimensions without dim_value and dim_param.
// Treat them as unnamed symbolic dimensions.
// NOTE: LSTM with unnamed dimensions is not ready in the new graph
// engine yet, so force fallback to classic parser.
if (curr_graph_proto)
{
const int n_nodes = curr_graph_proto->node_size();
for (int i = 0; i < n_nodes; ++i)
{
const std::string& op = curr_graph_proto->node(i).op_type();
if (op == "LSTM")
{
raiseError();
return false;
}
}
}
val_j = net.findDim("", true);
}
//CV_Assert(0 <= val_j && val_j <= INT_MAX);
@@ -1363,7 +1348,9 @@ void ONNXImporter2::parseLSTM(LayerParams& layerParams, const opencv_onnx::NodeP
layerParams.set("produce_sequence_y", need_y);
if (lstm_proto.input_size() == 8)
// The 8th input (P, peephole weights) is optional; an absent ONNX input is
// encoded as an empty name. Only enable peephole when it is actually present.
if (lstm_proto.input_size() == 8 && !lstm_proto.input(7).empty())
layerParams.set("use_peephole", true);
@@ -1471,9 +1458,17 @@ void ONNXImporter2::parsePRelu(LayerParams& layerParams, const opencv_onnx::Node
{
layerParams.type = "PReLU";
CV_Assert(node_inputs.size() == 2);
CV_Assert(net.isConstArg(node_inputs[1]));
layerParams.blobs.push_back(net.argTensor(node_inputs[1]));
addLayer(layerParams, node_proto, 1);
if (net.isConstArg(node_inputs[1]))
{
layerParams.blobs.push_back(net.argTensor(node_inputs[1]));
addLayer(layerParams, node_proto, 1);
}
else
{
// Slope produced by a foldable subgraph (e.g. Reshape of an initializer):
// keep it as a second input for constFold()/constArgs() to resolve.
addLayer(layerParams, node_proto);
}
}
void ONNXImporter2::parseLpNormalization(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
+18 -42
View File
@@ -3263,31 +3263,24 @@ void TFLayerHandler::handleFailed(const tensorflow::NodeDef& layer)
} // namespace
// 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_AUTO);
if (engine_forced == ENGINE_OPENCV)
engine = engine_forced;
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,
const std::vector<String>& extraOutputs)
{
static const int engine_forced = utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO);
if(engine_forced != ENGINE_AUTO)
engine = engine_forced;
if (engine == ENGINE_AUTO)
{
try
{
return detail::readNetDiagnostic<TFImporter>(model.c_str(), config.c_str(),
true, extraOutputs);
}
catch(const std::exception& e)
{
CV_LOG_WARNING(NULL, "Can't parse model with the new dnn engine, trying to parse with the old dnn engine: " << e.what());
return detail::readNetDiagnostic<TFImporter>(model.c_str(), config.c_str(),
false, extraOutputs);
}
}
else
{
return detail::readNetDiagnostic<TFImporter>(model.c_str(), config.c_str(), engine == ENGINE_NEW || engine == ENGINE_AUTO, extraOutputs);
}
warnIfUnsupportedTfEngine(engine);
return detail::readNetDiagnostic<TFImporter>(model.c_str(), config.c_str(),
/*newEngine*/ true, extraOutputs);
}
Net readNetFromTensorflow(const char* bufferModel, size_t lenModel,
@@ -3295,26 +3288,9 @@ Net readNetFromTensorflow(const char* bufferModel, size_t lenModel,
int engine,
const std::vector<String>& extraOutputs)
{
static const int engine_forced = utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO);
if(engine_forced != ENGINE_AUTO)
engine = engine_forced;
if (engine == ENGINE_AUTO)
{
try
{
return detail::readNetDiagnostic<TFImporter>(bufferModel, lenModel, bufferConfig, lenConfig, true, extraOutputs);
}
catch(const std::exception& e)
{
CV_LOG_WARNING(NULL, "Can't parse model with the new dnn engine, trying to parse with the old dnn engine: " << e.what());
return detail::readNetDiagnostic<TFImporter>(bufferModel, lenModel, bufferConfig, lenConfig, false, extraOutputs);
}
}
else
{
return detail::readNetDiagnostic<TFImporter>(bufferModel, lenModel, bufferConfig, lenConfig, engine == ENGINE_NEW || engine == ENGINE_AUTO, extraOutputs);
}
warnIfUnsupportedTfEngine(engine);
return detail::readNetDiagnostic<TFImporter>(bufferModel, lenModel, bufferConfig, lenConfig,
/*newEngine*/ true, extraOutputs);
}
Net readNetFromTensorflow(const std::vector<uchar>& bufferModel, const std::vector<uchar>& bufferConfig, int engine,
+16 -8
View File
@@ -1503,10 +1503,20 @@ void TFLiteImporter::getQuantParams(const Operator& op, float& inpScale, int& in
}
}
Net readNetFromTFLite(const String &modelPath, int engine) {
static const int engine_forced = utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO);
if(engine_forced != ENGINE_AUTO)
// 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_AUTO);
if (engine_forced == ENGINE_OPENCV)
engine = engine_forced;
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) {
warnIfUnsupportedTFLiteEngine(engine);
Net net;
@@ -1526,7 +1536,7 @@ Net readNetFromTFLite(const String &modelPath, int engine) {
ifs.read(content.data(), sz);
CV_Assert(!ifs.bad());
TFLiteImporter(net, content.data(), content.size(), engine == ENGINE_NEW || engine == ENGINE_AUTO);
TFLiteImporter(net, content.data(), content.size(), /*newEngine*/ true);
return net;
}
@@ -1535,12 +1545,10 @@ Net readNetFromTFLite(const std::vector<uchar>& bufferModel, int engine) {
}
Net readNetFromTFLite(const char *bufferModel, size_t bufSize, int engine) {
static const int engine_forced = utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO);
if(engine_forced != ENGINE_AUTO)
engine = engine_forced;
warnIfUnsupportedTFLiteEngine(engine);
Net net;
TFLiteImporter(net, bufferModel, bufSize, engine == ENGINE_NEW || engine == ENGINE_AUTO);
TFLiteImporter(net, bufferModel, bufSize, /*newEngine*/ true);
return net;
}
-7
View File
@@ -269,13 +269,6 @@ TEST_P(DNNTestNetwork, SSD_VGG16)
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
Mat sample = imread(findDataFile("dnn/street.png"));
Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
-11
View File
@@ -90,17 +90,6 @@ TEST(Reproducibility_SSD, Accuracy)
CV_TEST_TAG_DEBUG_VERYLONG
);
// The classic engine importer no longer carries the Caffe-SSD specific
// handling (LpNormalization/DetectionOutput); this model is supported on
// the new engine only.
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
Net net = readNetFromONNX(findDataFile("dnn/onnx/models/ssd_vgg16.onnx", false));
ASSERT_FALSE(net.empty());
net.setPreferableBackend(DNN_BACKEND_OPENCV);
@@ -55,13 +55,6 @@ static std::string _tf(TString filename)
TEST(Test_YOLO, read_yolov4_onnx)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
Net net = readNet(findDataFile("dnn/yolov4.onnx", false));
ASSERT_FALSE(net.empty());
}
@@ -78,14 +71,6 @@ public:
float nmsThreshold = 0.4, bool useWinograd = true,
int zeroPadW = 0, Size inputSize = Size())
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
checkBackend();
Mat img1 = imread(_tf("dog416.png"));
+1 -3
View File
@@ -153,9 +153,7 @@ TEST_F(Test_Graph_Simplifier, BiasedMatMulSubgraph) {
/* Test for 1 subgraphs
- BiasedMatMulSubgraph
*/
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
const std::string expected = engine_forced == cv::dnn::ENGINE_CLASSIC ? "MatMul" : "Gemm";
const std::string expected = "Gemm";
test("biased_matmul", expected);
}
+6 -50
View File
@@ -2249,21 +2249,10 @@ TEST(Layer_LSTM, repeatedInference)
TEST(Layer_If, resize)
{
// Skip this test when the classic DNN engine is explicitly requested. The
// "if" layer is supported only by the new engine.
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
// Mark the test as skipped and exit early.
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
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);
@@ -2286,16 +2275,8 @@ TEST(Layer_If, resize)
TEST(Layer_If, subgraph_name_scoping)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
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);
@@ -2331,16 +2312,8 @@ TEST(Layer_If, subgraph_name_scoping)
TEST(Layer_Size, onnx_1d)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
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);
@@ -2358,16 +2331,8 @@ TEST(Layer_Size, onnx_1d)
TEST(Layer_Size, onnx_0d_scalar)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
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;
@@ -2430,20 +2395,11 @@ class TESTKVCache : public testing::TestWithParam<std::string>
public:
void testKVCache(const std::string& layout)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
// Mark the test as skipped and exit early.
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
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
+2 -40
View File
@@ -798,13 +798,6 @@ TEST_P(Reproducibility_ViT_ONNX, Accuracy)
Target targetId = GetParam();
applyTestTag(targetId == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB);
ASSERT_TRUE(ocl::useOpenCL() || targetId == DNN_TARGET_CPU || targetId == DNN_TARGET_CPU_FP16);
auto engine_forced = static_cast<EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO));
if (engine_forced == ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
std::string modelname = _tf("vit_base_patch16_224_Opset16.onnx", false);
Net net = readNetFromONNX(modelname);
@@ -832,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}
};
@@ -859,13 +852,6 @@ TEST_P(Reproducibility_BERT_ONNX, Accuracy)
Target targetId = GetParam();
ASSERT_TRUE(ocl::useOpenCL() || targetId == DNN_TARGET_CPU || targetId == DNN_TARGET_CPU_FP16);
auto engine_forced = static_cast<EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO));
if (engine_forced == ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
std::string modelname = _tf("onnx/models/bert.onnx", false);
Net net = readNetFromONNX(modelname);
@@ -931,14 +917,6 @@ typedef testing::TestWithParam<Target> Reproducibility_MobileNetSSD_ONNX;
TEST_P(Reproducibility_MobileNetSSD_ONNX, Accuracy)
{
Target targetId = GetParam();
auto engine_forced = static_cast<EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO));
if (engine_forced == ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
applyTestTag(targetId == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
ASSERT_TRUE(ocl::useOpenCL() || targetId == DNN_TARGET_CPU || targetId == DNN_TARGET_CPU_FP16);
@@ -1265,14 +1243,6 @@ INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_YOLOXS_ONNX,
typedef testing::TestWithParam<Target> Reproducibility_BlazeFace_ONNX;
TEST_P(Reproducibility_BlazeFace_ONNX, Accuracy)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
Target targetId = GetParam();
applyTestTag(targetId == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
ASSERT_TRUE(ocl::useOpenCL() || targetId == DNN_TARGET_CPU || targetId == DNN_TARGET_CPU_FP16);
@@ -1381,16 +1351,8 @@ TEST_P(Reproducibility_SwinIR_ONNX, Accuracy)
Target targetId = GetParam();
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_LONG);
auto engine_forced = static_cast<EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO));
if (engine_forced == ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
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);
-7
View File
@@ -109,13 +109,6 @@ TEST(SoftNMS, Accuracy)
// NMS with dynamic output shapes is only supported by the new engine.
TEST(NMS, ZeroDetections_Reshape)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
std::string onnxmodel = findDataFile("dnn/onnx/models/nms_reshape_empty.onnx");
cv::dnn::Net net = cv::dnn::readNetFromONNX(onnxmodel);
@@ -1937,18 +1937,6 @@ public:
#include "test_onnx_conformance_layer_filter_opencv_ocl_fp32_denylist.inl.hpp"
};
EngineType engine_forced =
(EngineType)utils::getConfigurationParameterSizeT(
"OPENCV_FORCE_DNN_ENGINE", ENGINE_AUTO);
if (engine_forced == ENGINE_CLASSIC) {
classic_deny_list = {
#include "test_onnx_conformance_layer_filter_opencv_classic_denylist.inl.hpp"
};
} else {
classic_deny_list = {};
}
#ifdef HAVE_HALIDE
halide_deny_list = {
#include "test_onnx_conformance_layer_filter__halide_denylist.inl.hpp"
-16
View File
@@ -217,14 +217,6 @@ public:
// output against an in-test attention reference computed from the same inputs.
void testSDPAModel(const String& basename, double l1, double lInf)
{
// SDPA is only handled by the new-engine ONNX importer.
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC) {
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
Mat Q = blobFromNPY(_tf("data/input_" + basename + "_0.npy"));
Mat KT = blobFromNPY(_tf("data/input_" + basename + "_1.npy"));
Mat V = blobFromNPY(_tf("data/input_" + basename + "_2.npy"));
@@ -2323,14 +2315,6 @@ TEST_P(Test_ONNX_layers, Gemm_External_Data)
TEST_P(Test_ONNX_layers, Quantized_MatMul_Variable_Weights)
{
auto engine_forced = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
{
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
return;
}
testONNXModels("quantized_matmul_variable_inputs", npy, 1.3, 1.3);
}
+1 -1
View File
@@ -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_AUTO, 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
};
+1 -1
View File
@@ -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
@@ -8,22 +8,12 @@
#ifdef HAVE_OPENCV_DNN
#include "opencv2/dnn.hpp"
#include "opencv2/core/utils/configuration.private.hpp"
namespace opencv_test { namespace {
static void skipIfClassicDnnEngine()
{
const auto engine = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine == cv::dnn::ENGINE_CLASSIC)
throw SkipTestException("ALIKED/LightGlue reference outputs are generated with the new DNN engine");
}
TEST(Features2d_ALIKED, Regression)
{
applyTestTag( CV_TEST_TAG_MEMORY_2GB);
skipIfClassicDnnEngine();
const std::string modelPath = cvtest::findDataFile("dnn/onnx/models/aliked-n16rot-top1k-640.onnx", false);
@@ -88,7 +78,6 @@ TEST(Features2d_ALIKED, Regression)
TEST(Features2d_LightGlue, Regression)
{
applyTestTag( CV_TEST_TAG_MEMORY_2GB);
skipIfClassicDnnEngine();
const std::string alikedPath = cvtest::findDataFile("dnn/onnx/models/aliked-n16rot-top1k-640.onnx", false);
const std::string lgPath = cvtest::findDataFile("dnn/onnx/models/aliked_lightglue.onnx", false);
-12
View File
@@ -14,17 +14,8 @@
namespace opencv_test { namespace {
static void skipIfClassicDnnEngine()
{
const auto engine = static_cast<cv::dnn::EngineType>(
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
if (engine == cv::dnn::ENGINE_CLASSIC)
throw SkipTestException("DISK ONNX model is not supported by the classic DNN engine");
}
static void testDiskRegression(const Size& imageSize, const std::string& tag)
{
skipIfClassicDnnEngine();
applyTestTag(CV_TEST_TAG_MEMORY_2GB);
Mat refKpts = blobFromNPY(cvtest::findDataFile("features/disk/box_in_scene_" + tag + "_kpts.npy"));
@@ -84,7 +75,6 @@ TEST(Features2d_DISK, regression_512x384)
TEST(Features2d_DISK, MaxKeypointsAndThreshold)
{
skipIfClassicDnnEngine();
applyTestTag(CV_TEST_TAG_MEMORY_2GB);
const std::string modelPath = cvtest::findDataFile("dnn/disk.onnx", false);
@@ -124,7 +114,6 @@ TEST(Features2d_DISK, MaxKeypointsAndThreshold)
TEST(Features2d_DISK, MaskSupport)
{
skipIfClassicDnnEngine();
applyTestTag(CV_TEST_TAG_MEMORY_2GB);
const std::string modelPath = cvtest::findDataFile("dnn/disk.onnx", false);
@@ -153,7 +142,6 @@ TEST(Features2d_DISK, MaskSupport)
TEST(Features2d_DISK, InvalidImageSize)
{
skipIfClassicDnnEngine();
const std::string modelPath = cvtest::findDataFile("dnn/disk.onnx", false);
EXPECT_THROW(DISK::create(modelPath, -1, 0.0f, Size(1000, 1024)), cv::Exception);
+2 -6
View File
@@ -88,12 +88,8 @@ class TrackerNanoImpl : public TrackerNano
public:
TrackerNanoImpl(const TrackerNano::Params& parameters)
{
dnn::EngineType engine = dnn::ENGINE_AUTO;
if (parameters.backend != 0 || parameters.target != 0){
engine = dnn::ENGINE_CLASSIC;
}
backbone = dnn::readNet(parameters.backbone, "", "", engine);
neckhead = dnn::readNet(parameters.neckhead, "", "", engine);
backbone = dnn::readNet(parameters.backbone);
neckhead = dnn::readNet(parameters.neckhead);
CV_Assert(!backbone.empty());
CV_Assert(!neckhead.empty());
+1 -5
View File
@@ -43,11 +43,7 @@ class TrackerVitImpl : public TrackerVit
public:
TrackerVitImpl(const TrackerVit::Params& parameters)
{
dnn::EngineType engine = dnn::ENGINE_AUTO;
if (parameters.backend != 0 || parameters.target != 0){
engine = dnn::ENGINE_CLASSIC;
}
net = dnn::readNet(parameters.net, "", "", engine);
net = dnn::readNet(parameters.net);
CV_Assert(!net.empty());
net.setPreferableBackend(parameters.backend);
+1 -4
View File
@@ -135,10 +135,7 @@ int main(int argc, char *argv[])
Ptr<CCheckerDetector> detector;
#ifdef HAVE_OPENCV_DNN
if (model_path != "" && pbtxt_path != ""){
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net net = readNetFromTensorflow(model_path, pbtxt_path, engine);
net.setPreferableBackend(getBackendID(backend));
net.setPreferableTarget(getTargetID(target));
+1 -5
View File
@@ -165,11 +165,7 @@ int main(int argc, char **argv)
parser.about(about);
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu")
{
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net net;
loadModel(model, backend, target, net, engine);
+1 -3
View File
@@ -140,9 +140,7 @@ def apply_modnet(args, model, image):
def main(func_args=None):
args = get_args_parser(func_args)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_OPENCV
image = cv.imread(cv.samples.findFile(args.input))
if image is None:
+1 -4
View File
@@ -146,10 +146,7 @@ int main(int argc, char** argv)
}
CV_Assert(!model.empty());
//! [Read and initialize network]
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net net = readNetFromONNX(model, engine);
net.setPreferableBackend(getBackendID(backend));
net.setPreferableTarget(getTargetID(target));
+1 -3
View File
@@ -83,9 +83,7 @@ def main(func_args=None):
labels = f.read().rstrip('\n').split('\n')
# Load a network
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
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))
+1 -4
View File
@@ -83,10 +83,7 @@ int main(int argc, char** argv) {
resize(imgL, imgLResized, Size(256, 256), 0, 0, INTER_CUBIC);
// Prepare the model
EngineType engine = ENGINE_AUTO;
if (backendId != 0 || targetId != 0){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
dnn::Net net = dnn::readNetFromONNX(onnxModelPath, engine);
net.setPreferableBackend(backendId);
net.setPreferableTarget(targetId);
+1 -3
View File
@@ -44,9 +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_AUTO
if args.backend != 0 or args.target != 0:
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_OPENCV
session = cv.dnn.readNetFromONNX(onnx_model_path, engine)
session.setPreferableBackend(args.backend)
session.setPreferableTarget(args.target)
+1 -4
View File
@@ -95,10 +95,7 @@ int main(int argc, char **argv)
bool swapRB = parser.get<bool>("rgb");
Scalar mean_v = parser.get<Scalar>("mean");
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net net = readNetFromONNX(modelPath, engine);
net.setPreferableBackend(getBackendID(backend));
+1 -4
View File
@@ -83,10 +83,7 @@ def main():
args.model = findModel(args.model, args.sha1)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_OPENCV
net = cv.dnn.readNetFromONNX(args.model, engine)
net.setPreferableBackend(get_backend_id(args.backend))
+1 -4
View File
@@ -159,10 +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_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
parser.about(about);
VideoCapture cap;
+1 -3
View File
@@ -110,9 +110,7 @@ def apply_dexined(model, image):
def main(func_args=None):
args = get_args_parser(func_args)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_OPENCV
cap = cv.VideoCapture(cv.samples.findFile(args.input) if args.input else 0)
if not cap.isOpened():
+1 -1
View File
@@ -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}")
+1 -1
View File
@@ -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)
+1 -4
View File
@@ -129,10 +129,7 @@ int main(int argc, char **argv)
cout<<"Model loading..."<<endl;
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net net = readNetFromONNX(modelPath, engine);
net.setPreferableBackend(getBackendID(backend));
+1 -4
View File
@@ -114,10 +114,7 @@ def main():
args.model = findModel(args.model, args.sha1)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_OPENCV
net = cv.dnn.readNetFromONNX(args.model, engine)
net.setPreferableBackend(get_backend_id(args.backend))
+1 -3
View File
@@ -355,9 +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_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
engine = cv.dnn.ENGINE_OPENCV
self.encoder = cv.dnn.readNet(encoder_path, "", "", engine)
self.diffusor = cv.dnn.readNet(diffusor_path, "", "", engine)
+1 -4
View File
@@ -220,10 +220,7 @@ int main(int argc, char** argv)
}
}
//![read_net]
EngineType engine = ENGINE_AUTO;
if ((parser.get<String>("backend") != "default") || (parser.get<String>("target") != "cpu")){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net net = readNet(modelPath, configPath, "", engine);
int backend = getBackendID(parser.get<String>("backend"));
net.setPreferableBackend(backend);
+1 -3
View File
@@ -99,9 +99,7 @@ if args.labels:
labels = f.read().rstrip('\n').split('\n')
# Load a network
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
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))
+1 -4
View File
@@ -258,10 +258,7 @@ int main(int argc, char **argv)
int fontSize = 50;
int fontWeight = 500;
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net reidNet = readNetFromONNX(modelPath, engine);
reidNet.setPreferableBackend(getBackendID(backend));
reidNet.setPreferableTarget(getTargetID(target));
+1 -4
View File
@@ -183,10 +183,7 @@ def main():
else:
args.yolo_model = findModel(args.yolo_model, args.yolo_sha1)
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
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))
+1 -1
View File
@@ -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}")
+1 -4
View File
@@ -214,10 +214,7 @@ int main(int argc, char **argv)
CV_Assert(!model.empty());
//! [Read and initialize network]
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
EngineType engine = ENGINE_OPENCV;
Net net = readNetFromONNX(model, engine);
net.setPreferableBackend(getBackendID(backend));
net.setPreferableTarget(getTargetID(target));
+1 -3
View File
@@ -100,9 +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_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
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))
+3 -3
View File
@@ -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)
+1 -3
View File
@@ -122,9 +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_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
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))
+1 -3
View File
@@ -89,9 +89,7 @@ def main(func_args=None):
if args.model and args.config:
# Load the DNN from TensorFlow model
engine = cv.dnn.ENGINE_AUTO
if args.backend != "default" or args.target != "cpu":
engine = cv.dnn.ENGINE_CLASSIC
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))
+1 -1
View File
@@ -234,7 +234,7 @@ int main(int argc, char** argv)
ALIKED::Params detParams;
detParams.inputSize = Size(640, 640);
detParams.engine = dnn::ENGINE_NEW;
detParams.engine = dnn::ENGINE_OPENCV;
detParams.backend = backendId;
detParams.target = targetId;
auto detector = ALIKED::create(alikedPath, detParams);
+1 -1
View File
@@ -112,7 +112,7 @@ def main():
det_params = cv.ALIKED.Params()
det_params.inputSize = (640, 640)
det_params.engine = cv.dnn.ENGINE_NEW
det_params.engine = cv.dnn.ENGINE_OPENCV
detector = cv.ALIKED.create(args.aliked, det_params)
matcher = cv.LightGlueMatcher.create(