opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
76.54k stars 55.64k forks source link

Added dynamic input support to Pad layer #25606

Closed LaurentBerger closed 2 weeks ago

LaurentBerger commented 1 month ago

Pull Request Readiness Checklist

Question : Is opencv team want to solve bug #24729 and #25118?

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

onnx model : image

test_pad_add.zip

this model has a dynamic Pad layer : padding values are output result of Concat layer

I use this program : cv::dnn::Net x1 = cv::dnn::readNet("test_padadd.onnx"); std::vector sza = { 2, 1 }; Mat inpa = (Mat(2, 1) << 1, 2); Mat inpb = (Mat(2, 1) << 3, 1); Mat inpx = (Mat(3, 2) << 10, 11, 12, 13, 14, 15); x1.setInput(inpa, "inpa"); x1.setInput(inpb, "inpb"); x1.setInput(inpx, "inpx"); std::vector res(3); x1.forward(res, std::vector< String >{ "out_add", "pad_values", "out_pad" }); displayBlobSize(res[0], "\nout_add"); displayBlob(res[0], "out_add"); displayBlobSize(res[1], "\npad_values"); displayBlob(res[1], "pad_values"); displayBlobSize(res[2], "\nout_pad"); displayBlob(res[2], "out_pad");

and result

out_add blob size dim 0 : 6 dim 1 : 6 out_add = [2, 2, 2, 2, 2, 2; 2, 2, 2, 12, 13, 2; 2, 2, 2, 14, 15, 2; 2, 2, 2, 16, 17, 2; 2, 2, 2, 2, 2, 2; 2, 2, 2, 2, 2, 2] pad_values blob size dim 0 : 4 dim 1 : 1 pad_values = [1; 2; 3; 1] out_pad blob size dim 0 : 6 dim 1 : 6 out_pad = [0, 0, 0, 0, 0, 0; 0, 0, 0, 10, 11, 0; 0, 0, 0, 12, 13, 0; 0, 0, 0, 14, 15, 0; 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0]

LaurentBerger commented 4 weeks ago

@fengyuentau what does it mean :confused:?

LaurentBerger commented 4 weeks ago

now opencv is compatible vit_l_encoder.onnx (Segment Anything Model)

fengyuentau commented 4 weeks ago

Your code breaks the design of dnn, making it even harder to maintain.

LaurentBerger commented 4 weeks ago

Your code breaks the design of dnn, making it even harder to maintain.

All opencv dnn test are OK in thiscode Opencv cannot read vit_l_encoder.onnx and make inference this code can read and make inference. I check result with onnxruntime and resuts are good So what is broken?

LaurentBerger commented 2 weeks ago

moving to onnxruntime for dnn