1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

onnx coverage

This commit is contained in:
Abhishek Gola
2026-07-14 19:47:32 +05:30
parent 2d2611d5bd
commit ae392712b1
3 changed files with 21 additions and 4 deletions
+3 -2
View File
@@ -52,7 +52,8 @@ public:
}
else
{
out.assign(1, MatShape(1, 1));
// Reduced (mean/sum) loss is a rank-0 scalar in ONNX, not a [1] tensor.
out.assign(1, MatShape::scalar());
}
return false;
}
@@ -164,7 +165,7 @@ public:
}
}
const float out = (reduction == LOSS_REDUCTION_SUM) ? static_cast<float>(num) : static_cast<float>((den > 0.0) ? (num / den) : 0.0);
out_loss.at<float>(0) = out;
out_loss.ptr<float>()[0] = out;
}
}
@@ -49,7 +49,8 @@ public:
for (size_t i = 2; i < x.size(); ++i) y.push_back(x[i]);
out.push_back(y);
} else {
out.push_back(MatShape(1,1));
// Reduced (mean/sum) loss is a rank-0 scalar in ONNX, not a [1] tensor.
out.push_back(MatShape::scalar());
}
if (requiredOutputs >= 2)
@@ -325,7 +326,7 @@ public:
const float out = (reduction == LOSS_REDUCTION_SUM) ? static_cast<float>(num)
: static_cast<float>((den > 0.0) ? (num / den) : 0.0);
out_loss.at<float>(0) = out;
out_loss.ptr<float>()[0] = out;
}
}
+15
View File
@@ -316,7 +316,22 @@ template<>
PyObject* pyopencv_from(const cv::Mat& m)
{
if( !m.data )
{
// Shaped Mat with a zero-length dim: return a matching empty array, not None.
if( m.dims >= 1 )
{
int cn = m.channels();
int typenum = cvDepthToNumpyType(m.depth());
int dims = m.dims;
cv::AutoBuffer<npy_intp> _sizes(dims + 1);
for( int i = 0; i < dims; i++ )
_sizes[i] = (npy_intp)m.size[i];
if( cn > 1 )
_sizes[dims++] = cn;
return PyArray_SimpleNew(dims, _sizes.data(), typenum);
}
Py_RETURN_NONE;
}
// 0D (scalar) Mat: return a true 0D numpy array.
if( m.dims == 0 )
{