diff --git a/modules/dnn/src/net_impl_backend.cpp b/modules/dnn/src/net_impl_backend.cpp index fc62cc991c..ed4a7e73db 100644 --- a/modules/dnn/src/net_impl_backend.cpp +++ b/modules/dnn/src/net_impl_backend.cpp @@ -190,7 +190,7 @@ void Net::Impl::setPreferableBackend(Net& net, int backendId) { if (mainGraph) { - CV_LOG_WARNING(NULL, "Back-ends are not supported by the new graph egine for now"); + CV_LOG_WARNING(NULL, "Back-ends are not supported by the new graph engine for now"); preferableBackend = backendId; return; } @@ -226,7 +226,7 @@ void Net::Impl::setPreferableTarget(int targetId) { if (mainGraph) { - CV_LOG_WARNING(NULL, "Targtes are not supported by the new graph egine for now"); + CV_LOG_WARNING(NULL, "Targets are not supported by the new graph engine for now"); return; } if (netWasQuantized && targetId != DNN_TARGET_CPU && diff --git a/samples/dnn/classification.cpp b/samples/dnn/classification.cpp index 6c074ee23a..35ff331206 100644 --- a/samples/dnn/classification.cpp +++ b/samples/dnn/classification.cpp @@ -143,7 +143,11 @@ int main(int argc, char** argv) } CV_Assert(!model.empty()); //! [Read and initialize network] - Net net = readNetFromONNX(model); + EngineType engine = ENGINE_AUTO; + if (backend != "default" || target != "cpu"){ + engine = ENGINE_CLASSIC; + } + Net net = readNetFromONNX(model, engine); net.setPreferableBackend(getBackendID(backend)); net.setPreferableTarget(getTargetID(target)); //! [Read and initialize network] diff --git a/samples/dnn/classification.py b/samples/dnn/classification.py index ea0b43fc75..4ab1126a31 100644 --- a/samples/dnn/classification.py +++ b/samples/dnn/classification.py @@ -82,9 +82,10 @@ def main(func_args=None): labels = f.read().rstrip('\n').split('\n') # Load a network - - net = cv.dnn.readNet(args.model) - + engine = cv.dnn.ENGINE_AUTO + if args.backend != "default" or args.target != "cpu": + engine = cv.dnn.ENGINE_CLASSIC + net = cv.dnn.readNetFromONNX(args.model, engine) net.setPreferableBackend(get_backend_id(args.backend)) net.setPreferableTarget(get_target_id(args.target)) diff --git a/samples/dnn/colorization.cpp b/samples/dnn/colorization.cpp index 5c46588e2f..745dde9473 100644 --- a/samples/dnn/colorization.cpp +++ b/samples/dnn/colorization.cpp @@ -83,7 +83,11 @@ int main(int argc, char** argv) { resize(imgL, imgLResized, Size(256, 256), 0, 0, INTER_CUBIC); // Prepare the model - dnn::Net net = dnn::readNetFromONNX(onnxModelPath); + EngineType engine = ENGINE_AUTO; + if (backendId != 0 || targetId != 0){ + engine = ENGINE_CLASSIC; + } + dnn::Net net = dnn::readNetFromONNX(onnxModelPath, engine); net.setPreferableBackend(backendId); net.setPreferableTarget(targetId); //! [Read and initialize network] diff --git a/samples/dnn/colorization.py b/samples/dnn/colorization.py index 0d7233acc7..ebe59d4e46 100644 --- a/samples/dnn/colorization.py +++ b/samples/dnn/colorization.py @@ -44,7 +44,10 @@ 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 - session = cv.dnn.readNetFromONNX(onnx_model_path) + engine = cv.dnn.ENGINE_AUTO + if args.backend != 0 or args.target != 0: + engine = cv.dnn.ENGINE_CLASSIC + session = cv.dnn.readNetFromONNX(onnx_model_path, engine) session.setPreferableBackend(args.backend) session.setPreferableTarget(args.target) diff --git a/samples/dnn/edge_detection.cpp b/samples/dnn/edge_detection.cpp index 2cd84a0b00..f1324d8c76 100644 --- a/samples/dnn/edge_detection.cpp +++ b/samples/dnn/edge_detection.cpp @@ -29,8 +29,8 @@ static void applyCanny(const Mat& image, Mat& result) { } // Load Model -static void loadModel(const string modelPath, String backend, String target, Net &net){ - net = readNetFromONNX(modelPath); +static void loadModel(const string modelPath, String backend, String target, Net &net, EngineType engine){ + net = readNetFromONNX(modelPath, engine); net.setPreferableBackend(getBackendID(backend)); net.setPreferableTarget(getTargetID(target)); } @@ -159,6 +159,10 @@ int main(int argc, char** argv) { string method = parser.get("method"); String sha1 = parser.get("sha1"); string model = findModel(parser.get("model"), sha1); + EngineType engine = ENGINE_AUTO; + if (backend != "default" || target != "cpu"){ + engine = ENGINE_CLASSIC; + } parser.about(about); VideoCapture cap; @@ -179,7 +183,7 @@ int main(int argc, char** argv) { } if (method == "dexined") { - loadModel(model, backend, target, net); + loadModel(model, backend, target, net, engine); } else{ Mat dummy = Mat::zeros(512, 512, CV_8UC3); @@ -218,7 +222,7 @@ int main(int argc, char** argv) { if (!model.empty()){ method = "dexined"; if (net.empty()) - loadModel(model, backend, target, net); + loadModel(model, backend, target, net, engine); destroyWindow("Output"); namedWindow("Input", WINDOW_AUTOSIZE); namedWindow("Output", WINDOW_AUTOSIZE); diff --git a/samples/dnn/edge_detection.py b/samples/dnn/edge_detection.py index ab8c35b207..c18ce3a6fe 100644 --- a/samples/dnn/edge_detection.py +++ b/samples/dnn/edge_detection.py @@ -92,8 +92,8 @@ def setupCannyWindow(image): cv.createTrackbar('thrs2', 'Output', threshold2, 255, lambda value: [globals().__setitem__('threshold2', value), apply_canny(gray)]) cv.createTrackbar('blur', 'Output', blur_amount, 20, lambda value: [globals().__setitem__('blur_amount', value), apply_canny(gray)]) -def loadModel(args): - net = cv.dnn.readNetFromONNX(args.model) +def loadModel(args, engine): + net = cv.dnn.readNetFromONNX(args.model, engine) net.setPreferableBackend(get_backend_id(args.backend)) net.setPreferableTarget(get_target_id(args.target)) return net @@ -109,6 +109,9 @@ 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 cap = cv.VideoCapture(cv.samples.findFile(args.input) if args.input else 0) if not cap.isOpened(): @@ -136,7 +139,7 @@ def main(func_args=None): setupCannyWindow(dummy) net = None if method == "dexined": - net = loadModel(args) + net = loadModel(args, engine) while cv.waitKey(1) < 0: hasFrame, image = cap.read() if not hasFrame: @@ -160,7 +163,7 @@ def main(func_args=None): print("model: ", args.model) method = "dexined" if net is None: - net = loadModel(args) + net = loadModel(args, engine) cv.destroyWindow('Output') cv.namedWindow('Output', cv.WINDOW_AUTOSIZE) cv.moveWindow('Output', 200, 50) diff --git a/samples/dnn/models.yml b/samples/dnn/models.yml index 23b79ce0d5..41fe7862b8 100644 --- a/samples/dnn/models.yml +++ b/samples/dnn/models.yml @@ -360,9 +360,9 @@ OCR: dexined: load_info: - url: "https://github.com/gursimarsingh/opencv_zoo/raw/dexined_model/models/edge_detection_dexined/dexined.onnx" + url: "https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/edge_detection_dexined/edge_detection_dexined_2024sep.onnx?download=" sha1: "f86f2d32c3cf892771f76b5e6b629b16a66510e9" - model: "dexined.onnx" + model: "edge_detection_dexined_2024sep.onnx" mean: [103.5, 116.2, 123.6] scale: 1.0 width: 512 diff --git a/samples/dnn/person_reid.py b/samples/dnn/person_reid.py index 4f63268e4f..8ea4345335 100644 --- a/samples/dnn/person_reid.py +++ b/samples/dnn/person_reid.py @@ -184,7 +184,8 @@ def main(): args.yolo_model = findModel(args.yolo_model, args.yolo_sha1) engine = cv.dnn.ENGINE_AUTO - if args.backend != "default" or args.backend != "cpu": + + if args.backend != "default" or args.target != "cpu": engine = cv.dnn.ENGINE_CLASSIC yolo_net = cv.dnn.readNetFromONNX(args.yolo_model, engine) reid_net = cv.dnn.readNetFromONNX(args.model, engine)