mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
Merge pull request #23646 from dkurt:dnn_ie_region_fix
Fix Region layer with OpenVINO in case of different width/height
This commit is contained in:
commit
b122a4b436
@ -526,14 +526,14 @@ public:
|
||||
|
||||
std::vector<float> x_indices(w * h * anchors);
|
||||
auto begin = x_indices.begin();
|
||||
for (int i = 0; i < h; i++)
|
||||
for (int i = 0; i < w; i++)
|
||||
{
|
||||
std::fill(begin + i * anchors, begin + (i + 1) * anchors, i);
|
||||
}
|
||||
|
||||
for (int j = 1; j < w; j++)
|
||||
for (int j = 1; j < h; j++)
|
||||
{
|
||||
std::copy(begin, begin + h * anchors, begin + j * h * anchors);
|
||||
std::copy(begin, begin + w * anchors, begin + j * w * anchors);
|
||||
}
|
||||
auto horiz = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, box_broad_shape, x_indices.data());
|
||||
box_x = std::make_shared<ngraph::op::v1::Add>(box_x, horiz, ngraph::op::AutoBroadcastType::NUMPY);
|
||||
|
@ -181,12 +181,21 @@ public:
|
||||
const std::vector<std::vector<float> >& refConfidences,
|
||||
const std::vector<std::vector<Rect2d> >& refBoxes,
|
||||
double scoreDiff, double iouDiff, float confThreshold = 0.24,
|
||||
float nmsThreshold = 0.4, bool useWinograd = true)
|
||||
float nmsThreshold = 0.4, bool useWinograd = true,
|
||||
int zeroPadW = 0)
|
||||
{
|
||||
checkBackend();
|
||||
|
||||
Mat img1 = imread(_tf("dog416.png"));
|
||||
Mat img2 = imread(_tf("street.png"));
|
||||
cv::resize(img2, img2, Size(416, 416));
|
||||
|
||||
// Pad images by black pixel at the right to test not equal width and height sizes
|
||||
if (zeroPadW) {
|
||||
cv::copyMakeBorder(img1, img1, 0, 0, 0, zeroPadW, BORDER_CONSTANT);
|
||||
cv::copyMakeBorder(img2, img2, 0, 0, 0, zeroPadW, BORDER_CONSTANT);
|
||||
}
|
||||
|
||||
std::vector<Mat> samples(2);
|
||||
samples[0] = img1; samples[1] = img2;
|
||||
|
||||
@ -195,7 +204,7 @@ public:
|
||||
CV_Assert(batch_size == 1 || batch_size == 2);
|
||||
samples.resize(batch_size);
|
||||
|
||||
Mat inp = blobFromImages(samples, 1.0/255, Size(416, 416), Scalar(), true, false);
|
||||
Mat inp = blobFromImages(samples, 1.0/255, Size(), Scalar(), true, false);
|
||||
|
||||
Net net = readNet(findDataFile("dnn/" + cfg),
|
||||
findDataFile("dnn/" + weights, false));
|
||||
@ -275,6 +284,14 @@ public:
|
||||
continue;
|
||||
}
|
||||
|
||||
// Return predictions from padded image to the origin
|
||||
if (zeroPadW) {
|
||||
float scale = static_cast<float>(inp.size[3]) / (inp.size[3] - zeroPadW);
|
||||
for (auto& box : nms_boxes) {
|
||||
box.x *= scale;
|
||||
box.width *= scale;
|
||||
}
|
||||
}
|
||||
normAssertDetections(refClassIds[b], refConfidences[b], refBoxes[b], nms_classIds,
|
||||
nms_confidences, nms_boxes, format("batch size %d, sample %d\n", batch_size, b).c_str(), confThreshold, scoreDiff, iouDiff);
|
||||
}
|
||||
@ -285,18 +302,20 @@ public:
|
||||
const std::vector<float>& refConfidences,
|
||||
const std::vector<Rect2d>& refBoxes,
|
||||
double scoreDiff, double iouDiff, float confThreshold = 0.24,
|
||||
float nmsThreshold = 0.4, bool useWinograd = true)
|
||||
float nmsThreshold = 0.4, bool useWinograd = true,
|
||||
int zeroPadW = 0)
|
||||
{
|
||||
testDarknetModel(cfg, weights,
|
||||
std::vector<std::vector<int> >(1, refClassIds),
|
||||
std::vector<std::vector<float> >(1, refConfidences),
|
||||
std::vector<std::vector<Rect2d> >(1, refBoxes),
|
||||
scoreDiff, iouDiff, confThreshold, nmsThreshold, useWinograd);
|
||||
scoreDiff, iouDiff, confThreshold, nmsThreshold, useWinograd, zeroPadW);
|
||||
}
|
||||
|
||||
void testDarknetModel(const std::string& cfg, const std::string& weights,
|
||||
const cv::Mat& ref, double scoreDiff, double iouDiff,
|
||||
float confThreshold = 0.24, float nmsThreshold = 0.4, bool useWinograd = true)
|
||||
float confThreshold = 0.24, float nmsThreshold = 0.4, bool useWinograd = true,
|
||||
int zeroPadW = 0)
|
||||
{
|
||||
CV_Assert(ref.cols == 7);
|
||||
std::vector<std::vector<int> > refClassIds;
|
||||
@ -323,7 +342,7 @@ public:
|
||||
refBoxes[batchId].push_back(box);
|
||||
}
|
||||
testDarknetModel(cfg, weights, refClassIds, refScores, refBoxes,
|
||||
scoreDiff, iouDiff, confThreshold, nmsThreshold, useWinograd);
|
||||
scoreDiff, iouDiff, confThreshold, nmsThreshold, useWinograd, zeroPadW);
|
||||
}
|
||||
};
|
||||
|
||||
@ -767,6 +786,8 @@ TEST_P(Test_Darknet_nets, YOLOv4)
|
||||
{
|
||||
SCOPED_TRACE("batch size 1");
|
||||
testDarknetModel(config_file, weights_file, ref.rowRange(0, N0), scoreDiff, iouDiff, 0.24, 0.4, false);
|
||||
// Test not equal width and height applying zero padding
|
||||
testDarknetModel(config_file, weights_file, ref.rowRange(0, N0), 0.006, 0.008, 0.24, 0.4, false, /*zeroPadW*/ 32);
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user