From 5af1571073e2ea5ccfd29637286a242f71edaf27 Mon Sep 17 00:00:00 2001
From: Prasad Ayush Kumar <22bcs191@iiitdmj.ac.in>
Date: Thu, 30 Apr 2026 14:43:11 +0530
Subject: [PATCH] Darknet cleanup
---
modules/dnn/CMakeLists.txt | 2 +-
modules/dnn/include/opencv2/dnn/dnn.hpp | 32 +-
modules/dnn/misc/js/gen_dict.json | 2 +-
modules/dnn/misc/objc/gen_dict.json | 2 -
modules/dnn/perf/perf_net.cpp | 8 +-
modules/dnn/src/darknet/darknet_importer.cpp | 258 ----
modules/dnn/src/darknet/darknet_io.cpp | 1107 ------------------
modules/dnn/src/darknet/darknet_io.hpp | 117 --
modules/dnn/src/dnn_read.cpp | 4 +-
modules/dnn/test/test_common.hpp | 18 +
modules/dnn/test/test_darknet_importer.cpp | 1078 ++++-------------
modules/dnn/test/test_int8_layers.cpp | 111 +-
modules/dnn/test/test_misc.cpp | 3 -
modules/dnn/test/test_model.cpp | 123 --
platforms/js/opencv_js.config.py | 2 +-
15 files changed, 255 insertions(+), 2612 deletions(-)
delete mode 100644 modules/dnn/src/darknet/darknet_importer.cpp
delete mode 100644 modules/dnn/src/darknet/darknet_io.cpp
delete mode 100644 modules/dnn/src/darknet/darknet_io.hpp
diff --git a/modules/dnn/CMakeLists.txt b/modules/dnn/CMakeLists.txt
index 76f4515f9a..dbe3d5e04c 100644
--- a/modules/dnn/CMakeLists.txt
+++ b/modules/dnn/CMakeLists.txt
@@ -504,7 +504,7 @@ set(dnn_plugin_srcs ${dnn_srcs} ${dnn_int_hdrs})
ocv_list_filterout_ex(dnn_plugin_srcs
"/src/dnn.cpp$|/src/dnn_utils.cpp$|/src/dnn_read.cpp$|/src/registry.cpp$|/src/backend.cpp$"
# importers
- "/src/(caffe|darknet|onnx|tensorflow)/"
+ "/src/(caffe|onnx|tensorflow)/"
# executors
"/src/(cuda|cuda4dnn|ocl4dnn|vkcom|webnn)/"
)
diff --git a/modules/dnn/include/opencv2/dnn/dnn.hpp b/modules/dnn/include/opencv2/dnn/dnn.hpp
index bac8032481..9f7a515f7a 100644
--- a/modules/dnn/include/opencv2/dnn/dnn.hpp
+++ b/modules/dnn/include/opencv2/dnn/dnn.hpp
@@ -1066,31 +1066,6 @@ CV__DNN_INLINE_NS_BEGIN
ENGINE_ORT=4 //!< Try to use ONNX Runtime wrapper (ONNX only, requires build with WITH_ONNXRUNTIME=ON).
};
- /** @brief Reads a network model stored in Darknet model files.
- * @param cfgFile path to the .cfg file with text description of the network architecture.
- * @param darknetModel path to the .weights file with learned network.
- * @returns Network object that ready to do forward, throw an exception in failure cases.
- */
- CV_EXPORTS_W Net readNetFromDarknet(CV_WRAP_FILE_PATH const String &cfgFile, CV_WRAP_FILE_PATH const String &darknetModel = String());
-
- /** @brief Reads a network model stored in Darknet model files.
- * @param bufferCfg A buffer contains a content of .cfg file with text description of the network architecture.
- * @param bufferModel A buffer contains a content of .weights file with learned network.
- * @returns Net object.
- */
- CV_EXPORTS_W Net readNetFromDarknet(const std::vector& bufferCfg,
- const std::vector& bufferModel = std::vector());
-
- /** @brief Reads a network model stored in Darknet model files.
- * @param bufferCfg A buffer contains a content of .cfg file with text description of the network architecture.
- * @param lenCfg Number of bytes to read from bufferCfg
- * @param bufferModel A buffer contains a content of .weights file with learned network.
- * @param lenModel Number of bytes to read from bufferModel
- * @returns Net object.
- */
- CV_EXPORTS Net readNetFromDarknet(const char *bufferCfg, size_t lenCfg,
- const char *bufferModel = NULL, size_t lenModel = 0);
-
/** @brief Reads a network model stored in Caffe framework's format.
* @param prototxt path to the .prototxt file with text description of the network architecture.
* @param caffeModel path to the .caffemodel file with learned network.
@@ -1204,14 +1179,12 @@ CV__DNN_INLINE_NS_BEGIN
* extensions are expected for models from different frameworks:
* * `*.caffemodel` (Caffe, http://caffe.berkeleyvision.org/)
* * `*.pb` (TensorFlow, https://www.tensorflow.org/)
- * * `*.weights` (Darknet, https://pjreddie.com/darknet/)
* * `*.bin` | `*.onnx` (OpenVINO, https://software.intel.com/openvino-toolkit)
* * `*.onnx` (ONNX, https://onnx.ai/)
* @param[in] config Text file contains network configuration. It could be a
* file with the following extensions:
* * `*.prototxt` (Caffe, http://caffe.berkeleyvision.org/)
* * `*.pbtxt` (TensorFlow, https://www.tensorflow.org/)
- * * `*.cfg` (Darknet, https://pjreddie.com/darknet/)
* * `*.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.
@@ -1220,9 +1193,8 @@ CV__DNN_INLINE_NS_BEGIN
* @returns Net object.
*
* This function automatically detects an origin framework of trained model
- * and calls an appropriate function such @ref readNetFromCaffe, @ref readNetFromTensorflow
- * or @ref readNetFromDarknet. An order of @p model and @p config
- * arguments does not matter.
+ * and calls an appropriate function such @ref readNetFromCaffe, @ref readNetFromTensorflow.
+ * An order of @p model and @p config arguments does not matter.
*/
CV_EXPORTS_W Net readNet(CV_WRAP_FILE_PATH const String& model,
CV_WRAP_FILE_PATH const String& config = "",
diff --git a/modules/dnn/misc/js/gen_dict.json b/modules/dnn/misc/js/gen_dict.json
index 4b83a0e102..e1b7f2ae2d 100644
--- a/modules/dnn/misc/js/gen_dict.json
+++ b/modules/dnn/misc/js/gen_dict.json
@@ -2,7 +2,7 @@
"whitelist":
{
"dnn_Net": ["setInput", "forward", "setPreferableBackend","getUnconnectedOutLayersNames"],
- "": ["readNetFromCaffe", "readNetFromTensorflow", "readNetFromTorch", "readNetFromDarknet",
+ "": ["readNetFromCaffe", "readNetFromTensorflow", "readNetFromTorch",
"readNetFromONNX", "readNetFromTFLite", "readNet", "blobFromImage"]
},
"namespace_prefix_override":
diff --git a/modules/dnn/misc/objc/gen_dict.json b/modules/dnn/misc/objc/gen_dict.json
index 9e47677206..b94846bb2c 100644
--- a/modules/dnn/misc/objc/gen_dict.json
+++ b/modules/dnn/misc/objc/gen_dict.json
@@ -3,8 +3,6 @@
"Dnn": {
"(Net*)readNetFromCaffe:(NSString*)prototxt caffeModel:(NSString*)caffeModel engine:(int)engine" : { "readNetFromCaffe" : {"name" : "readNetFromCaffeFile"} },
"(Net*)readNetFromCaffe:(ByteVector*)bufferProto bufferModel:(ByteVector*)bufferModel engine:(int)engine" : { "readNetFromCaffe" : {"name" : "readNetFromCaffeBuffer"} },
- "(Net*)readNetFromDarknet:(NSString*)cfgFile darknetModel:(NSString*)darknetModel" : { "readNetFromDarknet" : {"name" : "readNetFromDarknetFile"} },
- "(Net*)readNetFromDarknet:(ByteVector*)bufferCfg bufferModel:(ByteVector*)bufferModel" : { "readNetFromDarknet" : {"name" : "readNetFromDarknetBuffer"} },
"(Net*)readNetFromONNX:(NSString*)onnxFile engine:(int)engine" : { "readNetFromONNX" : {"name" : "readNetFromONNXFile"} },
"(Net*)readNetFromONNX:(ByteVector*)buffer engine:(int)engine" : { "readNetFromONNX" : {"name" : "readNetFromONNXBuffer"} },
"(Net*)readNetFromTensorflow:(NSString*)model config:(NSString*)config engine:(int)engine extraOutputs:(NSArray*)extraOutputs" : { "readNetFromTensorflow" : {"name" : "readNetFromTensorflowFile"} },
diff --git a/modules/dnn/perf/perf_net.cpp b/modules/dnn/perf/perf_net.cpp
index 7a38ed4f49..357b930861 100644
--- a/modules/dnn/perf/perf_net.cpp
+++ b/modules/dnn/perf/perf_net.cpp
@@ -212,8 +212,9 @@ PERF_TEST_P_(DNNTestNetwork, YOLOv3)
#endif
Mat sample = imread(findDataFile("dnn/dog416.png"));
+ cv::resize(sample, sample, Size(640, 640));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(), Scalar(), true);
- processNet("dnn/yolov3.weights", "dnn/yolov3.cfg", inp);
+ processNet("dnn/yolov3.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOv4)
@@ -231,8 +232,9 @@ PERF_TEST_P_(DNNTestNetwork, YOLOv4)
throw SkipTestException("Test is disabled in OpenVINO 2020.4");
#endif
Mat sample = imread(findDataFile("dnn/dog416.png"));
+ cv::resize(sample, sample, Size(608, 608));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(), Scalar(), true);
- processNet("dnn/yolov4.weights", "dnn/yolov4.cfg", inp);
+ processNet("dnn/yolov4.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOv4_tiny)
@@ -243,7 +245,7 @@ PERF_TEST_P_(DNNTestNetwork, YOLOv4_tiny)
#endif
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(), Scalar(), true);
- processNet("dnn/yolov4-tiny-2020-12.weights", "dnn/yolov4-tiny-2020-12.cfg", inp);
+ processNet("dnn/yolov4-tiny.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOv5) {
diff --git a/modules/dnn/src/darknet/darknet_importer.cpp b/modules/dnn/src/darknet/darknet_importer.cpp
deleted file mode 100644
index 024c0b6c50..0000000000
--- a/modules/dnn/src/darknet/darknet_importer.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-// By downloading, copying, installing or using the software you agree to this license.
-// If you do not agree to this license, do not download, install,
-// copy or use the software.
-//
-//
-// License Agreement
-// For Open Source Computer Vision Library
-// (3-clause BSD License)
-//
-// Copyright (C) 2017, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// * Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// * Neither the names of the copyright holders nor the names of the contributors
-// may be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall copyright holders or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-#include "../precomp.hpp"
-
-#include
-#include
-#include
-#include
-#include