mirror of
https://github.com/hybridgroup/gocv
synced 2026-04-23 00:37:07 +08:00
test: update tests for OpenCV 4.13
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -43,10 +43,10 @@ jobs:
|
||||
- name: Install ONNX test model
|
||||
run: |
|
||||
mkdir -p ${GITHUB_WORKSPACE}/testdata
|
||||
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx > ${GITHUB_WORKSPACE}/testdata/object_tracking_vittrack_2023sep.onnx
|
||||
curl -sL https://huggingface.co/onnxmodelzoo/legacy_models/resolve/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
|
||||
curl -sL https://huggingface.co/opencv/face_recognition_sface/resolve/main/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://huggingface.co/opencv/face_detection_yunet/resolve/main/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://huggingface.co/opencv/object_tracking_vittrack/resolve/main/object_tracking_vittrack_2023sep.onnx > ${GITHUB_WORKSPACE}/testdata/object_tracking_vittrack_2023sep.onnx
|
||||
- name: Run main tests
|
||||
run: xvfb-run -a --error-file /var/log/xvfb_error.log --server-args="-screen 0 1024x768x24 +extension RANDR" go test -v -coverprofile=/tmp/coverage.out -count=1 -tags matprofile .
|
||||
env:
|
||||
|
||||
@@ -49,10 +49,10 @@ jobs:
|
||||
- name: Install ONNX test model
|
||||
run: |
|
||||
mkdir -p ${GITHUB_WORKSPACE}/testdata
|
||||
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx > ${GITHUB_WORKSPACE}/testdata/object_tracking_vittrack_2023sep.onnx
|
||||
curl -sL https://huggingface.co/onnxmodelzoo/legacy_models/resolve/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
|
||||
curl -sL https://huggingface.co/opencv/face_recognition_sface/resolve/main/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://huggingface.co/opencv/face_detection_yunet/resolve/main/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://huggingface.co/opencv/object_tracking_vittrack/resolve/main/object_tracking_vittrack_2023sep.onnx > ${GITHUB_WORKSPACE}/testdata/object_tracking_vittrack_2023sep.onnx
|
||||
- name: Run main tests
|
||||
run: go test -v -tags matprofile .
|
||||
env:
|
||||
|
||||
@@ -89,10 +89,10 @@ jobs:
|
||||
unzip -o ./testdata/inception5h.zip tensorflow_inception_graph.pb -d ./testdata
|
||||
- name: Install ONNX test model
|
||||
run: |
|
||||
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ./testdata/googlenet-9.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ./testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ./testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx > ./testdata/object_tracking_vittrack_2023sep.onnx
|
||||
curl -sL https://huggingface.co/onnxmodelzoo/legacy_models/resolve/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ./testdata/googlenet-9.onnx
|
||||
curl -sL https://huggingface.co/opencv/face_recognition_sface/resolve/main/face_recognition_sface_2021dec.onnx > ./testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://huggingface.co/opencv/face_detection_yunet/resolve/main/face_detection_yunet_2023mar.onnx > ./testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://huggingface.co/opencv/object_tracking_vittrack/resolve/main/object_tracking_vittrack_2023sep.onnx > ./testdata/object_tracking_vittrack_2023sep.onnx
|
||||
- name: Install GOTURN test model
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
@@ -193,12 +193,35 @@ void Net_GetUnconnectedOutLayers(Net net, IntVector* res) {
|
||||
void Net_GetLayerNames(Net net, CStrings* names) {
|
||||
try {
|
||||
std::vector< cv::String > cstrs(net->getLayerNames());
|
||||
const char **strs = new const char*[cstrs.size()];
|
||||
|
||||
for (size_t i = 0; i < cstrs.size(); ++i) {
|
||||
strs[i] = cstrs[i].c_str();
|
||||
size_t totalStrLen = 0;
|
||||
for (cv::String str : cstrs) {
|
||||
totalStrLen += str.size();
|
||||
}
|
||||
|
||||
|
||||
// Compute 1D buffer size required to store
|
||||
// 2D array of null-terminated strings
|
||||
size_t numStrings = cstrs.size();
|
||||
size_t bufferLen = numStrings * sizeof(char*) + (totalStrLen + numStrings) * sizeof(char);
|
||||
|
||||
const char **strs = (const char**)new char[bufferLen];
|
||||
memset(strs, 0, bufferLen);
|
||||
|
||||
char* it = (char*)(strs + cstrs.size());
|
||||
const char* end = (char*)(strs) + bufferLen;
|
||||
|
||||
for (size_t i = 0; i < numStrings; ++i, ++it) {
|
||||
strs[i] = it;
|
||||
size_t strlen = cstrs[i].size();
|
||||
|
||||
// Avoid buffer overrun
|
||||
if(end < it + strlen + 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(it, cstrs[i].c_str(), strlen);
|
||||
it += strlen;
|
||||
}
|
||||
|
||||
names->length = cstrs.size();
|
||||
names->strs = strs;
|
||||
} catch(const cv::Exception& e){
|
||||
|
||||
+86
-5
@@ -64,7 +64,24 @@ func TestReadNetDiskFromONNX(t *testing.T) {
|
||||
}
|
||||
defer net.Close()
|
||||
|
||||
checkONNXNet(t, net)
|
||||
m := map[int]string{
|
||||
0: "onnx_node_output_0!conv1/7x7_s2_1",
|
||||
10: "onnx_node_output_0!inception_3a/1x1_1",
|
||||
20: "onnx_node_output_0!inception_3a/pool_1",
|
||||
30: "onnx_node_output_0!inception_3b/5x5_reduce_1",
|
||||
40: "onnx_node_output_0!inception_4a/1x1_2",
|
||||
50: "onnx_node_output_0!inception_4a/pool_proj_1",
|
||||
60: "onnx_node_output_0!inception_4b/5x5_reduce_2",
|
||||
70: "onnx_node_output_0!inception_4c/3x3_reduce_2",
|
||||
80: "onnx_node_output_0!inception_4c/output_1",
|
||||
90: "onnx_node_output_0!inception_4d/5x5_2",
|
||||
100: "onnx_node_output_0!inception_4e/3x3_2",
|
||||
110: "onnx_node_output_0!inception_5a/1x1_1",
|
||||
120: "onnx_node_output_0!inception_5a/pool_1",
|
||||
130: "onnx_node_output_0!inception_5b/5x5_reduce_1",
|
||||
140: "onnx_node_output_0!OC2_DUMMY_0"}
|
||||
|
||||
checkONNXNet(t, net, m, 144)
|
||||
}
|
||||
|
||||
func TestReadNetMemoryFromONNX(t *testing.T) {
|
||||
@@ -91,7 +108,25 @@ func TestReadNetMemoryFromONNX(t *testing.T) {
|
||||
t.Errorf("Unable to load Caffe model using ReadNetBytes")
|
||||
}
|
||||
defer net.Close()
|
||||
checkONNXNet(t, net)
|
||||
|
||||
m := map[int]string{
|
||||
0: "onnx_node_output_0!conv1/7x7_s2_1",
|
||||
10: "onnx_node_output_0!inception_3a/1x1_1",
|
||||
20: "onnx_node_output_0!inception_3a/pool_1",
|
||||
30: "onnx_node_output_0!inception_3b/5x5_reduce_1",
|
||||
40: "onnx_node_output_0!inception_4a/1x1_2",
|
||||
50: "onnx_node_output_0!inception_4a/pool_proj_1",
|
||||
60: "onnx_node_output_0!inception_4b/5x5_reduce_2",
|
||||
70: "onnx_node_output_0!inception_4c/3x3_reduce_2",
|
||||
80: "onnx_node_output_0!inception_4c/output_1",
|
||||
90: "onnx_node_output_0!inception_4d/5x5_2",
|
||||
100: "onnx_node_output_0!inception_4e/3x3_2",
|
||||
110: "onnx_node_output_0!inception_5a/1x1_1",
|
||||
120: "onnx_node_output_0!inception_5a/pool_1",
|
||||
130: "onnx_node_output_0!inception_5b/5x5_reduce_1",
|
||||
140: "onnx_node_output_0!OC2_DUMMY_0"}
|
||||
|
||||
checkONNXNet(t, net, m, 144)
|
||||
}
|
||||
|
||||
func checkTensorflowNet(t *testing.T, net Net) {
|
||||
@@ -188,7 +223,24 @@ func TestOnnxMemory(t *testing.T) {
|
||||
}
|
||||
defer net.Close()
|
||||
|
||||
checkONNXNet(t, net)
|
||||
m := map[int]string{
|
||||
0: "onnx_node_output_0!conv1/7x7_s2_1",
|
||||
10: "onnx_node_output_0!inception_3a/1x1_1",
|
||||
20: "onnx_node_output_0!inception_3a/pool_1",
|
||||
30: "onnx_node_output_0!inception_3b/5x5_reduce_1",
|
||||
40: "onnx_node_output_0!inception_4a/1x1_2",
|
||||
50: "onnx_node_output_0!inception_4a/pool_proj_1",
|
||||
60: "onnx_node_output_0!inception_4b/5x5_reduce_2",
|
||||
70: "onnx_node_output_0!inception_4c/3x3_reduce_2",
|
||||
80: "onnx_node_output_0!inception_4c/output_1",
|
||||
90: "onnx_node_output_0!inception_4d/5x5_2",
|
||||
100: "onnx_node_output_0!inception_4e/3x3_2",
|
||||
110: "onnx_node_output_0!inception_5a/1x1_1",
|
||||
120: "onnx_node_output_0!inception_5a/pool_1",
|
||||
130: "onnx_node_output_0!inception_5b/5x5_reduce_1",
|
||||
140: "onnx_node_output_0!OC2_DUMMY_0"}
|
||||
|
||||
checkONNXNet(t, net, m, 144)
|
||||
}
|
||||
|
||||
func TestOnnxDisk(t *testing.T) {
|
||||
@@ -203,10 +255,27 @@ func TestOnnxDisk(t *testing.T) {
|
||||
}
|
||||
defer net.Close()
|
||||
|
||||
checkONNXNet(t, net)
|
||||
m := map[int]string{
|
||||
0: "onnx_node_output_0!conv1/7x7_s2_1",
|
||||
10: "onnx_node_output_0!inception_3a/1x1_1",
|
||||
20: "onnx_node_output_0!inception_3a/pool_1",
|
||||
30: "onnx_node_output_0!inception_3b/5x5_reduce_1",
|
||||
40: "onnx_node_output_0!inception_4a/1x1_2",
|
||||
50: "onnx_node_output_0!inception_4a/pool_proj_1",
|
||||
60: "onnx_node_output_0!inception_4b/5x5_reduce_2",
|
||||
70: "onnx_node_output_0!inception_4c/3x3_reduce_2",
|
||||
80: "onnx_node_output_0!inception_4c/output_1",
|
||||
90: "onnx_node_output_0!inception_4d/5x5_2",
|
||||
100: "onnx_node_output_0!inception_4e/3x3_2",
|
||||
110: "onnx_node_output_0!inception_5a/1x1_1",
|
||||
120: "onnx_node_output_0!inception_5a/pool_1",
|
||||
130: "onnx_node_output_0!inception_5b/5x5_reduce_1",
|
||||
140: "onnx_node_output_0!OC2_DUMMY_0"}
|
||||
|
||||
checkONNXNet(t, net, m, 144)
|
||||
}
|
||||
|
||||
func checkONNXNet(t *testing.T, net Net) {
|
||||
func checkONNXNet(t *testing.T, net Net, expectedLayers map[int]string, expectedLayerCount int) {
|
||||
img := IMRead("images/space_shuttle.jpg", IMReadColor)
|
||||
if img.Empty() {
|
||||
t.Error("Invalid Mat in ONNX test")
|
||||
@@ -219,6 +288,18 @@ func checkONNXNet(t *testing.T, net Net) {
|
||||
}
|
||||
defer blob.Close()
|
||||
|
||||
lnames := net.GetLayerNames()
|
||||
if len(lnames) != expectedLayerCount {
|
||||
t.Errorf("Invalid len layer names in test: %d\n", len(lnames))
|
||||
}
|
||||
|
||||
m := expectedLayers
|
||||
for k, v := range m {
|
||||
if lnames[k] != v {
|
||||
t.Errorf("Invalid layer name in test: \"%s\" (expected=\"%s\")\n", lnames[k], v)
|
||||
}
|
||||
}
|
||||
|
||||
net.SetInput(blob, "data_0")
|
||||
prob := net.Forward("prob_1")
|
||||
defer prob.Close()
|
||||
|
||||
+8
-8
@@ -525,8 +525,8 @@ func TestMinAreaRect(t *testing.T) {
|
||||
if m.Center.Y != 2 {
|
||||
t.Errorf("TestMinAreaRect(): unexpected center.Y = %v, want = %v", m.Center.Y, 2)
|
||||
}
|
||||
if m.Angle != 45.0 {
|
||||
t.Errorf("TestMinAreaRect(): unexpected angle = %v, want = %v", m.Angle, 45.0)
|
||||
if m.Angle != -45.0 {
|
||||
t.Errorf("TestMinAreaRect(): unexpected angle = %v, want = %v", m.Angle, -45.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,14 +590,14 @@ func TestMinAreaRect2f(t *testing.T) {
|
||||
if m.Center.Y != 3.5 {
|
||||
t.Errorf("TestMinAreaRect2f(): unexpected center.Y = %v, want = %v", m.Center.Y, 3.5)
|
||||
}
|
||||
if m.Width != 7.071067810058594 {
|
||||
t.Errorf("TestMinAreaRect2f(): unexpected width = %v, want = %v", m.Width, 7.071067810058594)
|
||||
if m.Height != 7.071067810058594 {
|
||||
t.Errorf("TestMinAreaRect2f(): unexpected height = %v, want = %v", m.Height, 7.071067810058594)
|
||||
}
|
||||
if m.Height != 5.656853675842285 {
|
||||
t.Errorf("TestMinAreaRect2f(): unexpected height = %v, want = %v", m.Height, 5.656853675842285)
|
||||
if m.Width != 5.656853675842285 {
|
||||
t.Errorf("TestMinAreaRect2f(): unexpected width = %v, want = %v", m.Width, 5.656853675842285)
|
||||
}
|
||||
if m.Angle != 45.0 {
|
||||
t.Errorf("TestMinAreaRect2f(): unexpected angle = %v, want = %v", m.Angle, 45.0)
|
||||
if m.Angle != -45.0 {
|
||||
t.Errorf("TestMinAreaRect2f(): unexpected angle = %v, want = %v", m.Angle, -45.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
func TestVersions(t *testing.T) {
|
||||
ocvv := OpenCVVersion()
|
||||
|
||||
if !(strings.Contains(ocvv, "4.11") || strings.Contains(ocvv, "4.12")) {
|
||||
if !(strings.Contains(ocvv, "4.11") || strings.Contains(ocvv, "4.12") || strings.Contains(ocvv, "4.13")) {
|
||||
t.Error("Wrong version of OpenCV:", ocvv)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user