instruction
stringclasses
9 values
input
stringlengths
279
5.47k
output
stringlengths
6
9.58k
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Review Line:** 54 **Code Changes:** ```diff + ANNIndexImpl(int dimension) : dim(dimension) + { + index = makePtr<::cvannoy::AnnoyIndex<int, DataType, DistanceType, Random, ::cvannoy::AnnoyIndexSingleThreadedBuildPolicy>>(dimension); + } + + void addItems(InputArray _dataset) CV_OVERRIDE + { + CV_Assert(!_dataset.empty()); + + Mat features = _dataset.getMat(); + CV_Assert(features.cols == dim); ```
> I propose to return bool and print error to log, but not throw exception, if `addItems` was not successful. Ok. And do you think it's better to return bool and print error too for `build` and `knnSearch`? My thought to throw exception was that there might be possible users who do not check the flags and just do addItems->build->knnSearch in a row which might cause crash.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Review Line:** 54 **Code Changes:** ```diff + ANNIndexImpl(int dimension) : dim(dimension) + { + index = makePtr<::cvannoy::AnnoyIndex<int, DataType, DistanceType, Random, ::cvannoy::AnnoyIndexSingleThreadedBuildPolicy>>(dimension); + } + + void addItems(InputArray _dataset) CV_OVERRIDE + { + CV_Assert(!_dataset.empty()); + + Mat features = _dataset.getMat(); + CV_Assert(features.cols == dim); ```
add_item returns false in a single case: if the state is loaded from file. So ignore my proposal, it's not relevant.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/hal_rvv/hal_rvv_1p0/merge.hpp **Change Type:** added **Context:** PR #26216: Add the HAL implementation for the merge function on RISC-V Vector. **Review Line:** 33 **Code Changes:** ```diff + { + auto a = __riscv_vle8_v_u8m1(src0 + i, vl); + __riscv_vsse8_v_u8m1(dst + i*cn, sizeof(uchar)*2, a, vl); + } + #if defined(__clang__) + #pragma clang loop vectorize(disable) + #endif + for( ; i < len; i++) + dst[i*cn] = src0[i]; + } + else if( k == 2 ) ```
Why do yoiu disable vectorization? Was it causing slowdown?
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/hal_rvv/hal_rvv_1p0/merge.hpp **Change Type:** added **Context:** PR #26216: Add the HAL implementation for the merge function on RISC-V Vector. **Review Line:** 27 **Code Changes:** ```diff + int i = 0, j; + int vl = __riscv_vsetvlmax_e8m1(); + if( k == 1 ) + { + const uchar* src0 = src[0]; + for( ; i <= len - vl; i += vl) + { + auto a = __riscv_vle8_v_u8m1(src0 + i, vl); + __riscv_vsse8_v_u8m1(dst + i*cn, sizeof(uchar)*2, a, vl); + } + #if defined(__clang__) ```
Did you try scalable vector length in the loop to avoid separate tail processing? Did it perform worse?
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/hal_rvv/hal_rvv_1p0/merge.hpp **Change Type:** added **Context:** PR #26216: Add the HAL implementation for the merge function on RISC-V Vector. **Review Line:** 27 **Code Changes:** ```diff + int i = 0, j; + int vl = __riscv_vsetvlmax_e8m1(); + if( k == 1 ) + { + const uchar* src0 = src[0]; + for( ; i <= len - vl; i += vl) + { + auto a = __riscv_vle8_v_u8m1(src0 + i, vl); + __riscv_vsse8_v_u8m1(dst + i*cn, sizeof(uchar)*2, a, vl); + } + #if defined(__clang__) ```
Yes, the scalable vector length loop is worse and I guess the reason is due to the `setvl` instruction inside the loop body.
You are an expert OpenCV code reviewer specializing in performance optimization. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/hal_rvv/hal_rvv_1p0/merge.hpp **Change Type:** added **Context:** PR #26216: Add the HAL implementation for the merge function on RISC-V Vector. **Review Line:** 33 **Code Changes:** ```diff + { + auto a = __riscv_vle8_v_u8m1(src0 + i, vl); + __riscv_vsse8_v_u8m1(dst + i*cn, sizeof(uchar)*2, a, vl); + } + #if defined(__clang__) + #pragma clang loop vectorize(disable) + #endif + for( ; i < len; i++) + dst[i*cn] = src0[i]; + } + else if( k == 2 ) ```
Yes, since it's actually quite short, vectorizing this loop will cause performance degradation. This is actually a ”tail“, but the static analysis of compiler does not know that it is the "tail".
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/hal_rvv/hal_rvv_1p0/merge.hpp **Change Type:** added **Context:** PR #26216: Add the HAL implementation for the merge function on RISC-V Vector. **Review Line:** 1 **Code Changes:** ```diff @@ -0,0 +1,363 @@ +#ifndef OPENCV_HAL_RVV_MERGE_HPP_INCLUDED +#define OPENCV_HAL_RVV_MERGE_HPP_INCLUDED + +#include <riscv_vector.h> + +namespace cv { namespace cv_hal_rvv { ```
Need to add OpenCV license header
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/hal_rvv/hal_rvv_1p0/merge.hpp **Change Type:** added **Context:** PR #26216: Add the HAL implementation for the merge function on RISC-V Vector. **Review Line:** 1 **Code Changes:** ```diff @@ -0,0 +1,363 @@ +#ifndef OPENCV_HAL_RVV_MERGE_HPP_INCLUDED +#define OPENCV_HAL_RVV_MERGE_HPP_INCLUDED + +#include <riscv_vector.h> + +namespace cv { namespace cv_hal_rvv { ```
Do you mean the shorter version below, or another longer version? ``` // 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. ```
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/hal/intrin_math.hpp **Change Type:** modified **Context:** PR #26358: 5.x merge 4.x - No changes in opencv_contrib and opencv_extra. Manual changes: - Fixed f16 in universal intrinsics for ARM, e.g. `template ... **Review Line:** 53 **Code Changes:** ```diff + const _TpVec16F _vexp_p0_f16 = v_setall_<_TpVec16F>(1.9875691500E-4f); + const _TpVec16F _vexp_p1_f16 = v_setall_<_TpVec16F>(1.3981999507E-3f); + const _TpVec16F _vexp_p2_f16 = v_setall_<_TpVec16F>(8.3334519073E-3f); + const _TpVec16F _vexp_p3_f16 = v_setall_<_TpVec16F>(4.1665795894E-2f); + const _TpVec16F _vexp_p4_f16 = v_setall_<_TpVec16F>(1.6666665459E-1f); + const _TpVec16F _vexp_p5_f16 = v_setall_<_TpVec16F>(5.0000001201E-1f); + + _TpVec16F _vexp_, _vexp_x, _vexp_y, _vexp_xx; + _TpVec16S _vexp_mm; + const _TpVec16S _vexp_bias_s16 = v_setall_<_TpVec16S>((short)0xf); + ```
use `hfloat(xxxx.f)` to replace the input number `v_setall_<_TpVec16F>(hfloat(-6.93359375E-1f));`
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/hal/intrin_math.hpp **Change Type:** modified **Context:** PR #26358: 5.x merge 4.x - No changes in opencv_contrib and opencv_extra. Manual changes: - Fixed f16 in universal intrinsics for ARM, e.g. `template ... **Review Line:** 207 **Code Changes:** ```diff + const _TpVec16F _vlog_p3_fp16 = v_setall_<_TpVec16F>(-1.2420140846E-1f); + const _TpVec16F _vlog_p4_fp16 = v_setall_<_TpVec16F>(1.4249322787E-1f); + const _TpVec16F _vlog_p5_fp16 = v_setall_<_TpVec16F>(-1.6668057665E-1f); + const _TpVec16F _vlog_p6_fp16 = v_setall_<_TpVec16F>(2.0000714765E-1f); + const _TpVec16F _vlog_p7_fp16 = v_setall_<_TpVec16F>(-2.4999993993E-1f); + const _TpVec16F _vlog_p8_fp16 = v_setall_<_TpVec16F>(3.3333331174E-1f); + + _TpVec16F _vlog_x, _vlog_e, _vlog_y, _vlog_z, _vlog_tmp; + _TpVec16S _vlog_ux, _vlog_emm0; + const _TpVec16S _vlog_inv_mant_mask_s16 = v_setall_<_TpVec16S>((short)~0x7c00); + ```
The same as above
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/hal/intrin_math.hpp **Change Type:** modified **Context:** PR #26358: 5.x merge 4.x - No changes in opencv_contrib and opencv_extra. Manual changes: - Fixed f16 in universal intrinsics for ARM, e.g. `template ... **Review Line:** 246 **Code Changes:** ```diff + _vlog_y = v_mul(_vlog_y, _vlog_x); + _vlog_y = v_mul(_vlog_y, _vlog_z); + + _vlog_y = v_fma(_vlog_e, _vlog_q1_fp16, _vlog_y); + + _vlog_y = v_sub(_vlog_y, v_mul(_vlog_z, v_setall_<_TpVec16F>(0.5f))); + + _vlog_x = v_add(_vlog_x, _vlog_y); + _vlog_x = v_fma(_vlog_e, _vlog_q2_fp16, _vlog_x); + // log(0) -> -INF + _TpVec16F mask_zero = v_eq(x, v_setzero_<_TpVec16F>()); ```
The same as above
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/hal/intrin_math.hpp **Change Type:** modified **Context:** PR #26358: 5.x merge 4.x - No changes in opencv_contrib and opencv_extra. Manual changes: - Fixed f16 in universal intrinsics for ARM, e.g. `template ... **Review Line:** 217 **Code Changes:** ```diff + + _vlog_ux = v_reinterpret_as_s16(x); + _vlog_emm0 = v_shr(_vlog_ux, 10); + + _vlog_ux = v_and(_vlog_ux, _vlog_inv_mant_mask_s16); + _vlog_ux = v_or(_vlog_ux, v_reinterpret_as_s16(v_setall_<_TpVec16F>(0.5f))); + _vlog_x = v_reinterpret_as_f16(_vlog_ux); + + _vlog_emm0 = v_sub(_vlog_emm0, v_setall_<_TpVec16S>((short)0xf)); + _vlog_e = v_cvt_f16(_vlog_emm0); + ```
The same as above
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/hal/intrin_neon.hpp **Change Type:** modified **Context:** PR #26358: 5.x merge 4.x - No changes in opencv_contrib and opencv_extra. Manual changes: - Fixed f16 in universal intrinsics for ARM, e.g. `template ... **Review Line:** 440 **Code Changes:** ```diff inline v_int8x16 v_reinterpret_as_s8(const v_##_Tpv& v) { return v_int8x16(vreinterpretq_s8_##suffix(v.val)); } \ @@ -435,6 +437,7 @@ OPENCV_HAL_IMPL_NEON_INIT(uint64x2, uint64, uint64, u64) OPENCV_HAL_IMPL_NEON_INIT(int64x2, int64, int64, s64) #if CV_SIMD128_FP16 OPENCV_HAL_IMPL_NEON_INIT(float16x8, hfloat, __fp16, f16); +template <> inline v_float16x8 v_setall_(float v) { return v_setall_f16((hfloat)v); } #define OPENCV_HAL_IMPL_NEON_INIT_FP16(_Tpv, suffix) \ inline v_float16x8 v_reinterpret_as_f16(const v_##_Tpv& v) { return v_float16x8(vreinterpretq_f16_##suffix(v.val)); } OPENCV_HAL_IMPL_NEON_INIT_FP16(uint8x16, u8) @@ -3030,6 +3033,28 @@ inline void v_pack_store(hfloat* ptr, const v_float32x4& v) ```
Should be removed
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/test/test_intrin_utils.hpp **Change Type:** modified **Context:** PR #26358: 5.x merge 4.x - No changes in opencv_contrib and opencv_extra. Manual changes: - Fixed f16 in universal intrinsics for ARM, e.g. `template ... **Review Line:** 2171 **Code Changes:** ```diff + TheTest &test_sincos_fp16() { +#if 0 // CV_SIMD_FP16 + hfloat flt16_min; + uint16_t flt16_min_hex = 0x0400; + std::memcpy(&flt16_min, &flt16_min_hex, sizeof(hfloat)); + __test_sincos((hfloat) 1e-3, flt16_min); +#endif + return *this; + } + + TheTest &test_sincos_fp32() { ```
release the threshold from `1e-3` to `1e-2`
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** doc/tutorials/introduction/linux_eclipse/linux_eclipse.markdown **Change Type:** modified **Context:** PR #26405: Rename features2d - This PR renames the module _features2d_ to _features_ as one of the Big OpenCV Cleanup #25007. Related PR: opencv/openc... **Code Changes:** ```diff @@ -111,7 +111,7 @@ Making a project on the list below are enough (for simple applications) . In my case, I am putting all of them since I plan to use the whole bunch: - opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui opencv_ml opencv_videoio opencv_video opencv_features2d + opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui opencv_videoio opencv_video opencv_features opencv_3d opencv_objdetect opencv_flann ![](images/a10.png) @@ -123,7 +123,7 @@ Making a project ```
-lopencv_ml is not there any more. calib3d also split on 3d, calib and stereo.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** platforms/js/opencv_js.config.py **Change Type:** modified **Context:** PR #26405: Rename features2d - This PR renames the module _features2d_ to _features_ as one of the Big OpenCV Cleanup #25007. Related PR: opencv/openc... **Code Changes:** ```diff @@ -151,7 +151,7 @@ '': ['readNetFromCaffe', 'readNetFromTensorflow', 'readNetFromDarknet', 'readNetFromONNX', 'readNetFromTFLite', 'readNet', 'blobFromImage']} -features2d = {'Feature2D': ['detect', 'compute', 'detectAndCompute', 'descriptorSize', 'descriptorType', 'defaultNorm', 'empty', 'getDefaultName'], +features = {'Feature2D': ['detect', 'compute', 'detectAndCompute', 'descriptorSize', 'descriptorType', 'defaultNorm', 'empty', 'getDefaultName'], 'ORB': ['create', 'setMaxFeatures', 'setScaleFactor', 'setNLevels', 'setEdgeThreshold', 'setFastThreshold', 'setFirstLevel', 'setWTA_K', 'setScoreType', 'setPatchSize', 'getFastThreshold', 'getDefaultName'], 'MSER': ['create', 'detectRegions', 'setDelta', 'getDelta', 'setMinArea', 'getMinArea', 'setMaxArea', 'getMaxArea', 'setPass2Only', 'getPass2Only', 'getDefaultName'], 'FastFeatureDetector': ['create', 'setThreshold', 'getThreshold', 'setNonmaxSuppression', 'getNonmaxSuppression', 'setType', 'getType', 'getDefaultName'], @@ -210,7 +210,7 @@ ```
`Feature2D` is class name, but not module name. SHould be reverted.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/java/sbt/src/main/scala/ScalaCorrespondenceMatchingDemo.scala **Change Type:** modified **Context:** PR #26405: Rename features2d - This PR renames the module _features2d_ to _features_ as one of the Big OpenCV Cleanup #25007. Related PR: opencv/openc... **Review Line:** 3 **Code Changes:** ```diff @@ -1,10 +1,10 @@ import org.opencv.imgcodecs.Imgcodecs -import org.opencv.features2d.DescriptorExtractor -import org.opencv.features2d.Features2d +import org.opencv.features.DescriptorExtractor +import org.opencv.features.Features import org.opencv.core.MatOfKeyPoint import org.opencv.core.Mat -import org.opencv.features2d.FeatureDetector -import org.opencv.features2d.DescriptorMatcher +import org.opencv.features.FeatureDetector ```
Features2d is class name, should be reverted.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/python/plane_tracker.py **Change Type:** modified **Context:** PR #26405: Rename features2d - This PR renames the module _features2d_ to _features_ as one of the Big OpenCV Cleanup #25007. Related PR: opencv/openc... **Code Changes:** ```diff @@ -4,7 +4,7 @@ Multitarget planar tracking ================== -Example of using features2d framework for interactive video homography matching. +Example of using "features" framework for interactive video homography matching. ORB features and FLANN matcher are used. This sample provides PlaneTracker class and an example of its usage. ```
I propose to use quotes "features" module.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/java/tutorial_code/features/feature_description/SURFMatchingDemo.java **Change Type:** renamed **Context:** PR #26405: Rename features2d - This PR renames the module _features2d_ to _features_ as one of the Big OpenCV Cleanup #25007. Related PR: opencv/openc... **Review Line:** 6 **Code Changes:** ```diff import org.opencv.core.MatOfDMatch; import org.opencv.core.MatOfKeyPoint; -import org.opencv.features2d.DescriptorMatcher; -import org.opencv.features2d.Features2d; +import org.opencv.features.DescriptorMatcher; +import org.opencv.features.Features; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.xfeatures2d.SURF; @@ -37,7 +37,7 @@ public void run(String[] args) { ```
I am not familiar with the java binding, and changing back to `Features2d` leads to compile errors.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_tflite_importer.cpp **Change Type:** modified **Context:** PR #26330: Modified TFLite parser for the new dnn engine **Review Line:** 158 **Code Changes:** ```diff @@ -155,6 +155,9 @@ TEST_P(Test_TFLite, max_unpooling) net.setPreferableBackend(backend); net.setPreferableTarget(target); + if (net.getMainGraph()) + throw SkipTestException("The new dnn engine doesn't support forward to specified layers"); // https://github.com/opencv/opencv/issues/26349 + Mat input = imread(findDataFile("cv/shared/lena.png")); cvtColor(input, input, COLOR_BGR2RGBA); input = input.mul(Scalar(1, 1, 1, 0)); ```
Please add reference to Github bug.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp **Change Type:** modified **Context:** PR #26330: Modified TFLite parser for the new dnn engine **Review Line:** 1112 **Code Changes:** ```diff + * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic. + * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Net object. */ - CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model); + CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_AUTO); /** @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. + * Please pay attention that the new DNN does not support non-CPU back-ends for now. ```
int or enum type?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/tflite/tflite_importer.cpp **Change Type:** modified **Context:** PR #26330: Modified TFLite parser for the new dnn engine **Review Line:** 82 **Code Changes:** ```diff void parseFusedActivation(const Operator& op, ActivationFunctionType activ); void parseActivation(const Operator& op, const std::string& opcode, LayerParams& layerParams, bool isFused); - void addLayer(LayerParams& layerParams, const Operator& op); - int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype); + void addLayer(LayerParams& layerParams, const Operator& op, bool additionalPreLayer = false, bool additionalPostLayer = false); + void addLayer(LayerParams& layerParams, const std::vector<std::string>& inputTensors, const std::vector<std::string>& outputTensors); + int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype, int inpTensorId); int addReshapeLayer(const std::vector<int>& shape, int axis, int num_axes, - const std::string& name, const std::pair<int, int>& inpId, int dtype); - int addFlattenLayer(int axis, int end_axis, const std::string& name, const std::pair<int, int>& inpId, int dtype); ```
Sorry, I forgot to add the PR description. Added it.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp **Change Type:** modified **Context:** PR #26330: Modified TFLite parser for the new dnn engine **Review Line:** 1112 **Code Changes:** ```diff + * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic. + * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Net object. */ - CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model); + CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_AUTO); /** @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. + * Please pay attention that the new DNN does not support non-CPU back-ends for now. ```
Changed to enum
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/tflite/tflite_importer.cpp **Change Type:** modified **Context:** PR #26330: Modified TFLite parser for the new dnn engine **Review Line:** 82 **Code Changes:** ```diff void parseFusedActivation(const Operator& op, ActivationFunctionType activ); void parseActivation(const Operator& op, const std::string& opcode, LayerParams& layerParams, bool isFused); - void addLayer(LayerParams& layerParams, const Operator& op); - int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype); + void addLayer(LayerParams& layerParams, const Operator& op, bool additionalPreLayer = false, bool additionalPostLayer = false); + void addLayer(LayerParams& layerParams, const std::vector<std::string>& inputTensors, const std::vector<std::string>& outputTensors); + int addPermuteLayer(const std::vector<int>& order, const std::string& permName, const std::pair<int, int>& inpId, int dtype, int inpTensorId); int addReshapeLayer(const std::vector<int>& shape, int axis, int num_axes, - const std::string& name, const std::pair<int, int>& inpId, int dtype); - int addFlattenLayer(int axis, int end_axis, const std::string& name, const std::pair<int, int>& inpId, int dtype); ```
I've added you naming for the new engine. Btw I've found out that the TFLite models don't have layer names and our parser just uses layer_outputs[0].name
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp **Change Type:** modified **Context:** PR #26330: Modified TFLite parser for the new dnn engine **Review Line:** 1112 **Code Changes:** ```diff + * @param engine select DNN engine to be used. With auto selection the new engine is used first and falls back to classic. + * Please pay attention that the new DNN does not support non-CPU back-ends for now. * @returns Net object. */ - CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model); + CV_EXPORTS_W Net readNetFromTFLite(CV_WRAP_FILE_PATH const String &model, int engine=ENGINE_AUTO); /** @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. + * Please pay attention that the new DNN does not support non-CPU back-ends for now. ```
I reverted back to int. Enum triggers issue with Java bindings generator. I know, it should be fixed, but it's less urgent.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/cpp/videowriter.cpp **Change Type:** added **Context:** PR #25349: Videocapture samples cleanup cpp **Code Changes:** ```diff @@ -0,0 +1,118 @@ +/** + @file videowriter.cpp + @brief A sample for VideoWriter and VideoCapture with options to specify video codec, fps and resolution + @date April 05, 2024 +*/ + + +#include <opencv2/core.hpp> +#include <opencv2/videoio.hpp> ```
The codec list depends on supported back-ends. Mjpeg is implemented by OpenCV itself. I propose to rewrite: "Supported codecs depend on OpenCV Configuration. Try one of 'h264', 'h265', 'mpeg2', 'mpeg4', 'mjpeg', 'vp8'"
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/cpp/videowriter.cpp **Change Type:** added **Context:** PR #25349: Videocapture samples cleanup cpp **Code Changes:** ```diff @@ -0,0 +1,118 @@ +/** + @file videowriter.cpp + @brief A sample for VideoWriter and VideoCapture with options to specify video codec, fps and resolution + @date April 05, 2024 +*/ + + +#include <opencv2/core.hpp> +#include <opencv2/videoio.hpp> ```
I propose to support WxH configrations like 640x480.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/cpp/videowriter.cpp **Change Type:** added **Context:** PR #25349: Videocapture samples cleanup cpp **Code Changes:** ```diff @@ -0,0 +1,118 @@ +/** + @file videowriter.cpp + @brief A sample for VideoWriter and VideoCapture with options to specify video codec, fps and resolution + @date April 05, 2024 +*/ + + +#include <opencv2/core.hpp> +#include <opencv2/videoio.hpp> ```
I propose to make it command line parameter.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/cpp/videocapture_combined.cpp **Change Type:** added **Context:** PR #25349: Videocapture samples cleanup cpp **Code Changes:** ```diff @@ -0,0 +1,88 @@ +/* + * This sample demonstrates how to read and display frames from a video file, a camera device or an image sequence. + * The sample also demonstrates extracting audio buffers from a video file. + + * Capturing video and audio simultaneously from camera device is not supported by OpenCV. +*/ + + +#include <opencv2/core.hpp> ```
It may be end of stream/sequence
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/matrix.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 20 **Code Changes:** ```diff + layout == DATA_LAYOUT_NHWC ? "NHWC" : + layout == DATA_LAYOUT_BLOCK ? "NC1HWC0" : + layout == DATA_LAYOUT_NCDHW ? "NCDHW" : + layout == DATA_LAYOUT_NDHWC ? "NDHWC" : + layout == DATA_LAYOUT_PLANAR ? "PLANAR" : + layout == DATA_LAYOUT_UNKNOWN ? "Unknown" : "???"; +} + +bool operator == (const MatShape& size1, const MatShape& size2) +{ + if (size1.dims != size2.dims) ```
Assert? Invalid layout value means user error or memory corruption. Both of them should stop the program.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/tflite/tflite_importer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -180,16 +180,16 @@ void TFLiteImporter::populateNet() std::vector<MatShape> inputsShapes(subgraph_inputs_size); for (size_t i = 0; i < subgraph_inputs_size; ++i) { - int idx = subgraph_inputs->Get(i); + size_t idx = subgraph_inputs->Get(i); layerIds[idx] = std::make_pair(0, i); const auto tensor = modelTensors->Get(idx); if (!tensor) - CV_Error(Error::StsError, cv::format("DNN/TFLite: subgraph input %d (%d) is NULL", (int)i, idx)); ```
`%zu` for `i` makes sense too to prevent conversions.
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/graph_const_fold.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 100 **Code Changes:** ```diff + if (!layer->dynamicOutputShapes()) + netimpl->allocateLayerOutputs(layer, inpTypes, inpShapes, outTypes, + outShapes, outOrigData, outMats, tempTypes, tempShapes, tempMats, + netimpl->scratchBufs, false); + layer->finalize(inpMats, outMats); + layer->forward(inpMats, outMats, tempMats); + CV_Assert(outMats.size() == noutputs); + for (j = 0; j < noutputs; j++) { + Arg out = outputs[j]; + ArgData& out_data = netimpl->args.at(out.idx); + const Mat& m = outMats[j]; ```
Missing support of other non-CPU executors and non-CPU buffers.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/mat.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -67,6 +67,113 @@ enum AccessFlag { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, CV_ENUM_FLAGS(AccessFlag) __CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag) +/** + * @brief Enum of data layout for model inference. + * @see Image2BlobParams + */ +enum DataLayout +{ ```
In general there is no such information in generic functions (MatShape doesn't contain that). So it could not be handled properly. Generic functions should receive already "handled" dynamic shapes. Basic structures should be minimal as possible.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/mat.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 170 **Code Changes:** ```diff + operator std::vector<int>() const; + std::string str() const; + + int dims; + DataLayout layout; + int C; + int p[MAX_DIMS]; +}; + +CV_EXPORTS bool operator == (const MatShape& shape1, const MatShape& shape2); +CV_EXPORTS bool operator != (const MatShape& shape1, const MatShape& shape2); ```
Avoid one letter names. No way to properly find related code.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/mat.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 171 **Code Changes:** ```diff + std::string str() const; + + int dims; + DataLayout layout; + int C; + int p[MAX_DIMS]; +}; + +CV_EXPORTS bool operator == (const MatShape& shape1, const MatShape& shape2); +CV_EXPORTS bool operator != (const MatShape& shape1, const MatShape& shape2); + ```
The same. What is `p`?
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1176 **Code Changes:** ```diff +/** @brief Broadcast the given Mat to the given shape. + * @param src input array + * @param shape target shape. Note that negative values are not supported. + * @param dst output array that has the given shape + */ +CV_EXPORTS void broadcast(InputArray src, const MatShape& shape, OutputArray dst); + enum RotateFlags { ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise ROTATE_180 = 1, //!<Rotate 180 degrees clockwise ```
This violate existed rules of parameters ordering.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/mat.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 490 **Code Changes:** ```diff + + void fit(Size sz, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void fit(int rows, int cols, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void fit(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void fit(const MatShape& shape, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void fitSameSize(const _InputArray& arr, int mtype) const; + void release() const; void clear() const; void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const; @@ -876,6 +994,20 @@ class CV_EXPORTS Mat ```
Tests should be added too.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/mat.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -67,6 +67,113 @@ enum AccessFlag { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, CV_ENUM_FLAGS(AccessFlag) __CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag) +/** + * @brief Enum of data layout for model inference. + * @see Image2BlobParams + */ +enum DataLayout +{ ```
Consider using inheritance to avoid creation of GOD classes.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/matrix.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1110 **Code Changes:** ```diff return p; } +MatShape Mat::shape() const +{ + return dims == 0 && data == 0 ? MatShape() : MatShape(dims, size.p); +} Mat::Mat(Mat&& m) CV_NOEXCEPT : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), @@ -747,6 +1243,27 @@ void Mat::create(const std::vector<int>& _sizes, int _type) ```
We should not work with non-existed tensors. It is a programming error in general. `CV_Assert(data);`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/matrix.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1851 **Code Changes:** ```diff } +Mat Mat::reshape(int _cn, const MatShape& _newshape) const +{ + if (_newshape.dims < 0) { + int newshape[] = {0}; + return reshape(_cn, 1, newshape); + } + return reshape(_cn, _newshape.dims, _newshape.p); +} + ```
Looks like as an invalid usage which we should not allow.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/matrix_wrap.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -593,6 +593,41 @@ int _InputArray::sizend(int* arrsz, int i) const return d; } +bool _InputArray::empty(int i) const +{ + _InputArray::KindFlag k = kind(); + if (i >= 0) { + if (k == STD_VECTOR_MAT) { + auto mv = reinterpret_cast<const std::vector<Mat>*>(obj); ```
Keep code readable. One line - one variable.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -42,6 +42,7 @@ #ifndef OPENCV_DNN_DNN_HPP #define OPENCV_DNN_DNN_HPP +#include <ostream> #include <vector> #include <opencv2/core.hpp> #include "opencv2/core/async.hpp" @@ -61,7 +62,6 @@ CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn ```
int => enum type
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/graph_buffer_allocator.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 332 **Code Changes:** ```diff +}; + +void Net::Impl::assignBuffers() +{ + BufferAllocator buf_allocator(this); + buf_allocator.assign(); +} + +CV__DNN_INLINE_NS_END +}} ```
How to disable that? E.g for debug pursposes.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 2314 **Code Changes:** ```diff @@ -2311,10 +2311,10 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N int axis = axes.getIntValue(0); axis = axis < 0 ? axis + (int)inpShape.size() + 1 : axis; CV_Assert(0 <= axis && axis <= inpShape.size()); - std::vector<int> outShape = inpShape; + MatShape outShape = inpShape; outShape.insert(outShape.begin() + axis, 1); layerParams.type = (depth == CV_8S) ? "ReshapeInt8" : "Reshape"; - layerParams.set("dim", DictValue::arrayInt(&outShape[0], outShape.size())); + layerParams.set("dim", DictValue::arrayInt(&outShape[0], (int)outShape.size())); if (hasDynamicShapes) ```
Since we are getting symbolic inference, the shape inference in onnx importer should be dropped, am I right?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -0,0 +1,2450 @@ +// 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. + +#include "../precomp.hpp" +#include "../net_impl.hpp" + +#include <opencv2/dnn/shape_utils.hpp> +#include <opencv2/dnn/layer_reg.private.hpp> ```
I believe this can be dropped on 5.x since `Mat` can handles 0D/1D correctly.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -42,6 +42,7 @@ #ifndef OPENCV_DNN_DNN_HPP #define OPENCV_DNN_DNN_HPP +#include <ostream> #include <vector> #include <opencv2/core.hpp> #include "opencv2/core/async.hpp" @@ -61,7 +62,6 @@ CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn ```
The methods are defined, but not implemented. It causes linker issue.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 2314 **Code Changes:** ```diff @@ -2311,10 +2311,10 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N int axis = axes.getIntValue(0); axis = axis < 0 ? axis + (int)inpShape.size() + 1 : axis; CV_Assert(0 <= axis && axis <= inpShape.size()); - std::vector<int> outShape = inpShape; + MatShape outShape = inpShape; outShape.insert(outShape.begin() + axis, 1); layerParams.type = (depth == CV_8S) ? "ReshapeInt8" : "Reshape"; - layerParams.set("dim", DictValue::arrayInt(&outShape[0], outShape.size())); + layerParams.set("dim", DictValue::arrayInt(&outShape[0], (int)outShape.size())); if (hasDynamicShapes) ```
yes, I removed it. But it means more cases should be handled during the inference itself.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -0,0 +1,2450 @@ +// 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. + +#include "../precomp.hpp" +#include "../net_impl.hpp" + +#include <opencv2/dnn/shape_utils.hpp> +#include <opencv2/dnn/layer_reg.private.hpp> ```
Add a wrapper for this?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 2314 **Code Changes:** ```diff @@ -2311,10 +2311,10 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N int axis = axes.getIntValue(0); axis = axis < 0 ? axis + (int)inpShape.size() + 1 : axis; CV_Assert(0 <= axis && axis <= inpShape.size()); - std::vector<int> outShape = inpShape; + MatShape outShape = inpShape; outShape.insert(outShape.begin() + axis, 1); layerParams.type = (depth == CV_8S) ? "ReshapeInt8" : "Reshape"; - layerParams.set("dim", DictValue::arrayInt(&outShape[0], outShape.size())); + layerParams.set("dim", DictValue::arrayInt(&outShape[0], (int)outShape.size())); if (hasDynamicShapes) ```
Code looks way simpler and cleaner in the new importer. I have no idea on > more cases should be handled during the inference itself though.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -0,0 +1,2450 @@ +// 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. + +#include "../precomp.hpp" +#include "../net_impl.hpp" + +#include <opencv2/dnn/shape_utils.hpp> +#include <opencv2/dnn/layer_reg.private.hpp> ```
there is `Net::newConstArg()` (and `Net::Impl::newConstArg()`) for that, which is a safe way to create new constant argument.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/matrix.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1110 **Code Changes:** ```diff return p; } +MatShape Mat::shape() const +{ + return dims == 0 && data == 0 ? MatShape() : MatShape(dims, size.p); +} Mat::Mat(Mat&& m) CV_NOEXCEPT : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), @@ -747,6 +1243,27 @@ void Mat::create(const std::vector<int>& _sizes, int _type) ```
disagree. For empty Mat we should return empty shape. This is very natural extension of the function domain that may eliminate some conditions and still keep the code absolutely safe.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1176 **Code Changes:** ```diff +/** @brief Broadcast the given Mat to the given shape. + * @param src input array + * @param shape target shape. Note that negative values are not supported. + * @param dst output array that has the given shape + */ +CV_EXPORTS void broadcast(InputArray src, const MatShape& shape, OutputArray dst); + enum RotateFlags { ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise ROTATE_180 = 1, //!<Rotate 180 degrees clockwise ```
this is overload of the previous function that preserves order of parameters
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/mat.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 171 **Code Changes:** ```diff + std::string str() const; + + int dims; + DataLayout layout; + int C; + int p[MAX_DIMS]; +}; + +CV_EXPORTS bool operator == (const MatShape& shape1, const MatShape& shape2); +CV_EXPORTS bool operator != (const MatShape& shape1, const MatShape& shape2); + ```
this is for compatibility with a lot of OpenCV code if we replace `MatSize size` inside `cv::Mat` with `MatShape size` at some point
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/graph_buffer_allocator.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 332 **Code Changes:** ```diff +}; + +void Net::Impl::assignBuffers() +{ + BufferAllocator buf_allocator(this); + buf_allocator.assign(); +} + +CV__DNN_INLINE_NS_END +}} ```
buffer allocation (or rather a buffer assignment) is crucial and necessary preprocessing stage in the new engine. Without it you cannot call forward. Some other stages, such as fusion, could be potentially disabled; this is TODO.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/operations.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 489 **Code Changes:** ```diff @@ -484,6 +485,11 @@ int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout) return print(Formatter::get()->format(cv::Mat(matx)), stream); } +// numpy/ONNXRuntime-style matrix pretty-printer +CV_EXPORTS std::ostream& pprint(std::ostream& strm, InputArray tensor, int indent=0, + int edge=3, int wholeTensorThreshold=100, + char parens='\0'); + //! @endcond ```
Better name is needed here.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -42,6 +42,7 @@ #ifndef OPENCV_DNN_DNN_HPP #define OPENCV_DNN_DNN_HPP +#include <ostream> #include <vector> #include <opencv2/core.hpp> #include "opencv2/core/async.hpp" @@ -61,7 +62,6 @@ CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn ```
I propose to use enum here: - old engine - new engine - auto (fallback). It makes regression testing easier and unblock other backends.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/convolution_layer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1432 **Code Changes:** ```diff BaseConvolutionLayerImpl::finalize(inputs_arr, outputs_arr); @@ -1420,6 +1429,11 @@ class DeConvolutionLayerImpl CV_FINAL : public BaseConvolutionLayerImpl inputs_arr.getMatVector(inputs); outputs_arr.getMatVector(outputs); + CV_Assert(inputs.size() > 1 || !blobs.empty()); + + MatShape weightShape = blobs.empty() ? inputs[1].shape() : blobs[0].shape(); + numOutput = weightShape[1]*groups; + std::vector<int> inpShape; ```
Why do you need assert here?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/convolution_layer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1875 **Code Changes:** ```diff - forward_ocl(inputs_arr, outputs_arr, internals_arr)); + // For some reason, tests for deconvolution fail; + // Also, the current implementation is super-inefficient, + // Just disabled it. Need to rewrite it and then uncomment back these lines + //CV_OCL_RUN(IS_DNN_OPENCL_TARGET(preferableTarget), + // forward_ocl(inputs_arr, outputs_arr, internals_arr)); - if (inputs_arr.depth() == CV_16F) + if (inputs_arr.depth(0) == CV_16F) { forward_fallback(inputs_arr, outputs_arr, internals_arr); ```
Please disable the test in the test name and file a bug about the issue.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/convolution_layer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1913 **Code Changes:** ```diff + pprint(std::cout, inputs[0], 0, 3, 100, '['); + printf("\nDeConvolution Weights: "); + pprint(std::cout, weightsMat, 0, 3, 100, '['); + printf("\nDeConvolution Bias: "); + pprint(std::cout, biasesMat, 0, 3, 100, '['); + printf("\n");*/ + + //for (size_t ii = 0; ii < outputs.size(); ii++) { - int ngroups = outCn / blobs[0].size[1]; - int inpGroupCn = inpCn / ngroups; ```
remove dead code.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/flatten_layer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -65,10 +65,14 @@ namespace dnn class FlattenLayerImpl CV_FINAL : public FlattenLayer { public: + bool _onnxMode; + FlattenLayerImpl(const LayerParams &params) { _startAxis = params.get<int>("axis", 1); _endAxis = params.get<int>("end_axis", -1); ```
please file github bug about it.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/reshape2_layer.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 68 **Code Changes:** ```diff + virtual bool dynamicOutputShapes() const CV_OVERRIDE + { + // [TODO] fix. If the 'shape' spec is attribute, + // or if shape is a constant 2nd input of the layer, + // then the output shape can be inferred from the input tensor shape. + // That is, dynamicShapeSpec is not quite incorrect. + return dynamicShapeSpec; + } + + virtual bool supportBackend(int backendId) CV_OVERRIDE + { ```
File github bug.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/ts/src/ts_func.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -1505,8 +1505,14 @@ double norm(InputArray _src1, InputArray _src2, int normType, InputArray _mask) normType = normType == NORM_L2SQR ? NORM_L2 : normType; CV_CheckTypeEQ(src1.type(), src2.type(), ""); - CV_Assert(src1.size == src2.size); - CV_Assert( mask.empty() || (src1.size == mask.size && (mask.type() == CV_8U || mask.type() == CV_Bool)) ); + MatShape shape1 = src1.shape(); + MatShape shape2 = src2.shape(); + if (shape1 != shape2) { + printf("shape1: %s\n", shape1.str().c_str()); ```
remove dead code.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_onnx_importer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 49 **Code Changes:** ```diff { std::vector<MatShape> inLayerShapes; std::vector<MatShape> outLayerShapes; - net.getLayerShapes(MatShape(), CV_32F, 0, inLayerShapes, outLayerShapes); + std::vector<MatShape> suggestedShapes; + std::vector<int> suggestedTypes; + for (const Mat& inp: inps) { + suggestedShapes.push_back(inp.shape()); + suggestedTypes.push_back(inp.type()); + } + net.getLayerShapes(suggestedShapes, suggestedTypes, 0, inLayerShapes, outLayerShapes); ```
call vector.reserve() to reduce mallocs.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_model.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 105 **Code Changes:** ```diff const std::string& inImgPath, const std::string& outImgPath, float norm, const Size& size = {-1, -1}, Scalar mean = Scalar(), - double scale = 1.0, bool swapRB = false, bool crop = false, const std::string outname = "") + double scale = 1.0, bool swapRB = false, bool crop = false, + const std::vector<std::string>& outnames=std::vector<std::string>()) { checkBackend(); @@ -115,8 +116,8 @@ class Test_Model : public DNNTestLayer model.setPreferableBackend(backend); model.setPreferableTarget(target); ```
is it used somewhere?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -231,7 +231,7 @@ void testReshape(const MatShape& inputShape, const MatShape& targetShape, runLayer(rl, inpVec, outVec); Mat& out = outVec[0]; - MatShape shape(out.size.p, out.size.p + out.dims); + MatShape shape = out.shape(); EXPECT_EQ(shape, targetShape); } @@ -502,9 +502,9 @@ TEST_F(Layer_LSTM_Test, get_set_test) ```
File a github bug.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_backends.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 520 **Code Changes:** ```diff #endif - expectNoFallbacksFromCUDA(net); + // BUG: https://github.com/opencv/opencv/issues/26306 + // Temporarily disabled check for no "fallbacks", since the new engine does not support CUDA yet + //expectNoFallbacksFromCUDA(net); } INSTANTIATE_TEST_CASE_P(/*nothing*/, DNNTestNetwork, dnnBackendsAndTargets(/* withInferenceEngine = */ true, ```
force old engine here?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl_fuse.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -662,6 +662,15 @@ void Net::Impl::fuseLayers(const std::vector<LayerPin>& blobsToKeep_) if (preferableBackend != DNN_BACKEND_OPENCV && preferableBackend != DNN_BACKEND_CUDA) continue; // Go to the next layer. + // [TODO] temporarily disabled Concat optimization. + // + // Ticket: https://github.com/opencv/opencv/issues/26195 + // + // It's not quite compatible with dynamic shapes, + // so we need to make sure that we correctly predicted shapes ```
File github bug
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 928 **Code Changes:** ```diff + +// [TODO] +// The current 'pure' shape inference is quite fragile, it does not handle any dynamic cases +// or even some seemingly dynamic cases. +// It would be nice maybe to some optional speculative forward() with some dummy inputs when +// straight-forward shape inference mechanism failed. +bool Net::Impl::tryInferGraphShapes(const Ptr<Graph>& graph, + std::vector<MatShape>& shapeCache, + std::vector<MatType>& typeCache) const +{ + if (!graph) ```
File github issue.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 556 **Code Changes:** ```diff + } + + for (int k = 0; k < mshape.dims; k++) { + checkAndUpdateDim(graph, Node(), inp, k, tsize.size[k]); + } + */ + + if (adata.kind == DNN_ARG_INPUT) { + int adata_type = adata.type; + if ((adata_type == CV_16F || adata_type == CV_16BF) && !enableFP16) + adata_type = CV_32F; ```
Need to be fixed before merge.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 556 **Code Changes:** ```diff + } + + for (int k = 0; k < mshape.dims; k++) { + checkAndUpdateDim(graph, Node(), inp, k, tsize.size[k]); + } + */ + + if (adata.kind == DNN_ARG_INPUT) { + int adata_type = adata.type; + if ((adata_type == CV_16F || adata_type == CV_16BF) && !enableFP16) + adata_type = CV_32F; ```
disagree. It's quite difficult to fix properly. It will surely breaks some test cases that just ignore shapes in the model and pass tensors with completely different shapes
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl_fuse.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -662,6 +662,15 @@ void Net::Impl::fuseLayers(const std::vector<LayerPin>& blobsToKeep_) if (preferableBackend != DNN_BACKEND_OPENCV && preferableBackend != DNN_BACKEND_CUDA) continue; // Go to the next layer. + // [TODO] temporarily disabled Concat optimization. + // + // Ticket: https://github.com/opencv/opencv/issues/26195 + // + // It's not quite compatible with dynamic shapes, + // so we need to make sure that we correctly predicted shapes ```
Concat optimization is incompatible with dynamic shapes. It will be disabled anyway in the new engine. So it's not a bug actually
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/convolution_layer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1432 **Code Changes:** ```diff BaseConvolutionLayerImpl::finalize(inputs_arr, outputs_arr); @@ -1420,6 +1429,11 @@ class DeConvolutionLayerImpl CV_FINAL : public BaseConvolutionLayerImpl inputs_arr.getMatVector(inputs); outputs_arr.getMatVector(outputs); + CV_Assert(inputs.size() > 1 || !blobs.empty()); + + MatShape weightShape = blobs.empty() ? inputs[1].shape() : blobs[0].shape(); + numOutput = weightShape[1]*groups; + std::vector<int> inpShape; ```
because we need deconvolution weights. They come as extra input or as a blob.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Code Changes:** ```diff @@ -42,6 +42,7 @@ #ifndef OPENCV_DNN_DNN_HPP #define OPENCV_DNN_DNN_HPP +#include <ostream> #include <vector> #include <opencv2/core.hpp> #include "opencv2/core/async.hpp" @@ -61,7 +62,6 @@ CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn ```
it's temporary solution. The boolean flag should be removed by 5.0 gold release, since there is a plan to completely migrate to the new engine.
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/operations.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 489 **Code Changes:** ```diff @@ -484,6 +485,11 @@ int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout) return print(Formatter::get()->format(cv::Mat(matx)), stream); } +// numpy/ONNXRuntime-style matrix pretty-printer +CV_EXPORTS std::ostream& pprint(std::ostream& strm, InputArray tensor, int indent=0, + int edge=3, int wholeTensorThreshold=100, + char parens='\0'); + //! @endcond ```
It's a very good name, see https://docs.python.org/3/library/pprint.html for example
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 556 **Code Changes:** ```diff + } + + for (int k = 0; k < mshape.dims; k++) { + checkAndUpdateDim(graph, Node(), inp, k, tsize.size[k]); + } + */ + + if (adata.kind == DNN_ARG_INPUT) { + int adata_type = adata.type; + if ((adata_type == CV_16F || adata_type == CV_16BF) && !enableFP16) + adata_type = CV_32F; ```
It means that the tests should be fixed.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 75 **Code Changes:** ```diff + enableFP16 = haveFP16 = false; + // FP16 is not ready yet in the new DNN engine + // Ticket: https://github.com/opencv/opencv/issues/26196 + /*if (checkHardwareSupport(CV_CPU_FP16)) { + enableFP16 = haveFP16 = true; + }*/ + + tracingMode = DNN_TRACE_NONE; + profilingMode = DNN_PROFILE_NONE; + + dump_strm = &std::cout; ```
the code belongs to the new engine, I do whatever I want with it. FP16 support in the new engine is not ready yet.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objc/generator/CMakeLists.txt **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 94 **Code Changes:** ```diff @@ -91,7 +91,7 @@ macro(ocv_add_objc_generated_target TARGET) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}") add_custom_command( OUTPUT ${objc_generated_files} "${objc_${TARGET}_generated_output_dependecy}" - COMMAND ${PYTHON_DEFAULT_EXECUTABLE} "${OBJC_SOURCE_DIR}/generator/gen_objc.py" + COMMAND ${PYTHON3_EXECUTABLE} "${OBJC_SOURCE_DIR}/generator/gen_objc.py" -p "${OBJC_SOURCE_DIR}/../python/src2/gen2.py" -c "${CONFIG_FILE}" -t "${TARGET}" ```
macos does not supply python 2.x for a long time already; the previous code causes compile errors. I fixed the bug and now ios framework is generated properly.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_onnx_importer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 49 **Code Changes:** ```diff { std::vector<MatShape> inLayerShapes; std::vector<MatShape> outLayerShapes; - net.getLayerShapes(MatShape(), CV_32F, 0, inLayerShapes, outLayerShapes); + std::vector<MatShape> suggestedShapes; + std::vector<int> suggestedTypes; + for (const Mat& inp: inps) { + suggestedShapes.push_back(inp.shape()); + suggestedTypes.push_back(inp.type()); + } + net.getLayerShapes(suggestedShapes, suggestedTypes, 0, inLayerShapes, outLayerShapes); ```
do you really want me to waste time optimizing tests? )
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_model.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 105 **Code Changes:** ```diff const std::string& inImgPath, const std::string& outImgPath, float norm, const Size& size = {-1, -1}, Scalar mean = Scalar(), - double scale = 1.0, bool swapRB = false, bool crop = false, const std::string outname = "") + double scale = 1.0, bool swapRB = false, bool crop = false, + const std::vector<std::string>& outnames=std::vector<std::string>()) { checkBackend(); @@ -115,8 +116,8 @@ class Test_Model : public DNNTestLayer model.setPreferableBackend(backend); model.setPreferableTarget(target); ```
yes, the previous implementation assumed that all semantic segmentation models produce a single output. Apparently, this is not the case with some models in OpenCV extra. Somehow this bug did not cause any problems in the old engine; the new engine is more strict.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/convolution_layer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1875 **Code Changes:** ```diff - forward_ocl(inputs_arr, outputs_arr, internals_arr)); + // For some reason, tests for deconvolution fail; + // Also, the current implementation is super-inefficient, + // Just disabled it. Need to rewrite it and then uncomment back these lines + //CV_OCL_RUN(IS_DNN_OPENCL_TARGET(preferableTarget), + // forward_ocl(inputs_arr, outputs_arr, internals_arr)); - if (inputs_arr.depth() == CV_16F) + if (inputs_arr.depth(0) == CV_16F) { forward_fallback(inputs_arr, outputs_arr, internals_arr); ```
Disabled test won't fix the broken implementation. I fixed it.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_backends.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 520 **Code Changes:** ```diff #endif - expectNoFallbacksFromCUDA(net); + // BUG: https://github.com/opencv/opencv/issues/26306 + // Temporarily disabled check for no "fallbacks", since the new engine does not support CUDA yet + //expectNoFallbacksFromCUDA(net); } INSTANTIATE_TEST_CASE_P(/*nothing*/, DNNTestNetwork, dnnBackendsAndTargets(/* withInferenceEngine = */ true, ```
the model works correctly with the new engine; but the extra check that verifies that the engine really used all CUDA layers fails. I think, using the new engine to test correct model processing is more important than switching to the old engine.
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_impl2.cpp **Change Type:** added **Context:** PR #26056: New dnn engine **Review Line:** 556 **Code Changes:** ```diff + } + + for (int k = 0; k < mshape.dims; k++) { + checkAndUpdateDim(graph, Node(), inp, k, tsize.size[k]); + } + */ + + if (adata.kind == DNN_ARG_INPUT) { + int adata_type = adata.type; + if ((adata_type == CV_16F || adata_type == CV_16BF) && !enableFP16) + adata_type = CV_32F; ```
that's a lot of work. Maybe another 2 weeks. If someone has that much time, please, go ahead. The new engine does no less sanity checks than the old engine and is more robust in general. The commented off code is some extra feature on top of the old engine; it can be polished and enabled in the later PRs after alpha.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/convolution_layer.cpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 92 **Code Changes:** ```diff -#ifdef HAVE_WEBNN - groups = ngroups; -#endif - CV_Assert(numOutput % ngroups == 0); + numOutput = -1; + groups = params.get<int>("group", 1); if (kernel_size.size() == 2) { kernel = Size(kernel_size[1], kernel_size[0]); @@ -122,18 +117,19 @@ class BaseConvolutionLayerImpl : public ConvolutionLayer ```
For asmorkalov: Need to check.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1176 **Code Changes:** ```diff +/** @brief Broadcast the given Mat to the given shape. + * @param src input array + * @param shape target shape. Note that negative values are not supported. + * @param dst output array that has the given shape + */ +CV_EXPORTS void broadcast(InputArray src, const MatShape& shape, OutputArray dst); + enum RotateFlags { ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise ROTATE_180 = 1, //!<Rotate 180 degrees clockwise ```
These is design requirement which is stated on Wiki contribution guidelines / coding style guide: 1. Input tensors 2. Output tensors 3. Other parameters. --- > overload of the previous function not related answer.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/mat.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 88 **Code Changes:** ```diff + DATA_LAYOUT_BLOCK = 7, //!< Block layout (also referred to as 'NC1HWC0'), which some accelerators need and even on CPU a better performance may be achieved. + + // for compatibility with the old code in DNN + DNN_LAYOUT_UNKNOWN = 0, + DNN_LAYOUT_ND = 1, //!< OpenCV data layout for 2D data. + DNN_LAYOUT_NCHW = 2, //!< OpenCV data layout for 4D data. + DNN_LAYOUT_NCDHW = 3, //!< OpenCV data layout for 5D data. + DNN_LAYOUT_NHWC = 4, //!< Tensorflow-like data layout for 4D data. + DNN_LAYOUT_NDHWC = 5, //!< Tensorflow-like data layout for 5D data. + DNN_LAYOUT_PLANAR = 6, //!< Tensorflow-like data layout, it should only be used at tf or tflite model parsing. + DNN_LAYOUT_BLOCK = 7, //!< Block layout (also referred to as 'NC1HWC0'), which some accelerators need and even on CPU a better performance may be achieved. ```
We should not have DNN-specific code in the `core` module.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core.hpp **Change Type:** modified **Context:** PR #26056: New dnn engine **Review Line:** 1176 **Code Changes:** ```diff +/** @brief Broadcast the given Mat to the given shape. + * @param src input array + * @param shape target shape. Note that negative values are not supported. + * @param dst output array that has the given shape + */ +CV_EXPORTS void broadcast(InputArray src, const MatShape& shape, OutputArray dst); + enum RotateFlags { ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise ROTATE_180 = 1, //!<Rotate 180 degrees clockwise ```
shape is overload of InputArray here. I would treat it as InputTensor too.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
OpenCV provides cv::normalize for it.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
You can use blobFromImageWithParams and remove own `preprocess` function.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
`FLT_MIN`?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
It's just dotProduct. You can use OpenCV impl.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
Why TopK? It's just Top1.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
reference is better here.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
The first element is used. I propose to replace the function parameter to `const std::vector<float>&` and check query emptiness on caller side.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
The dedicated function does not make a lot of sense. I propose to merge it inside of main.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.cpp **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Code Changes:** ```diff @@ -1,245 +1,372 @@ -// -// You can download a baseline ReID model and sample input from: -// https://github.com/ReID-Team/ReID_extra_testdata -// -// Authors of samples and Youtu ReID baseline: -// Xing Sun <winfredsun@tencent.com> -// Feng Zheng <zhengf@sustech.edu.cn> -// Xinyang Jiang <sevjiang@tencent.com> -// Fufu Yu <fufuyu@tencent.com> ```
Please refresh description with information about env variables.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.py **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Review Line:** 257 **Code Changes:** ```diff + label="Tracking" + labelSize, _ = cv.getTextSize(label, cv.FONT_HERSHEY_SIMPLEX, fontSize, fontThickness) + cv.rectangle(frame, (0, 0), (labelSize[0]+10, labelSize[1]+10), (255,255,255), cv.FILLED) + cv.putText(frame, label, (10, int(25*fontSize)), cv.FONT_HERSHEY_SIMPLEX, fontSize, (0, 0, 0), fontThickness) + cv.imshow("TRACKING", frame) + if cv.waitKey(1) & 0xFF in [ord('q'), 27]: + break + + cap.release() + cv.destroyAllWindows() + return ```
`if cv.waitKey(1) in [ord('q'), 27]:`
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/person_reid.py **Change Type:** modified **Context:** PR #25667: Improved person reid cpp and python sample **Review Line:** 220 **Code Changes:** ```diff + cv.rectangle(image, (0, 0), (labelSize[0]+10, labelSize[1]+int(30*fontSize)), (255,255,255), cv.FILLED) + cv.putText(image, label, (10, int(25*fontSize)), cv.FONT_HERSHEY_SIMPLEX, fontSize, (0, 0, 0), fontThickness) + cv.putText(image, "Press space bar after selecting.", (10, int(50*fontSize)), cv.FONT_HERSHEY_SIMPLEX, fontSize, (0, 0, 0), fontThickness) + cv.imshow('TRACKING', image) + + key = cv.waitKey(100) & 0xFF + if key == ord(' '): + rect = cv.selectROI("TRACKING", image) + if rect: + x, y, w, h = rect + query_image = image[y:y + h, x:x + w] ```
`key = cv.waitKey(100)`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/imgwarp.cpp **Change Type:** modified **Context:** PR #26271: imgproc: add optimized warpPerspective linear kernels for inputs of type CV_8U/16U/32F+C1/C3/C4 **Review Line:** 2375 **Code Changes:** ```diff const char * const kernelName = op_type == OCL_OP_AFFINE ? "warpAffine" : "warpPerspective"; int scalarcn = cn == 3 ? 4 : cn; - bool is32f = !dev.isAMD() && (interpolation == INTER_CUBIC || interpolation == INTER_LINEAR) && op_type == OCL_OP_AFFINE; + bool is32f = op_type == OCL_OP_AFFINE ? + /* Affine*/ !dev.isAMD() && (interpolation == INTER_CUBIC || interpolation == INTER_LINEAR) : + /* Perspective*/ interpolation == INTER_LINEAR; int wdepth = interpolation == INTER_NEAREST ? depth : std::max(is32f ? CV_32F : CV_32S, depth); int sctype = CV_MAKETYPE(wdepth, scalarcn); @@ -2385,8 +2388,7 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0, ```
do we still have AMD-specific OpenCL kernel for warpAffine? If not, the condition should be updated.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/imgwarp.cpp **Change Type:** modified **Context:** PR #26271: imgproc: add optimized warpPerspective linear kernels for inputs of type CV_8U/16U/32F+C1/C3/C4 **Review Line:** 2375 **Code Changes:** ```diff const char * const kernelName = op_type == OCL_OP_AFFINE ? "warpAffine" : "warpPerspective"; int scalarcn = cn == 3 ? 4 : cn; - bool is32f = !dev.isAMD() && (interpolation == INTER_CUBIC || interpolation == INTER_LINEAR) && op_type == OCL_OP_AFFINE; + bool is32f = op_type == OCL_OP_AFFINE ? + /* Affine*/ !dev.isAMD() && (interpolation == INTER_CUBIC || interpolation == INTER_LINEAR) : + /* Perspective*/ interpolation == INTER_LINEAR; int wdepth = interpolation == INTER_NEAREST ? depth : std::max(is32f ? CV_32F : CV_32S, depth); int sctype = CV_MAKETYPE(wdepth, scalarcn); @@ -2385,8 +2388,7 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0, ```
> do we still have AMD-specific OpenCL kernel for warpAffine? There is conditional compilation with `AMD_DEVICE` in the cubic interpolation affine kernel: https://github.com/opencv/opencv/blob/8e5dbc03fe0c8264e667de5bbae4d0ab04dcab6b/modules/imgproc/src/opencl/warp_affine.cl#L233-L245 https://github.com/opencv/opencv/blob/8e5dbc03fe0c8264e667de5bbae4d0ab04dcab6b/modules/imgproc/src/opencl/warp_affine.cl#L264-L283
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/hal/intrin_wasm.hpp **Change Type:** modified **Context:** PR #25909: Update intrin_wasm.hpp **Review Line:** 20 **Code Changes:** ```diff +// __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__ and __EMSCRIPTEN_tiny__ are defined via commandline in +// https://github.com/emscripten-core/emscripten/blob/1690a5802cd1241adc9714fb7fa2f633d38860dc/tools/shared.py#L506-L515 +// +// See https://github.com/opencv/opencv/pull/25909 +#ifndef __EMSCRIPTEN_major__ +#include <emscripten/version.h> +#endif + #define CV_SIMD128 1 #define CV_SIMD128_64F 0 // Now all implementation of f64 use fallback, so disable it. #define CV_SIMD128_FP16 0 ```
Line 11 do the same (and fail). I triggered `javascript-simd` build configuration. It is based on EMSDK 2.0.13. PR: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100452 4.x (also fail): https://pullrequest.opencv.org/buildbot/builders/4_x_javascript-simd-emscripten-lin64/builds/100077