{"action":"created","issue":{"url":"https://api.github.com/repos/opencv/opencv/issues/13118","repository_url":"https://api.github.com/repos/opencv/opencv","labels_url":"https://api.github.com/repos/opencv/opencv/issues/13118/labels{/name}","comments_url":"https://api.github.com/repos/opencv/opencv/issues/13118/comments","events_url":"https://api.github.com/repos/opencv/opencv/issues/13118/events","html_url":"https://github.com/opencv/opencv/issues/13118","id":379634132,"node_id":"MDU6SXNzdWUzNzk2MzQxMzI=","number":13118,"title":"The net loaded weights from onnx setInput failed for new input in opencv 4.0","user":{"login":"CaptainEven","id":9303747,"node_id":"MDQ6VXNlcjkzMDM3NDc=","avatar_url":"https://avatars2.githubusercontent.com/u/9303747?v=4","gravatar_id":"","url":"https://api.github.com/users/CaptainEven","html_url":"https://github.com/CaptainEven","followers_url":"https://api.github.com/users/CaptainEven/followers","following_url":"https://api.github.com/users/CaptainEven/following{/other_user}","gists_url":"https://api.github.com/users/CaptainEven/gists{/gist_id}","starred_url":"https://api.github.com/users/CaptainEven/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaptainEven/subscriptions","organizations_url":"https://api.github.com/users/CaptainEven/orgs","repos_url":"https://api.github.com/users/CaptainEven/repos","events_url":"https://api.github.com/users/CaptainEven/events{/privacy}","received_events_url":"https://api.github.com/users/CaptainEven/received_events","type":"User","site_admin":false},"labels":[{"id":635087908,"node_id":"MDU6TGFiZWw2MzUwODc5MDg=","url":"https://api.github.com/repos/opencv/opencv/labels/category:%20dnn","name":"category: dnn","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-12T06:07:31Z","updated_at":"2018-11-12T07:09:37Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nIf you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.\r\nIf you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).\r\n\r\nPlease:\r\n\r\n* Read the documentation to test with the latest developer build.\r\n* Check if other person has already created the same issue to avoid duplicates. You can comment on it if there already is an issue.\r\n* Try to be as detailed as possible in your report.\r\n* Report only one problem per created issue.\r\n\r\n\r\nThis is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.\r\n-->\r\n\r\n##### System information (version)\r\n<!-- Example\r\n- OpenCV = 4.0\r\n- Operating System / Platform => Windows 64 Bit\r\n- Compiler => Visual Studio 2017\r\n-->\r\n\r\n- OpenCV => :4.0beta:\r\n- Operating System / Platform => :Windows 64 bit:\r\n- Compiler => :Visual studio 2017:\r\n\r\n##### Detailed description\r\n Net is loaded from Onnx, the net just can not successfully update input data from setInput\r\ninvalid when call function setInput for the second blob(blob_2):\r\nThe result is 1.0 which means set two different input from blob_1 and blob_2 but got the same vector.\r\nThe details of code is as follows.\r\n<!-- your description -->\r\n\r\n##### Steps to reproduce\r\n#include <opencv2/opencv.hpp>\r\n#include <opencv2/dnn.hpp>\r\n#include <iostream>\r\n#include <fstream>\r\n\r\nusing namespace std;\r\nusing namespace cv;\r\nusing namespace cv::dnn;\r\n\r\nint test_onnx()\r\n{\r\n    \r\n    Net net_1 = readNetFromONNX(model_path);\r\n\r\n    if (net_1.empty() || net_2.empty())\r\n    {\r\n        printf(\"=> net load failed.\\n\");\r\n        return -1;\r\n    }\r\n    const String img_1_path = \"../img_1.jpg\";\r\n    const String img_2_path = \"../img_3.jpg\";\r\n    Mat img_1, img_2;\r\n    img_1 = imread(img_1_path, IMREAD_GRAYSCALE);\r\n    img_2 = imread(img_2_path, IMREAD_GRAYSCALE);\r\n    \r\n    if (img_1.empty() || img_2.empty())\r\n    {\r\n        printf(\"[Err]: empty dir.\\n\");\r\n        return -1;\r\n    }\r\n    img_1.convertTo(img_1, CV_32F);\r\n    img_2.convertTo(img_2, CV_32F);\r\n\r\n    // padding\r\n    int H = img_1.rows;\r\n    int W = img_1.cols;\r\n    int dim_diff = std::abs(H - W);\r\n    int top, bottom, left, right;\r\n    if (H <= W)\r\n    {\r\n\t    top = dim_diff / 2;\r\n\t    bottom = dim_diff - top;\r\n\t    left = 0;\r\n\t    right = 0;\r\n    }\r\n    else\r\n    {\r\n        left = dim_diff / 2;\r\n        right = dim_diff - left;\r\n        top = 0;\r\n        bottom = 0;\r\n    }\r\n\r\n    Mat img_1_pad, img_2_pad;\r\n    copyMakeBorder(img_1, img_1_pad,\r\n\t    top, bottom, left, right, BORDER_CONSTANT, 127.5);\r\n    copyMakeBorder(img_2, img_2_pad,\r\n\t    top, bottom, left, right, BORDER_CONSTANT, 127.5);\r\n\r\n    // construct blob\r\n    Mat blob_1, blob_2;\r\n    blob_1 = blobFromImage(\r\n\t    img_1_pad,\r\n\t    1.0 / 127.5f,\r\n\t    Size(224, 224), \r\n\t    127.5,\r\n\t    true);\r\n    blob_2 = blobFromImage(\r\n\t    img_2_pad,\r\n\t    1.0 / 127.5f,\r\n\t    Size(224, 224),\r\n\t    127.5,\r\n\t    true);\r\n\r\n    // inference: get features\r\n    net_1.setInput(blob_1);\r\n    Mat feature_1 = net_1.forward();\r\n    net_1.setInput(blob_2);  // invalid here...\r\n    Mat feature_2 = net_1.forward();\r\n\r\n    // vector dot\r\n    double dot = feature_1.dot(feature_2);\r\n\r\n    // L2 norm\r\n    double feature_1_norm = norm(feature_1, NORM_L2);\r\n    double feature_2_norm = norm(feature_2, NORM_L2);\r\n\r\n    // cosine similarity\r\n    double sim = dot / (feature_1_norm * feature_2_norm);\r\n    printf(\"\\n=> similarity: %.5f\\n\", sim);\r\n\r\n    return 0;}\r\n<!-- to add code example fence it with triple backticks and optional file extension\r\n    ```\r\n   \r\n    ```\r\n\r\n or attach as .txt or .zip file\r\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/opencv/opencv/issues/comments/437778865","html_url":"https://github.com/opencv/opencv/issues/13118#issuecomment-437778865","issue_url":"https://api.github.com/repos/opencv/opencv/issues/13118","id":437778865,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNzc3ODg2NQ==","user":{"login":"dkurt","id":25801568,"node_id":"MDQ6VXNlcjI1ODAxNTY4","avatar_url":"https://avatars0.githubusercontent.com/u/25801568?v=4","gravatar_id":"","url":"https://api.github.com/users/dkurt","html_url":"https://github.com/dkurt","followers_url":"https://api.github.com/users/dkurt/followers","following_url":"https://api.github.com/users/dkurt/following{/other_user}","gists_url":"https://api.github.com/users/dkurt/gists{/gist_id}","starred_url":"https://api.github.com/users/dkurt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkurt/subscriptions","organizations_url":"https://api.github.com/users/dkurt/orgs","repos_url":"https://api.github.com/users/dkurt/repos","events_url":"https://api.github.com/users/dkurt/events{/privacy}","received_events_url":"https://api.github.com/users/dkurt/received_events","type":"User","site_admin":false},"created_at":"2018-11-12T07:09:37Z","updated_at":"2018-11-12T07:09:37Z","author_association":"MEMBER","body":" @CaptainEven, please close one of the issues t(this one or this: https://github.com/opencv/opencv/issues/13090) if they are related to the same problem."}}
{"actor":{"display_login":"dkurt"}}