FlattenLayerImpl::finalize previously overwrote _startAxis and _endAxis
with normalize_axis(..., numAxes) for the rank of the first input.
Since end_axis defaults to -1 (and axis can also be negative), this
replaced relative negative indices with positive indices bound to the
first input rank.
Reusing the same Flatten layer on an input of a different rank then:
- flattened the wrong range of dimensions when rank increased (e.g.
[2, 3, 4, 5] flattened to [2, 12, 5] instead of [2, 60] for default
axis=1, end_axis=-1), or
- triggered an assertion failure in normalize_axis when rank decreased
(e.g. stale end_axis=3 on a 3D input).
getMemoryShapes, initCann, and initNgraph already normalize _startAxis
and _endAxis locally, and forward/forward_ocl/initCUDA use the output
shapes directly. Keep _startAxis and _endAxis unchanged in finalize
while still validating the normalized axis range.
GatherElementsLayerImpl::finalize previously normalized the axis attribute
by overwriting this->axis with normalize_axis(axis, data.dims).
When the layer was created with a negative axis (such as -1, supported by
the ONNX GatherElements specification), this replaced the relative index
with a positive index fixed to the rank of the first input.
Subsequent evaluations on an input of different rank on the same layer then:
- evaluated GatherElements along the wrong axis (e.g. axis 1 instead of axis 2
when moving from a 2D tensor to a 3D tensor), leading to silent data corruption, or
- triggered an assertion failure in normalize_axis (e.g. axis 2 on a 2D tensor
when moving from a 3D tensor to a 2D tensor).
Fix this by keeping this->axis unmodified and storing the normalized axis
separately for execution. Add regression tests covering both decreasing and
increasing rank on the same GatherElements layer instance.
TopKLayerImpl::finalize previously normalized the axis attribute by
overwriting this->axis with normalize_axis(axis, input_shape.size()).
When the layer was created with a negative axis (such as the default -1),
this replaced the relative index with a positive index fixed to the rank
of the first input.
Subsequent runs on an input of different rank then either:
- evaluated TopK along the wrong axis (e.g. axis 1 instead of axis 2
when moving from a 2D tensor to a 3D tensor), or
- triggered an out-of-range assertion in getMemoryShapes (e.g. axis 2
on a 2D tensor when moving from a 3D tensor to a 2D tensor).
Fix this by keeping this->axis unmodified and storing the normalized axis
separately for execution. Add unit tests for both increasing and decreasing
rank inputs on the same TopK layer instance.
* dnn: repack the convolution when SAME padding changes after a reshape
* dnn: rebuild the packed convolution in every finalize()
forward() packs fastConvImpl with the pads and the Winograd choice that
finalize() computes, and with weightsMat, into which fuseLayers() may
still fold BatchNorm. finalize() kept the pack whenever the Winograd
choice was unchanged, so a SAME convolution kept the old padding after a
reshape, and a convolution kept BatchNorm folded in after
enableFusion(false). Reset it in every finalize(), as convolutionOp is.
Also print the target as int in the test message (-Wsign-promo).
* dnn: drop the OpenCL case from the reshape test
The OpenCL path never uses fastConvImpl, so the case passed on 4.x too.
MVN, LayerNormalization, InstanceNormalization and GroupNormalization took
the variance of each row as E[x^2] - E[x]^2 in float. When the mean is large
against the spread the two terms cancel: from about 1000 standard deviations
the variance comes out as 0 and the outputs are scaled by 1/sqrt(eps).
Keep the one-pass result for ordinary rows. When mean^2 > 64 * var, measure
the row again from d = x - mean, summed in double: mean += E[d],
var = E[d^2] - E[d]^2.
GemmLayerImpl::initCUDA() called cv::transpose(B, B) on a shallow view of blobs[0]. When B is square (K == N) and transB is false, cv::transpose reuses the buffer in-place, mutating blobs[0] on the first forward() and transposing it back on a subsequent batch-size reshape. Transpose into a separate Mat before constructing InnerProductOp.
* dnn: fix Reduce over three or more axes
Port of #30108 (5.x, reduce2_layer.cpp) to the 4.x Reduce layer.
ReduceInvoker walks the reduced block with an odometer over every reduced axis but the innermost one. On a carry it assigned the step of the next outer axis (j - 1) instead of removing the offset of the axis that wrapped and adding one step of the next. projected_steps is shared by all output elements, so once an outer reduced axis has three or more elements every output was wrong. Carry the same way as the unprojected axes below. This also makes test_mvn_expanded pass, so it is removed from the parser denylist.
* dnn: parameterize the Reduce multi-axis regression test
Pass each (sizes, axes) case to TEST_P instead of looping inside one TEST.
* dnn: test LogSoftmax far below the maximum
LogSoftmax must give x - max - log(sum(exp(x - max))) for values about 104 or more below the row maximum, where exp underflows in float32. Covers a short row and one long enough for the SIMD loops. See #30544.
* dnn: compute LogSoftmax without taking the log of softmax
logSoftmax() took the log of the softmax output, so elements whose exp(x - max) underflows came out as -inf. The softmax kernel already has the row maximum and the sum of exp(x - max), so the log path now writes (x - max) - log(sum) directly. Subtracting max first keeps rows of large, close values exact, as in test_logsoftmax_large_number.
Fixes#30544
* dnn: pass the LogSoftmax flag to softmax() instead of a separate function
Address review: softmax() takes a logSoftmax flag with a default of false, and logSoftmax() calls it with true.
* dnn: run the LogSoftmax underflow test on the OpenCL targets
The test now runs for every target of the OpenCV backend, and uses the default FP16 thresholds for the FP16 targets.
* dnn: compute LogSoftmax in the OpenCL kernels without taking the log of softmax
With LOG_SOFTMAX, the kernels kept exp(x - max) and returned log(exp(x - max) / sum), which is -inf once exp underflows. They now keep x - max, add up exp(x - max), and return x - max - log(sum), like the CPU path. This covers the generic kernels in softmax.cl and the subgroup kernels in softmax_loss.cl.
dnn: fix packed-B offsets for broadcast batched MatMul
When the constant B of a MatMul has more than one batch slice but fewer than the output batch (B broadcasts over A's leading dims), updatePackedBOffsets derived the packed slice stride from the output batch, so every slice after the first read the wrong packed data. matmul_layer.cpp now passes fastGemmPackBSize(N, K, opt), the size of one packed slice, as the stride.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
resolves https://github.com/opencv/opencv/issues/27580
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Fixed ReduceMean layer behaviour #25120
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
a93c31e3c9/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc (L433-L443)
Supporting protobuf v22 and later(with abseil-cpp/C++17) #24372
fix https://github.com/opencv/opencv/issues/24369
related https://github.com/opencv/opencv/issues/23791
1. This patch supports external protobuf v22 and later, it required abseil-cpp and c++17.
Even if the built-in protobuf is upgraded to v22 or later,
the dependency on abseil-cpp and the requirement for C++17 will continue.
2. Some test for caffe required patched protobuf, so this patch disable them.
This patch is tested by following libraries.
- Protobuf: /usr/local/lib/libprotobuf.so (4.24.4)
- abseil-cpp: YES (20230125)
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
TFLite models on different backends (tests and improvements) #24039
### Pull Request Readiness Checklist
* MaxUnpooling with OpenVINO
* Fully connected with transposed inputs/weights with OpenVINO
* Enable backends tests for TFLite (related to https://github.com/opencv/opencv/issues/23992#issuecomment-1640691722)
* Increase existing tests thresholds
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Switch to new OpenVINO API after 2022.1 release
* Pass Layer_Test_Convolution_DLDT.Accuracy/0 test
* Pass test Test_Caffe_layers.Softmax
* Failed 136 tests
* Fix Concat. Failed 120 tests
* Custom nGraph ops. 19 failed tests
* Set and get properties from Core
* Read model from buffer
* Change MaxPooling layer output names. Restore reshape
* Cosmetic changes
* Cosmetic changes
* Override getOutputsInfo
* Fixes for OpenVINO < 2022.1
* Async inference for 2021.4 and less
* Compile model with config
* Fix serialize for 2022.1
* Asynchronous inference with 2022.1
* Handle 1d outputs
* Work with model with dynamic output shape
* Fixes with 1d output for old API
* Control outputs by nGraph function for all OpenVINO versions
* Refer inputs in PrePostProcessor by indices
* Fix cycled dependency between InfEngineNgraphNode and InfEngineNgraphNet.
Add InferRequest callback only for async inference. Do not capture InferRequest object.
* Fix tests thresholds
* Fix HETERO:GPU,CPU plugin issues with unsupported layer
Support non-zero hidden state for LSTM
* fully support non-zero hidden state for LSTM
* check dims of hidden state for LSTM
* fix failed test Test_Model.TextRecognition
* add new tests for LSTM w/ non-zero hidden params
Co-authored-by: Julie Bareeva <julia.bareeva@xperience.ai>