{"id":663,"date":"2024-03-25T08:00:21","date_gmt":"2024-03-25T00:00:21","guid":{"rendered":"https:\/\/www.zhoubin.asia\/?p=663"},"modified":"2024-03-25T17:56:30","modified_gmt":"2024-03-25T09:56:30","slug":"hailort","status":"publish","type":"post","link":"https:\/\/www.zhoubin.asia\/index.php\/2024\/03\/25\/hailort\/","title":{"rendered":"[HailoRT] \u5982\u4f55\u4f7f\u7528\u5176\u4ed6\u786c\u4ef6\u52a0\u901f\u6765\u8fdb\u884cinput tensor\u7684\u5f52\u4e00\u5316"},"content":{"rendered":"<p>\u5bf9\u4e8e\u5728hailo NPU\u4e0a\u8fd0\u884c\u4e00\u822c\u7684\u56fe\u50cfAI\u7b97\u6cd5\uff0c\u5efa\u8bae\u5c06\u5f52\u4e00\u5316\u653e\u5230hailo\u5185\u90e8\u53bb\u505a\u3002\u5177\u4f53\u505a\u6cd5\u4e3a\uff1a\u5728\u8f6c\u6a21\u578b\u65f6\uff0c\u811a\u672c\u4e2d\u52a0\u4e0a\u4e00\u53e5\uff1a<\/p>\n<p><code>normalization1 = normalization([0.0, 0.0, 0.0], [255.0, 255.0, 255.0])<\/code><\/p>\n<p>\u8fd9\u662f\u56e0\u4e3ahailo\u672c\u8eab\u662f\u505a\u91cf\u5316\u7684NPU\u52a0\u901f\u5668\uff0c\u5f52\u4e00\u5316\u653e\u5728hailo\u82af\u7247\u91cc\u53ef\u4ee5\u907f\u514dhost\u8d44\u6e90\u635f\u8017\uff0c\u63d0\u9ad8\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<p>\u4f46\u662f\u5f53\u8f93\u5165\u7684tensor\u4e0d\u662f\u56fe\u50cf\u6570\u636e\u800c\u662f\u7279\u5f81\u56fe\u6216\u6fc0\u5149\u96f7\u8fbe\u6570\u636e\u65f6\uff0c\u8f93\u5165tensor\u672c\u8eab\u5c31\u662f\u6d6e\u70b9\u578b\uff0c\u65e0\u6cd5\u5728hailo\u5185\u90e8\u505a\u5f52\u4e00\u5316\uff0c\u5fc5\u987b\u4f7f\u7528hailort\u800c\u975ehailo\u786c\u4ef6\u505a\u5f52\u4e00\u5316\u3002<\/p>\n<p>\u4f7f\u7528hailort\u505a\u5f52\u4e00\u5316\u610f\u5473\u7740\u8f93\u5165\u5230hailort API\u7684\u6570\u636e\u4e3afloat32\u6570\u636e\u7c7b\u578b\uff0chailort\u4f1a\u5728API\u5185\u90e8\u57fa\u4e8ehost\u8d44\u6e90\u548c\u8f6c\u6362\u6a21\u578b\u5f97\u5230\u7684\u91cf\u5316\u53c2\u6570\uff0c\u4f7f\u7528CPU\u8fdb\u884c\u91cf\u5316\u8ba1\u7b97\uff0c\u7136\u540e\u5c06\u91cf\u5316\u540e\u7684\u6570\u636e\u4f20\u8f93\u7ed9hailo\u786c\u4ef6\u3002<\/p>\n<p>\u5982\u679c\u5e0c\u671b\u4f7f\u7528DSP\u800c\u4e0d\u662fCPU\u8fdb\u884c\u91cf\u5316\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<ol>\n<li><strong>\u5c06input vstream\u7684\u8f93\u5165\u683c\u5f0f\u7531float32\u4fee\u6539\u4e3aUINT8\uff1a<br \/>\n<\/strong><em><code>auto input_params = network_group.value()-&gt;make_input_vstream_params({}, HAILO_FORMAT_TYPE_UINT8, HAILO_DEFAULT_VSTREAM_TIMEOUT_MS, HAILO_DEFAULT_VSTREAM_QUEUE_SIZE);<\/code><\/em><strong><br \/>\n<\/strong><\/li>\n<li><strong>\u901a\u8fc7\u6a21\u578b\u6587\u4ef6hef\u83b7\u53d6\u8f93\u5165tensor\u7684\u91cf\u5316\u53c2\u6570\uff1a<br \/>\n<\/strong><em><code>auto input_vstreams = pipeline.get_input_vstreams();<br \/>\nstd::vector quant;<br \/>\nfor (const auto &amp;input_vstream : input_vstreams) {<br \/>\nquant = input_vstream.get().get_quant_infos();<br \/>\nassert(quant.size() == 1);<br \/>\nconst auto input_name = input_vstream.get().name();<br \/>\nstd::cout &lt;&lt; \"input_name:\" &lt;&lt; input_name &lt;&lt; \" zp: \" &lt;&lt; quant[0].qp_zp<br \/>\n&lt;&lt; \" scale: \" &lt;&lt; quant[0].qp_scale &lt;&lt; \" frame size: \" &lt;&lt;\u00a0 input_vstream.get().get_frame_size() &lt;&lt; std::endl;<br \/>\n}<\/code><\/em><strong><br \/>\n<\/strong><\/li>\n<li><strong>\u91c7\u7528\u81ea\u5b9a\u4e49\u7684\u91cf\u5316\u65b9\u5f0f\uff0c\u8fd9\u91cc\u793a\u4f8b\u4e2d\u91c7\u7528CPU\u91cf\u5316\uff1a<br \/>\n<\/strong><em><code>#ifdef QUANT_EXT<br \/>\n\/\/TODO: you could do the quant in other ways or in other HW.<br \/>\nQuantization::quantize_input_buffer&lt;float32_t, uint8_t&gt;((float32_t*)file_data.data(), (uint8_t*)input_buffer.data(),<br \/>\ninput_vstream.get().get_frame_size(), quant[0]);<br \/>\n#else<br \/>\nstd::copy(file_data.begin(), file_data.end(), input_buffer.begin());<br \/>\n#endif<\/code><\/em><\/li>\n<\/ol>\n<p>\u8bf7\u6839\u636e\u91cf\u5316\u4fe1\u606f\u81ea\u884c\u9009\u62e9\u5408\u9002\u7684\u91cf\u5316\u65b9\u5f0f\uff0c\u4f8b\u5982\u4f7f\u7528DSP\u8fdb\u884c\u91cf\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e\u5728hailo NPU\u4e0a\u8fd0\u884c\u4e00\u822c\u7684\u56fe\u50cfAI\u7b97\u6cd5\uff0c\u5efa\u8bae\u5c06\u5f52\u4e00\u5316\u653e\u5230hailo\u5185\u90e8\u53bb\u505a\u3002\u5177\u4f53\u505a\u6cd5\u4e3a\uff1a\u5728\u8f6c\u6a21\u578b\u65f6\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[5,1],"tags":[],"class_list":["post-663","post","type-post","status-publish","format-standard","hentry","category-hailort","category-tech"],"_links":{"self":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":2,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"predecessor-version":[{"id":667,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/663\/revisions\/667"}],"wp:attachment":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}