mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
replace Qualcomm yolov3.onnx with darknet-converted yolov3
This commit is contained in:
@@ -332,26 +332,19 @@ TEST_P(Test_Model, YOLOv3)
|
||||
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
|
||||
// The in-graph YOLO decode (Split) is not evaluable by the OpenVINO backend.
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
|
||||
std::string model_file = _tf("yolov3.onnx", false);
|
||||
std::string img_path = _tf("dog416.png"); // Matches standard YOLO inference classes
|
||||
checkBackend();
|
||||
|
||||
// Extracted from original flat ref_ array: batchId, classId, confidence, left, top, right, bottom
|
||||
std::vector<int> refClassIds = {7, 16, 1};
|
||||
std::vector<float> refConfidences = {0.606292f, 0.55195f, 0.433444f};
|
||||
|
||||
// Rect2d requires (x, y, width, height) format
|
||||
std::vector<int> refClassIds = {16, 1, 7};
|
||||
std::vector<float> refConfidences = {0.998835f, 0.987915f, 0.952998f};
|
||||
std::vector<Rect2d> refBoxes = {
|
||||
Rect2d(0.612037f, 0.149921f, 0.910763f - 0.612037f, 0.300503f - 0.149921f), // Class 7
|
||||
Rect2d(0.170690f, 0.356024f, 0.471459f - 0.170690f, 0.877178f - 0.356024f), // Class 16
|
||||
Rect2d(0.199235f, 0.301175f, 0.753253f - 0.199235f, 0.744156f - 0.301175f) // Class 1
|
||||
Rect2d(0.160018f, 0.389962f, 0.257871f, 0.553753f),
|
||||
Rect2d(0.150904f, 0.221934f, 0.591361f, 0.524322f),
|
||||
Rect2d(0.614625f, 0.150259f, 0.286741f, 0.138992f),
|
||||
};
|
||||
|
||||
// Setting precision tolerances
|
||||
double scoreDiff = 8e-5, iouDiff = 3e-4;
|
||||
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
|
||||
{
|
||||
@@ -364,16 +357,49 @@ TEST_P(Test_Model, YOLOv3)
|
||||
iouDiff = 0.03;
|
||||
}
|
||||
|
||||
// Model parameters
|
||||
double confThreshold = 0.24;
|
||||
double nmsThreshold = 0.4;
|
||||
Size size{640, 640};
|
||||
double scale = 1.0 / 255.0; // Standard image scaling for YOLO models
|
||||
Scalar mean = Scalar();
|
||||
bool swapRB = true; // YOLO expects RGB
|
||||
const float confThreshold = 0.5f, nmsThreshold = 0.4f;
|
||||
const Size inputSize(416, 416);
|
||||
|
||||
testDetectModel(model_file, "", img_path, refClassIds, refConfidences, refBoxes,
|
||||
scoreDiff, iouDiff, confThreshold, nmsThreshold, size, mean, scale, swapRB);
|
||||
Mat img = imread(_tf("dog416.png"));
|
||||
cv::resize(img, img, inputSize);
|
||||
Mat blob = blobFromImage(img, 1.0 / 255.0, inputSize, Scalar(), true, false);
|
||||
|
||||
Net net = readNet(_tf("yolov3.onnx", false));
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
net.setInput(blob);
|
||||
std::vector<Mat> outs;
|
||||
net.forward(outs, net.getUnconnectedOutLayersNames());
|
||||
|
||||
int numBoxes = (int)(outs[0].total() / 4);
|
||||
Mat boxesMat = outs[0].reshape(1, numBoxes);
|
||||
Mat confsMat = outs[1].reshape(1, numBoxes);
|
||||
|
||||
std::vector<Rect2d> boxes;
|
||||
std::vector<float> confidences;
|
||||
std::vector<int> classIds;
|
||||
for (int j = 0; j < numBoxes; ++j)
|
||||
{
|
||||
Mat scores = confsMat.row(j);
|
||||
double confidence; Point maxLoc;
|
||||
minMaxLoc(scores, 0, &confidence, 0, &maxLoc);
|
||||
if (confidence >= confThreshold)
|
||||
{
|
||||
float* b = boxesMat.ptr<float>(j);
|
||||
boxes.emplace_back(b[0], b[1], b[2] - b[0], b[3] - b[1]);
|
||||
confidences.push_back((float)confidence);
|
||||
classIds.push_back(maxLoc.x);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> keep;
|
||||
NMSBoxes(boxes, confidences, confThreshold, nmsThreshold, keep);
|
||||
|
||||
std::vector<Rect2d> nmsBoxes; std::vector<float> nmsConfs; std::vector<int> nmsCls;
|
||||
for (int k : keep) { nmsBoxes.push_back(boxes[k]); nmsConfs.push_back(confidences[k]); nmsCls.push_back(classIds[k]); }
|
||||
|
||||
normAssertDetections(refClassIds, refConfidences, refBoxes,
|
||||
nmsCls, nmsConfs, nmsBoxes, "", confThreshold, scoreDiff, iouDiff);
|
||||
}
|
||||
|
||||
TEST_P(Test_Model, Keypoints_pose)
|
||||
|
||||
Reference in New Issue
Block a user