{"id":778,"date":"2024-12-13T08:00:45","date_gmt":"2024-12-13T00:00:45","guid":{"rendered":"https:\/\/www.zhoubin.asia\/?p=778"},"modified":"2024-12-13T07:19:41","modified_gmt":"2024-12-12T23:19:41","slug":"hailo-input-format","status":"publish","type":"post","link":"https:\/\/www.zhoubin.asia\/index.php\/2024\/12\/13\/hailo-input-format\/","title":{"rendered":"Hailo \u8f6c\u6a21\u578b\u5982\u4f55\u5c06 NV12\u5230RGB\u7684\u989c\u8272\u7a7a\u95f4\u8f6c\u6362\u52a0\u5165\u5230Hailo NN core\u4e2d\u8fd0\u884c"},"content":{"rendered":"<p>\u67d0\u4e9b\u4f4e\u7aef\u7684host, \u56fe\u50cf\u91c7\u96c6\u7684\u65f6\u5019\uff0c ISP\u6700\u7ec8\u8f93\u51fa\u7684\u56fe\u50cf\u4e00\u822c\u4e3aNV12\u7684\u6570\u636e\u683c\u5f0f\uff0c \u4e00\u822c\u7684AI\u6a21\u578b\u7684\u67b6\u6784\u4e3aRGB\u6570\u636e\u96c6\u3002\u5982\u679c\u5728host\u7aef\u5c06NV12\u8f6c\u6362\u4e3aRGB\uff0c\u7136\u540e\u53d1\u9001\u7ed9Hailo\u8fdb\u884c\u63a8\u7406\u5219\u53ef\u80fd\u4f1a\u6781\u5927\u7684\u5360\u7528CPU\u7684\u4f7f\u7528\u7387\uff0c\u4ece\u800c\u5f71\u54cd\u6700\u7ec8pipeline\u7684\u6027\u80fd\u3002<\/p>\n<div class=\"content\">\n<p>\u6211\u4eec\u63a8\u8350\u5c06NV12\u8f6cRGB\u8fd9\u4e2a\u6b65\u9aa4\u653e\u5230Hailo\u4e2d\u8fdb\u884c\uff0cHailo\u5df2\u7ecf\u652f\u6301\u4e86\u3002<\/p>\n<p>\u6709\u4e24\u79cdalls\u53ef\u4ee5\u53c2\u8003\uff1a<br \/>\n<code>yuv_to_rgb1 = input_conversion(yuv_to_rgb)<br \/>\nreshape = input_conversion(input_layer1, nv12_to_hailo_yuv, emulator_support=False)<\/code><\/p>\n<p>\u6216\u8005\uff08DFC 3.29.0\u652f\u6301\uff09<\/p>\n<pre><code>reshape_nv12,rgb_layer = input_conversion(input_layer1, nv12_to_rgb, emulator_support=True)<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\u6211\u8fd9\u8fb9\u4e24\u4e2a\u811a\u672c\u4e2demulator_support\u8bbe\u5b9a\u7684\u4e0d\u540c\uff0c\u6b64\u8bbe\u5b9a\u7684\u76ee\u7684\u662f\u4e3a\u4e86\u8bf4\u660e\u6211\u4eec\u5728\u6821\u51c6\u8fd9\u4e2a\u6a21\u578b\u7684\u65f6\u5019\u4f7f\u7528\u7684\u6570\u636e\u96c6\u683c\u5f0f\u4e0d\u540c\u3002\u5f53\u8bbe\u7f6e\u4e3aTrue\u7684\u65f6\u5019\uff0c\u8bf4\u660e\u6211\u4eec\u4f7f\u7528\u7684\u662fNV12\u6570\u636e\u96c6\u8fdb\u884c\u6821\u51c6\uff1b \u5f53\u4e3aFalse\u7684\u65f6\u5019\u5219\u4e3aRGB\u6821\u51c6\u96c6\u3002<\/p>\n<h2>\u5982\u4f55\u51c6\u5907\u8fd9\u79cdNV12\u6570\u636e\u96c6\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528pyhailort\u6216\u8005DFC\u6a21\u62df\u5668\u8fdb\u884c\u63a8\u7406\u5462\uff1f<\/h2>\n<p>\u4e00\u4e2a\u6b63\u5e38\u7684(N,H,W,C)\u7684RGB\u6821\u51c6\u96c6\uff0c\u5982\u679c\u683c\u5f0f\u4e3aNV12,\u6211\u4eec\u5de5\u5177\u8981\u6c42\u7684\u683c\u5f0f\u4e3a\uff08N,H\/2,W,C\uff09<\/p>\n<p>\u5177\u4f53\u8f6c\u6362\u51fd\u6570\u53ef\u4ee5\u53c2\u8003\uff1a<\/p>\n<pre><code>def bgr2nv12(bgr:np.ndarray) -&gt; np.ndarray:\r\n    yuv = cv2.cvtColor(bgr, cv2.COLOR_BGR2YUV_I420)\r\n    uv_row_cnt = yuv.shape[0] \/\/ 3\r\n    uv_plane = np.transpose(yuv[uv_row_cnt * 2:].reshape(2, -1), [1, 0])\r\n    yuv[uv_row_cnt * 2:] = uv_plane.reshape(uv_row_cnt, -1)\r\n    return yuv<\/code><\/pre>\n<p>\u5b9e\u9645\u4e0a\u4f7f\u7528\uff1a<\/p>\n<pre><code>image_array = bgr2nv12(image_array)\r\nimage_array = np.reshape(image_array, (height\/2, width, 3))<\/code><\/pre>\n<p>\u5f53\u7136\u4e5f\u53ef\u4ee5\u53c2\u8003\u6211\u4eecmodel\u4e2d\u7684\u65b9\u5f0f\u8fdb\u884c\u6570\u636e\u8f6c\u6362\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/hailo-ai\/hailo_model_zoo\/blob\/88365ee4f0d5d2b7a071dcc3bde8db4a81a80009\/hailo_model_zoo\/core\/preprocessing\/preprocessing_factory.py#L39\">yuv\u5230NV12<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/hailo-ai\/hailo_model_zoo\/blob\/88365ee4f0d5d2b7a071dcc3bde8db4a81a80009\/hailo_model_zoo\/core\/preprocessing\/preprocessing_factory.py#L17\">RGB\u5230YUV<\/a><\/li>\n<\/ul>\n<p>\u7c7b\u4f3c\u7684\uff0c\u5982\u679c\u4f60\u60f3\u5728\u989c\u8272\u8f6c\u6362\u57fa\u7840\u4e0a\u518d\u52a0\u4e0a\u4e00\u4e2aresize\u529f\u80fd\u7684\u8bdd\uff0c\u53ef\u4ee5\u53c2\u8003\u6211\u4eec\u7684model zoo <a href=\"https:\/\/github.com\/hailo-ai\/hailo_model_zoo\/blob\/master\/hailo_model_zoo\/cfg\/alls\/generic\/yolov5n_seg_nv12_fhd.alls\">yolov5n_seg_nv12_fhd.alls<\/a>\uff1a<\/p>\n<pre><code>resize_input1 = resize(input_layer1, resize_shapes=[1080, 1920])\r\nyuv_to_rgb1 = input_conversion(yuv_to_rgb)\r\nreshape = input_conversion(input_layer1, nv12_to_hailo_yuv, emulator_support=True)<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u67d0\u4e9b\u4f4e\u7aef\u7684host, \u56fe\u50cf\u91c7\u96c6\u7684\u65f6\u5019\uff0c ISP\u6700\u7ec8\u8f93\u51fa\u7684\u56fe\u50cf\u4e00\u822c\u4e3aNV12\u7684\u6570\u636e\u683c\u5f0f\uff0c \u4e00\u822c\u7684AI\u6a21\u578b\u7684\u67b6\u6784\u4e3a [&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":[1],"tags":[],"class_list":["post-778","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/778","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=778"}],"version-history":[{"count":1,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/778\/revisions"}],"predecessor-version":[{"id":779,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/778\/revisions\/779"}],"wp:attachment":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/media?parent=778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/categories?post=778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/tags?post=778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}