nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Please align indentations.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
You may use `cv::format` here
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
I think `layerParams.set("bias_term", layerParams.blobs.size() == 2);` is shorter.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
We need to name it somehow differently because it's not weights mat for this layer. And we don't need a loop here because Reshape takes only input blob and shape, doesn't it?
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
There is the same assertion at `getMatFromTensor`.
**File:** modules/dnn/test/test_onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,344 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+
+#include "test_precomp.hpp"
```

Review comment:
I think we can remove `modelsFolder` variable: ```cpp String onnxmodel = _tf("models/"+ basename + ".onnx"); ```
**File:** modules/dnn/test/test_onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,344 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+
+#include "test_precomp.hpp"
```

Review comment:
The same as above: ```cpp String inpfile = _tf("data/input_" + basename + ".npy"); String outfile = _tf("data/output_" + basename + ".npy"); ```
**File:** modules/dnn/test/test_onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,344 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+
+#include "test_precomp.hpp"
```

Review comment:
I think we can remove it.
**File:** modules/dnn/test/test_onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,344 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+
+#include "test_precomp.hpp"
```

Review comment:
Please use `target` and `backend` instead `targetId`, `backendId` (see DNNTestLayer implementation)
**File:** modules/dnn/test/test_onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,344 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+
+#include "test_precomp.hpp"
```

Review comment:
It looks like we need to skip this test for some of test cases (OpenCV backend, OpenCL fp16 target).
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -800,6 +800,18 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
      */
     CV_EXPORTS_W Net readNetFromModelOptimizer(const String &xml, const String &bin);
 
+    /** @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.
+     *  @returns Network object that ready to do forward, throw an exception in failure cases.
+     */
+    CV_EXPORTS_W Net readNetFromONNX(const String &onnxFile);
+
```

Review comment:
Let's replace a reference to https://onnx.ai/.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -800,6 +800,18 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
      */
     CV_EXPORTS_W Net readNetFromModelOptimizer(const String &xml, const String &bin);
 
+    /** @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.
+     *  @returns Network object that ready to do forward, throw an exception in failure cases.
+     */
+    CV_EXPORTS_W Net readNetFromONNX(const String &onnxFile);
+
```

Review comment:
I think this method can read a general tensor as well but not only 4-dimensional.
**File:** modules/dnn/test/test_onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,344 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+
+#include "test_precomp.hpp"
```

Review comment:
Do you mind to unite some tests by layers? In example, ```cpp TEST_P(Test_ONNX_layers, Convolution) { testLayerUsingONNXModels("convolution"); testLayerUsingONNXModels("convolution2"); } ``` Can you also rename "convolution2" to something more informative like "two_convolutions"?
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
> precomp.hpp Should be the first include (without any precheck "#if")
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Redundant duplicate check.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Please no indentation in namespaces.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
What is about: - range check: should we warn user if input is out of OpenCV 32S range? - using of `cv::saturate_cast<int>()`
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Most part of users don't expect object releasing in function called `getMatFromTensor()`. Releasing input is out of scope operation of normal "get" functions. Move "release" calls to caller. Make function input as "const reference". Also avoid "manual" lifetime management. For example, this code has memory leak on "CV_Error()" processing (3 lines above). Use `cv::Ptr<>` / `std::shared_ptr<>` instead of raw objects.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Please fix indentation here and below (2+ cases)
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Do we need these explicit protobuf includes? Perhaps all of them are included via "opencv-onnx.pb.h".
**File:** modules/dnn/src/onnx/opencv-onnx.proto
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,446 @@
+//
+// WARNING: This file is automatically generated!  Please edit onnx.in.proto.
+//
+
+
+// Copyright (c) Facebook Inc. and Microsoft Corporation.
+// Licensed under the MIT license.
+
+syntax = "proto2";
```

Review comment:
To avoid conflicts usually we need to rename package name too (see "opencv_caffe", #10139): - something like `opencv_onnx`
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Is this "endif" for `HAVE_PROTOBUF`? This should be moved to the end of file. Ideally, with "#else" branch with "Non Implemented" stubs for public API (but it is not used yet even for caffe - protobuf is required for opencv_dnn).
**File:** modules/dnn/src/onnx/opencv-onnx.proto
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,446 @@
+//
+// WARNING: This file is automatically generated!  Please edit onnx.in.proto.
+//
+
+
+// Copyright (c) Facebook Inc. and Microsoft Corporation.
+// Licensed under the MIT license.
+
+syntax = "proto2";
```

Review comment:
Need to re-generate "pb" files too.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Please add some comment that you register network's inputs here.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Can we consider that Gemm layer always has inputs in the following order? ``` input weights bias (optional) ``` This way we can start a loop from 1 and remove a condition that input is trained parameters but not an output from previous layers.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
the same as above
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
Does `currentId->second` differ from `id` from `addLayer`?
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
please add an assertion that `index < node_proto.input_size()`
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
We need to create a test with a network which has more than one input. In example, element-wise summation of two inputs. Please also add a comment above what this loop does.
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
As for me the following line looks better here and below. ```cpp layerParams.set("ceil_mode", framework_name == "onnx-caffe2"); ```
**File:** modules/dnn/src/onnx/onnx_importer.cpp
**Change Type:** added
**Context:** PR #12071: Added ONNX parser with AlexNet support - **Merge with extra**: https://github.com/opencv/opencv_extra/pull/499 related #11008 ``` force_bui...

**Code Changes:**
```diff
@@ -0,0 +1,585 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+// Copyright (C) 2018, Intel Corporation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+
+#include "../precomp.hpp"
+
```

Review comment:
What if `layerParams.has("bias")` is false?