{"id":256,"date":"2024-11-23T09:29:30","date_gmt":"2024-11-23T01:29:30","guid":{"rendered":"https:\/\/obagg.com\/index.php\/2024\/11\/23\/%e5%9f%ba%e4%ba%8eopenvino-c-api%e9%83%a8%e7%bd%b2yolov5-seg%e5%ae%9e%e4%be%8b%e5%88%86%e5%89%b2%e6%a8%a1%e5%9e%8b\/"},"modified":"2024-11-23T09:29:30","modified_gmt":"2024-11-23T01:29:30","slug":"%e5%9f%ba%e4%ba%8eopenvino-c-api%e9%83%a8%e7%bd%b2yolov5-seg%e5%ae%9e%e4%be%8b%e5%88%86%e5%89%b2%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/obagg.com\/index.php\/2024\/11\/23\/%e5%9f%ba%e4%ba%8eopenvino-c-api%e9%83%a8%e7%bd%b2yolov5-seg%e5%ae%9e%e4%be%8b%e5%88%86%e5%89%b2%e6%a8%a1%e5%9e%8b\/","title":{"rendered":"\u57fa\u4e8eOpenVINO C++ API\u90e8\u7f72YOLOv5-Seg\u5b9e\u4f8b\u5206\u5272\u6a21\u578b"},"content":{"rendered":"<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u300a\u57fa\u4e8eOpenVNO\u90e8\u7f72YOLOv5-seg\u5b9e\u65f6\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\u300b \u4ecb\u7ecd\u4e86\u57fa\u4e8eOpenVINO Python API\u90e8\u7f72YOLOv5-Seg\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\uff0c\u672c\u6587\u4ecb\u7ecd\u57fa\u4e8eOpenVINO C++ API\u90e8\u7f72YOLOv5-Seg\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\uff0c\u4e3b\u8981\u6b65\u9aa4\u6709\uff1a<\/p>\n<ol>\n<li>\u914d\u7f6eOpenVINO C++\u5f00\u53d1\u73af\u5883<\/li>\n<li>\u4e0b\u8f7d\u5e76\u8f6c\u6362YOLOv5-Seg\u9884\u8bad\u7ec3\u6a21\u578b<\/li>\n<li>\u4f7f\u7528OpenVINO Runtime C++ API\u7f16\u5199\u63a8\u7406\u7a0b\u5e8f<\/li>\n<\/ol>\n<p>\u4e0b\u9762\uff0c\u672c\u6587\u5c06\u4f9d\u6b21\u8be6\u8ff0\u3002<\/p>\n<p><strong>\u7b2c\u4e00\u6b65<\/strong>\uff0c\u914d\u7f6eOpenVINO C++\u5f00\u53d1\u73af\u5883\uff0c\u8bf7\u53c2\u8003\u300a\u5728Windows\u4e2d\u57fa\u4e8eVisual Studio\u914d\u7f6eOpenVINO C++\u5f00\u53d1\u73af\u5883\u300b<\/p>\n<p><strong>\u7b2c\u4e8c\u6b65<\/strong>\uff0c\u53c2\u8003\u300a\u57fa\u4e8eOpenVNO\u90e8\u7f72YOLOv5-seg\u5b9e\u65f6\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\u300b \u514b\u9686YOLOv5 Github \u4ee3\u7801\u4ed3\u5230\u672c\u5730\uff0c\u7136\u540e\u8fd0\u884c\u547d\u4ee4\u83b7\u5f97 yolov5s-seg ONNX \u683c\u5f0f\u6a21\u578b\uff1ayolov5s-seg.onnx\uff1a<\/p>\n<blockquote>\n<p>python export.py &#8211;weights yolov5s-seg.pt &#8211;include onnx<\/p>\n<\/blockquote>\n<p>\u63a5\u7740\u8fd0\u884c\u547d\u4ee4\u83b7\u5f97yolov5s-seg IR\u683c\u5f0f\u6a21\u578b\uff1ayolov5s-seg.xml\u548cyolov5s-seg.bin\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<blockquote>\n<p>mo -m yolov5s-seg.onnx &#8211;compress_to_fp16<\/p>\n<\/blockquote>\n<div class=\"image-package\">\n<div class=\"image-container\" style=\"max-width: 400px; max-height: 217px;\">\n<div class=\"image-view\" data-width=\"400\" data-height=\"217\"><img decoding=\"async\" src=\"https:\/\/obagg.com\/wp-content\/uploads\/2024\/11\/frc-45f55ea3b7cf37a334b490f6b00ffe5f.png\"><\/div>\n<\/div>\n<div class=\"image-caption\">yolov5-seg ONNX\u683c\u5f0f\u548cIR\u683c\u5f0f\u6a21\u578b<\/div>\n<\/div>\n<p><strong>\u7b2c\u4e09\u6b65<\/strong>\uff1a\u4f7f\u7528OpenVINO Runtime C++ API\u7f16\u5199\u63a8\u7406\u7a0b\u5e8f\u3002\u4e00\u4e2a\u7aef\u5230\u7aef\u7684AI\u63a8\u7406\u7a0b\u5e8f\uff0c\u4e3b\u8981\u5305\u542b\u4e94\u4e2a\u5178\u578b\u7684\u5904\u7406\u6d41\u7a0b\uff1a<\/p>\n<ol>\n<li>\u91c7\u96c6\u56fe\u50cf&amp;\u56fe\u50cf\u89e3\u7801<\/li>\n<li>\u56fe\u50cf\u6570\u636e\u9884\u5904\u7406<\/li>\n<li>AI\u63a8\u7406\u8ba1\u7b97<\/li>\n<li>\u5bf9\u63a8\u7406\u7ed3\u679c\u8fdb\u884c\u540e\u5904\u7406<\/li>\n<li>\u5c06\u5904\u7406\u540e\u7684\u7ed3\u679c\u96c6\u6210\u5230\u4e1a\u52a1\u6d41\u7a0b<\/li>\n<\/ol>\n<div class=\"image-package\">\n<div class=\"image-container\" style=\"max-width: 693px; max-height: 173px;\">\n<div class=\"image-view\" data-width=\"693\" data-height=\"173\"><img decoding=\"async\" src=\"https:\/\/obagg.com\/wp-content\/uploads\/2024\/11\/frc-38eff8649b88b4a36c6849eb99d74ca1.png\"><\/div>\n<\/div>\n<div class=\"image-caption\">image.png<\/div>\n<\/div>\n<p>\u57fa\u4e8eOpenVINO Runtime C++API\u7684\u540c\u6b65\u63a8\u7406\u4ee3\u7801\u7684\u5173\u952e\u7247\u6bb5\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code class=\"C++\">int main(int argc, char* argv[]) {\n    \/\/ -------- Get OpenVINO runtime version --------\n    std::cout  paddings(3);       \/\/scale, half_h, half_w\n    cv::Mat resized_img = letterbox(img, paddings); \/\/resize to (640,640) by letterbox\n    \/\/ BGR-&gt;RGB, u8(0-255)-&gt;f32(0.0-1.0), HWC-&gt;NCHW\n    cv::Mat blob = cv::dnn::blobFromImage(resized_img, 1 \/ 255.0, cv::Size(640, 640), cv::Scalar(0, 0, 0), true);\n\n    \/\/ -------- Step 5. Feed the blob into the input node of YOLOv5 -------\n    \/\/ Get input port for model with one input\n    auto input_port = compiled_model.input();\n    \/\/ Create tensor from external memory\n    ov::Tensor input_tensor(input_port.get_element_type(), input_port.get_shape(), blob.ptr(0));\n    \/\/ Set input tensor for model with one input\n    infer_request.set_input_tensor(input_tensor);\n\n    \/\/ -------- Step 6. Start inference --------\n    infer_request.infer();\n\n    \/\/ -------- Step 7. Get the inference result --------\n    auto detect = infer_request.get_output_tensor(0);\n    auto detect_shape = detect.get_shape();\n    std::cout  32 x 25600\n    cv::Mat proto_buffer(proto_shape[1], proto_shape[2] * proto_shape[3], CV_32F, proto.data());\n\n    \/\/ -------- Step 8. Post-process the inference result -----------\n   ...\n}\n<\/code><\/pre>\n<p>\u5b8c\u6574\u8303\u4f8b\u4ee3\u7801\uff1ahttps:\/\/gitee.com\/ppov-nuc\/yolov5_infer\/blob\/main\/yolov5seg_openvino_dGPU.cpp<\/p>\n<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<div class=\"image-package\">\n<div class=\"image-container\" style=\"max-width: 692px; max-height: 384px;\">\n<div class=\"image-view\" data-width=\"692\" data-height=\"384\"><img decoding=\"async\" src=\"https:\/\/obagg.com\/wp-content\/uploads\/2024\/11\/frc-4265cfafc132ab9b12795053c49db092.png\"><\/div>\n<\/div>\n<div class=\"image-caption\">yolov5seg_openvino_dGPU.cpp\u8fd0\u884c\u7ed3\u679c<\/div>\n<\/div>\n<p>Please credit: <a href=\"https:\/\/obagg.com\">OBA Blog<\/a> &raquo; <a href=\"https:\/\/obagg.com\/index.php\/2024\/11\/23\/%e5%9f%ba%e4%ba%8eopenvino-c-api%e9%83%a8%e7%bd%b2yolov5-seg%e5%ae%9e%e4%be%8b%e5%88%86%e5%89%b2%e6%a8%a1%e5%9e%8b\/\">\u57fa\u4e8eOpenVINO C++ API\u90e8\u7f72YOLOv5-Seg\u5b9e\u4f8b\u5206\u5272\u6a21\u578b<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u300a\u57fa\u4e8eOpenVNO\u90e8\u7f72YOLOv5-seg\u5b9e\u65f6\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\u300b \u4ecb\u7ecd\u4e86\u57fa\u4e8eOpenVINO Python API\u90e8\u7f72YOLOv5-Seg\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\uff0c\u672c\u6587\u4ecb\u7ecd\u57fa\u4e8eOpenVINO C++ API\u90e8\u7f72YOLOv5-Seg\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\uff0c\u4e3b\u8981\u6b65\u9aa4\u6709\uff1a \u914d\u7f6eOpenVINO C++\u5f00\u53d1\u73af\u5883 \u4e0b\u8f7d\u5e76\u8f6c\u6362YOLOv5-Seg\u9884\u8bad\u7ec3\u6a21\u578b \u4f7f\u7528OpenVINO Runtime C++ API\u7f16\u5199\u63a8\u7406\u7a0b\u5e8f \u4e0b\u9762\uff0c\u672c\u6587\u5c06\u4f9d\u6b21\u8be6\u8ff0\u3002 \u7b2c\u4e00\u6b65\uff0c\u914d\u7f6eOpenVINO C++\u5f00\u53d1\u73af\u5883\uff0c\u8bf7\u53c2\u8003\u300a\u5728Windows\u4e2d\u57fa\u4e8eVisual Studio\u914d\u7f6eOpenVINO C++\u5f00\u53d1\u73af\u5883\u300b \u7b2c\u4e8c\u6b65\uff0c\u53c2\u8003\u300a\u57fa\u4e8eOpenVNO\u90e8\u7f72YOLOv5-seg\u5b9e\u65f6\u5b9e\u4f8b\u5206\u5272\u6a21\u578b\u300b \u514b\u9686YOLOv5 Github \u4ee3\u7801\u4ed3\u5230\u672c\u5730\uff0c\u7136\u540e\u8fd0\u884c\u547d\u4ee4\u83b7\u5f97 yolov5s-seg ONNX \u683c\u5f0f\u6a21\u578b\uff1ayolov5s-seg.onnx\uff1a python export.py &#8211;weights yolov5s-seg.pt &#8211;include onnx \u63a5\u7740\u8fd0\u884c\u547d\u4ee4\u83b7\u5f97yolov5s-seg IR\u683c\u5f0f\u6a21\u578b\uff1ayolov5s-seg.xml\u548cyolov5s-seg.bin\uff0c\u5982\u4e0b\u56fe\u6240\u793a mo -m yolov5s-seg.onnx &#8211;compress_to_fp16 yolov5-seg ONNX\u683c\u5f0f\u548cIR\u683c\u5f0f\u6a21\u578b \u7b2c\u4e09\u6b65\uff1a\u4f7f\u7528OpenVINO Runtime C++ API\u7f16\u5199\u63a8\u7406\u7a0b\u5e8f\u3002\u4e00\u4e2a\u7aef\u5230\u7aef\u7684AI\u63a8\u7406\u7a0b\u5e8f\uff0c\u4e3b\u8981\u5305\u542b\u4e94\u4e2a\u5178\u578b\u7684\u5904\u7406\u6d41\u7a0b\uff1a \u91c7\u96c6\u56fe\u50cf&amp;\u56fe\u50cf\u89e3\u7801 \u56fe\u50cf\u6570\u636e\u9884\u5904\u7406 AI\u63a8\u7406\u8ba1\u7b97 \u5bf9\u63a8\u7406\u7ed3\u679c\u8fdb\u884c\u540e\u5904\u7406 \u5c06\u5904\u7406\u540e\u7684\u7ed3\u679c\u96c6\u6210\u5230\u4e1a\u52a1\u6d41\u7a0b image.png \u57fa\u4e8eOpenVINO Runtime C++API\u7684\u540c\u6b65\u63a8\u7406\u4ee3\u7801\u7684\u5173\u952e\u7247\u6bb5\u5982\u4e0b\u6240\u793a\uff1a int main(int argc, char* argv[]) { \/\/ &#8212;&#8212;&#8211; Get OpenVINO runtime version &#8212;&#8212;&#8211; std::cout paddings(3); \/\/scale, half_h, half_w cv::Mat resized_img = letterbox(img, paddings); \/\/resize to (640,640) by letterbox \/\/ BGR-&gt;RGB, u8(0-255)-&gt;f32(0.0-1.0), HWC-&gt;NCHW cv::Mat blob = cv::dnn::blobFromImage(resized_img, 1 \/ 255.0, cv::Size(640, 640), cv::Scalar(0, 0, 0), true); \/\/ &#8212;&#8212;&#8211; Step 5. Feed the blob into the input node of YOLOv5 &#8212;&#8212;- \/\/ Get input port for model with one input auto input_port = compiled_model.input(); \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-256","post","type-post","status-publish","format-standard","hentry","category-share"],"_links":{"self":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/posts\/256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":0,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"wp:attachment":[{"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obagg.com\/index.php\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}