nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/src/layers/reorg_layer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,140 @@
+/*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.
+//
+//
```

Review comment:
It seems to me Reorg layer can't work in-place. `getMemoryShapes` returns true if layer can do it.
**File:** modules/dnn/src/layers/region_layer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,331 @@
+/*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.
+//
+//
```

Review comment:
The same as Reorg layer: it should returns false.
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
It's better to name layers using type prefix every time. Moreover some of layers just named with numbers and it's hard to debug them.
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
Ok. Also required `maxpool_param.set<cv::String>("pad_mode", "SAME");` for odd sizes of layers.
**File:** modules/dnn/src/layers/reorg_layer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,140 @@
+/*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.
+//
+//
```

Review comment:
No, there is no typo, initially I left unchanged a bit strange original implementation of this layer. But now I have changed this place so that there is no confusion.
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
However only one way of padding strategy is used: manual values or padMode ("SAME", "VALID") from TensorFlow. Please take a look on the "ceil_mode" flag instead: https://github.com/opencv/opencv/blob/master/modules/dnn/src/layers/pooling_layer.cpp#L629.
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
Unused variable `channels_num`
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
* Accuracy test passed for Tiny-Yolo if `padMode="SAME"` with any `ceil_mode` value. * Accuracy test can't be passed for Tiny-Yolo for any values of padMode (`padMode="VALID"` or if `padMod` isn't set) with any `ceil_mode` value.
**File:** modules/dnn/src/darknet/darknet_io.hpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,116 @@
+/*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.
+//
+//
```

Review comment:
Unused structure
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
Unused function
**File:** modules/dnn/src/layers/reorg_layer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,140 @@
+/*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.
+//
+//
```

Review comment:
Please, add an assertion that `total(outputs[0]) == total(inputs[0])`.
**File:** modules/dnn/src/layers/reorg_layer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...
**Review Line:** 104

**Code Changes:**
```diff
+
+            int channels = inputShape[1], height = inputShape[2], width = inputShape[3];
+
+            int out_c = channels / (reorgStride*reorgStride);
+
+            for (int k = 0; k < channels; ++k) {
+                for (int j = 0; j < height; ++j) {
+                    for (int i = 0; i < width; ++i) {
+                        int out_index = i + width*(j + height*k);
+                        int c2 = k % out_c;
+                        int offset = k / out_c;
```

Review comment:
Please make it more clear: iterate over output dimensions and map them to input ones.
**File:** modules/dnn/test/test_darknet_importer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,186 @@
+/*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.
+//
+//
```

Review comment:
`float const*const` is a bit confusing (there are 4 places with it). May I ask you to use named constant variables or place a comments because it's hard to understand the magic numbers? Especially it's about samples and tests.
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
Please try to use `cv::format("conv_%d", layer_id)` instead `toString` here and in other places.
**File:** modules/dnn/src/darknet/darknet_io.hpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,116 @@
+/*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.
+//
+//
```

Review comment:
I hope we can emit this structure. Layers are connected sequentially or using explicit numeric offsets starting from the newly added layer. So I think it's possible to use single vector of layers during network building. May I ask you to try it?
**File:** modules/dnn/src/layers/reorg_layer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...
**Review Line:** 104

**Code Changes:**
```diff
+
+            int channels = inputShape[1], height = inputShape[2], width = inputShape[3];
+
+            int out_c = channels / (reorgStride*reorgStride);
+
+            for (int k = 0; k < channels; ++k) {
+                for (int j = 0; j < height; ++j) {
+                    for (int i = 0; i < width; ++i) {
+                        int out_index = i + width*(j + height*k);
+                        int c2 = k % out_c;
+                        int offset = k / out_c;
```

Review comment:
Most likely there was made a logical mistake in the original version of Darknet in the reorg layer: https://github.com/pjreddie/darknet/blob/master/src/blas.c#L9 It works as I described if called `reorg(input, output, out_w, out_h, _out_c, ...);` https://github.com/opencv/opencv/pull/9705#discussion_r141307309 But in the original Darknet version function is called in this way `reorg(input, output, in_w, in_h, in_c, ...);`, so the one-to-one correspondence of the input and output parameters is preserved, but very strange permutations occur. But because original Darknet works with this implementation of reorg and all models trained using it, then we can't fix this logical mistake. Why the author has not found and corrected this error? I think: * Perhaps this logical error does not spoil the detection accuracy, so it was not detected. * Theoretically, we can assume that this error even increased the accuracy - so the author found it and left it. ---- > iterate over output dimensions and map them to input ones. So I can implement it in a such way, but it works correctly only **`if (in_w % 2 == 0 && in_h % 2 == 0 && in_c % 4 == 0)`** : http://coliru.stacked-crooked.com/a/b962d20938362d4f ``` void reorg_my(const float*const srcData, float *const dstData, int width, int height, int channels, int reorgStride) { int outChannels = channels * reorgStride * reorgStride; int outHeight = height / reorgStride; int outWidth = width / reorgStride; for (int y = 0; y < outHeight; ++y) { for (int x = 0; x < outWidth; ++x) { for (int c = 0; c < outChannels; ++c) { int out_index = x + outWidth*(y + outHeight*c); int step = c / channels; int x_offset = step % reorgStride; int y_offset = reorgStride * ((step / reorgStride) % reorgStride); int in_x = x * reorgStride + x_offset; int out_seq_y = y + c*outHeight; int in_intermediate_y = out_seq_y*2 - out_seq_y%2; in_intermediate_y = in_intermediate_y % (channels*height); int in_c = in_intermediate_y / height; int in_y = in_intermediate_y % height + y_offset; int in_index = in_x + width*(in_y + height*in_c); dstData[out_index] = srcData[in_index]; } } } } ```
**File:** modules/dnn/src/darknet/darknet_io.hpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,116 @@
+/*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.
+//
+//
```

Review comment:
Do you mean that I should to try use `cv::dnn::experimental_dnn_v1::LayerParams` instead of `darknet::LayerParameter`?
**File:** modules/dnn/src/darknet/darknet_io.hpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,116 @@
+/*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.
+//
+//
```

Review comment:
Yeah, I think we can just parse text and binary files simultaneously: for an every entry in config we create a new one LayerParams and fill it depends on layer type. If specific layer has weights - read them from opened binary file. Then add a layer to final network (addLayerToPrev or addLayer with multiple connections based on id of the new layer and offsets i.e. -1, -4 of route).
**File:** modules/dnn/test/test_darknet_importer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,186 @@
+/*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.
+//
+//
```

Review comment:
I removed `const*const`, also added named constant variables and described the format of network output that compared to the reference in the tests. But why is `const*const` confusing, is this contrary to the code style conventions that is accepted in OpenCV? 1st `const` forbids modification of values pointed to by this pointer, 2nd `const` forbids modification of this pointer.
**File:** modules/dnn/src/darknet/darknet_importer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...
**Review Line:** 1

**Code Changes:**
```diff
@@ -0,0 +1,195 @@
+/*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,
```

Review comment:
I think we need to replace it. Please take a look on more fresh versions of the licence.
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...
**Review Line:** 1

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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,
```

Review comment:
The same, please update the licence.
**File:** modules/dnn/src/darknet/darknet_io.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,624 @@
+/*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.
+//
+//
```

Review comment:
Is it possible to nest it into the `cv::dnn` namespace?
**File:** modules/dnn/src/darknet/darknet_io.hpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...
**Review Line:** 1

**Code Changes:**
```diff
@@ -0,0 +1,116 @@
+/*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,
```

Review comment:
One again: the licence update.
**File:** modules/dnn/src/darknet/darknet_io.hpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,116 @@
+/*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.
+//
+//
```

Review comment:
namespace `cv::dnn::darknet`
**File:** modules/dnn/test/test_darknet_importer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...
**Review Line:** 1

**Code Changes:**
```diff
@@ -0,0 +1,186 @@
+/*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,
```

Review comment:
The licence update.
**File:** modules/dnn/test/test_darknet_importer.cpp
**Change Type:** added
**Context:** PR #9705: Added DNN Darknet Yolo v2 for object detection - ``` opencv_extra=dnn_model_darknet_yolo_v2 ``` ### This pullrequest changes  Added neural n...

**Code Changes:**
```diff
@@ -0,0 +1,186 @@
+/*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.
+//
+//
```

Review comment:
An extra include directive.