{"id":692,"date":"2024-04-24T08:00:37","date_gmt":"2024-04-24T00:00:37","guid":{"rendered":"https:\/\/www.zhoubin.asia\/?p=692"},"modified":"2024-07-12T13:56:23","modified_gmt":"2024-07-12T05:56:23","slug":"petr","status":"publish","type":"post","link":"https:\/\/www.zhoubin.asia\/index.php\/2024\/04\/24\/petr\/","title":{"rendered":"[PETR] \u5982\u4f55\u5c06Hailo\u7248\u672cPETR\u7684onnx\u6a21\u578b\u91cd\u8bad\u7ec3\uff0c\u53ef\u89c6\u5316\uff0c\u5bfc\u51faonnx\u4ee5\u53ca\u91cf\u5316\u7f16\u8bd1"},"content":{"rendered":"<p>PETR\u662f\u4e00\u4e2a\u7edf\u4e00\u7684\u6846\u67b6\uff0c\u7528\u4e8e\u4ece\u591a\u89c6\u89d2\u56fe\u50cf\u4e2d\u8fdb\u884c3D\u611f\u77e5\u7684BEV\u6a21\u578b\u3002<br \/>\n\u5176\u6a21\u578b\u57fa\u672c\u6846\u67b6\u5982\u4e0b\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-693\" src=\"https:\/\/www.zhoubin.asia\/wp-content\/uploads\/2024\/04\/PETRv2.jpg\" alt=\"\" width=\"631\" height=\"289\" \/><br \/>\n\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Hailo\u6765\u5bfc\u51faPETR\u7684onnx\u6a21\u578b\u5e76\u8fdb\u884c\u6a21\u578b\u7f16\u8bd1\u3002<br \/>\n\u56e0\u4e3aHailo\u7684\u82af\u7247\u4e13\u6ce8\u4e8eCNN\u4ee5\u53catransformer\u6a21\u5757\u7684\u63a8\u7406\uff0c\u6240\u4ee5\u6b64\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5c06\u6574\u4f53\u6a21\u578b\u62c6\u5206\u4e3aHailo\u5904\u7406\u90e8\u5206\uff0c\u4ee5\u53caHost\u5904\u7406\u90e8\u5206\uff0c\u8bf7\u67e5\u770b\u4e0b\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-694\" src=\"https:\/\/www.zhoubin.asia\/wp-content\/uploads\/2024\/04\/PETR-Hailo.jpg\" alt=\"\" width=\"654\" height=\"199\" \/><br \/>\n\u7b80\u5355\u6765\u8bf4\uff0c\u5c06\u56fe\u7247\u5904\u7406\u4e3a2D feature\u7684CNN\u90e8\u5206\u9700\u8981hailo\u4e0a\u9762\u5904\u7406\uff1b \u7136\u540e\u5c06\u8fd9\u4e9bfeature\u4ee5\u53ca\u5176\u4ed6\u76843D coordinates \u524d\u5904\u7406\u7ed3\u679c\u4e00\u8d77\u4f5c\u4e3a\u540e\u7eed tansformer\u6a21\u578b\u7684\u8f93\u5165\uff0c\u6b64transformer\u90e8\u5206\u4e5f\u5728hailo\u4e0a\u9762\u8fd0\u884c\uff1b\u4f46\u662ftransformer\u7684Det\/Seg Head\u4e4b\u7c7b\u7684\u540e\u5904\u7406\u5168\u90e8\u5728host\u7aef\u5b8c\u6210\u3002<\/p>\n<h3>1. \u4e0b\u8f7d\u4ee3\u7801<\/h3>\n<p>PETR\u7684\u5b98\u65b9github\u4e3a\uff1a<a href=\"https:\/\/github.com\/megvii-research\/PETR\">https:\/\/github.com\/megvii-research\/PETR<\/a>\uff0c\u6211\u4eec\u5173\u6ce8\u7684\u662fHailo\u7248\u672c\u7684github\u4e3a\uff1a<a href=\"https:\/\/github.com\/hailo-ai\/PETR\">https:\/\/github.com\/hailo-ai\/PETR<\/a><\/p>\n<h3>2. \u6784\u5efaDocker\u955c\u50cf<\/h3>\n<p>\u4f7f\u7528Dockerfile\u6587\u4ef6\u521b\u5efa\u5bf9\u5e94\u7684docker image\uff0c\u53c2\u8003\u547d\u4ee4\uff1a<\/p>\n<pre>docker build --build-arg timezone='cat \/etc\/timezone' --build-arg user=$USER --build-arg uid=$(id -u) --build-arg gid=$(id -g) --build-arg group=alex -t petr:alex .<\/pre>\n<h3>3. \u8fd0\u884ccontainer<\/h3>\n<p>\u53c2\u8003\u547d\u4ee4\uff1a<\/p>\n<pre>docker run --gpus all --name &lt;docker-name&gt; -it --user $USER --shm-size 32gb -p 5000:5000 '[ -d $HOME\/.ssh ] &amp;&amp; echo -v $HOME\/.ssh:\/home\/$USER\/.ssh' '[ -f $HOME\/.gitconfig ] &amp;&amp; echo -v $HOME\/.gitconfig:\/home\/$USER\/.gitconfig' '[ -f $HOME\/.bash_aliases ] &amp;&amp; echo -v $HOME\/.bash_aliases:\/home\/$USER\/.bash_aliases' -v \/home\/alex:\/home\/alex petr:alex \/bin\/bash --login<\/pre>\n<h3>4. \u6fc0\u6d3b\u865a\u62df\u73af\u5883\u5e76\u51c6\u5907\u6570\u636e\u96c6<\/h3>\n<pre>source my_venv\/bin\/activate<\/pre>\n<p>\u6570\u636e\u96c6\u51c6\u5907\uff1a<\/p>\n<ol>\n<li>\u4e0b\u8f7d\u5e76\u653e\u7f6enuscenes\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528Mini\u6570\u636e\u96c6\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-695\" src=\"https:\/\/www.zhoubin.asia\/wp-content\/uploads\/2024\/04\/nuscenes_mini.jpg\" alt=\"\" width=\"622\" height=\"184\" \/><\/li>\n<li>\u5c06\u6587\u4ef6\u7f6e\u4e8e\u8def\u5f84\uff1a\/workspace\/PETR\/data\/nuscenes<\/li>\n<li>\u5728MMDetection3D\u4e2d\u5b9e\u73b0\u6570\u636e\u5e93\u7684\u751f\u6210\uff0c\u53c2\u8003\u94fe\u63a5\uff1a<a href=\"https:\/\/mmdetection3d.readthedocs.io\/zh-cn\/dev-1.x\/advanced_guides\/datasets\/nuscenes.html\">https:\/\/mmdetection3d.readthedocs.io\/zh-cn\/dev-1.x\/advanced_guides\/datasets\/nuscenes.html<\/a><br \/>\n\u5177\u4f53\u547d\u4ee4\uff1a<br \/>\ncd \/workspace\/mmdetection3d<br \/>\npython3 setup.py develop (\u5148\u5b89\u88c5\u5de5\u5177\u73af\u5883)<br \/>\npython tools\/create_data.py nuscenes &#8211;root-path \/workspace\/PETR\/data\/nuscenes &#8211;out-dir \/workspace\/PETR\/data\/nuscenes &#8211;extra-tag nuscenes<\/li>\n<li>\u9664\u4e86\u6807\u51c6\u7684mmdetection\u7684\u6570\u636e\u51c6\u5907\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u4e13\u95e8\u4e3aPETR\u505a\u4e00\u4e9b\u6570\u636e\u51c6\u5907\u3002<br \/>\ncd \/workspace\/PETR\/<br \/>\npython tools\/generate_sweep_pkl.py<br \/>\n\u5728\u8fd0\u884c\u524d\uff0c\u9996\u5148\u9700\u8981\u4fee\u6539\u4e0b\u8fd9\u4e2a\u6587\u6863\u7684info_prefix \u4e0e data_root = &#8220;data\/nuscenes\/&#8221;<br \/>\n\u8bb0\u5f97\u8fd0\u884c\u4e24\u6b21\uff0c\u5206\u522b\u5c06info_prefix \u4fee\u6539\u4e3a\u201ctrain\u201d \u548c \u201cval\u201d<\/li>\n<\/ol>\n<h3>5. \u91cd\u8bad\u7ec3\u6216\u6d4b\u8bd5\u6a21\u578b<\/h3>\n<pre>\u91cd\u8bad\u7ec3\u7684\u65f6\u5019\uff0c\u6211\u4eec\u6700\u597d\u662f\u5f00\u542f\u865a\u62df\u73af\u5883 source \/workspace\/my_venv\/bin\/activate\r\n\u5e76\u4e14\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\u989d\u5916\u5b89\u88c5 pip install absl-py\r\n# Train\r\ntools\/dist_train.sh &lt;config-file-path&gt; &lt;num-gpus&gt; --work-dir &lt;output-workdir&gt;\r\n\u4f8b\u5982\uff1a tools\/dist_train.sh projects\/configs\/petrv2\/petrv2_fcos3d_repvgg_b0x32_decoder_3_UN_1600x640.py 1 --work-dir work_dirs\r\n# Test \u67e5\u770bmAP\r\ntools\/dist_test.sh &lt;config-file-path&gt; &lt;ckpt-path&gt; &lt;num-gpus&gt; --eval bbox\r\n# \u53ef\u89c6\u5316\r\n\u57fa\u672c\u4e0a\u53c2\u8003github\u4e2d\u7684<a href=\"https:\/\/github.com\/hailo-ai\/PETR\/tree\/petrv2-repvgg?tab=readme-ov-file#visualize\">\u65b9\u5f0f<\/a>\r\n\u4f8b\u5982\uff1a.\/tools\/dist_test.sh projects\/configs\/petrv2\/petrv2_fcos3d_repvgg_b0x32_decoder_3_UN_1600x640.py ckpts\/petrv2_fcos3d_repvgg_b0_epoch_120.pth 1 --out work_dirs\/pp-nus\/results_eval.pkl --format-only --eval-options 'jsonfile_prefix=work_dirs\/pp-nus\/results_eval'\r\n\u8fd9\u91cc\u7279\u5b9a\u7684pth\u5bf9\u5e94\u7684\u662f\u7279\u5b9a\u7684\u6a21\u578b\uff0c<strong>\u8bf7\u786e\u4fddconfig-file-path\u4e2d\u7684 num_query \u4e3a900.<\/strong><\/pre>\n<pre>\u6700\u540e\u8c03\u7528create_visualization_video.py\u5c06\u53ef\u89c6\u5316\u7684\u7ed3\u679cexport\u5230\u4e00\u4e2amp4<\/pre>\n<p>python3 tools\/visualize.py<br \/>\npython3 create_visualization_video.py<br \/>\n\u6ce8\uff1a\u9700\u8981\u63d0\u524d\u4fee\u6539 visualize.py\u4e2d\u7684database\u8def\u5f84.<\/p>\n<h3>6. \u5bfc\u51fa\u6a21\u578b<\/h3>\n<pre>\u5c06\u7edf\u4e00\u6846\u67b6\u7684\u6a21\u578b\u8fdb\u884c\u62c6\u5206<\/pre>\n<pre>python tools\/export_onnx.py projects\/configs\/petrv2\/petrv2_fcos3d_repvgg_b0x32_decoder_3_UN_1600x640.py petrv2_fcos3d_repvgg_b0_epoch_120.pth --split transformer --ncams 4 --out petrv2_transformer.onnx --img-dims 608 800\r\npython tools\/export_onnx.py projects\/configs\/petrv2\/petrv2_fcos3d_repvgg_b0x32_decoder_3_UN_1600x640.py petrv2_fcos3d_repvgg_b0_epoch_120.pth --split backbone --ncams 4 --out petrv2_backbone.onnx --img-dims 608 800<\/pre>\n<p>\u9700\u8981\u5c06transformer\u7684\u6a21\u578b\u8fdb\u884c\u526a\u679d\u6574\u7406\uff0c\u65b9\u4fbfhailo\u5bf9\u5b83\u8fdb\u884c\u652f\u6301\u3002<\/p>\n<pre>python tools\/onnx_reshape.py --onnx petrv2_transformer.onnx --cfg tools\/onnx_reshape_cfg_repvgg_b0x32_cams_4_decoder_3_UN_800x608.json --out petrv2_transformer_const0.onnx<\/pre>\n<h3>7. \u6a21\u578b\u91cf\u5316\u7f16\u8bd1<\/h3>\n<p>\u6309\u7167\u6b63\u5e38\u7684DFC\u6a21\u578b\u8fdb\u884c\u91cf\u5316\uff0c\u4e3b\u8981\u8981\u4f7f\u7528transfomer\u7684\u4e13\u7528alls\u6587\u4ef6\u8fdb\u884c\u91cf\u5316\u4ee5\u53cacompiler\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528Hailo\u5229\u7528PETR\u7684onnx\u6a21\u578b\u5bfc\u51fa\u4ee5\u53ca\u6a21\u578b\u7f16\u8bd1\u7684\u6b65\u9aa4\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PETR\u662f\u4e00\u4e2a\u7edf\u4e00\u7684\u6846\u67b6\uff0c\u7528\u4e8e\u4ece\u591a\u89c6\u89d2\u56fe\u50cf\u4e2d\u8fdb\u884c3D\u611f\u77e5\u7684BEV\u6a21\u578b\u3002 \u5176\u6a21\u578b\u57fa\u672c\u6846\u67b6\u5982\u4e0b\u56fe\uff1a \u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55 [&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":[15,1],"tags":[],"class_list":["post-692","post","type-post","status-publish","format-standard","hentry","category-ai","category-tech"],"_links":{"self":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/692","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=692"}],"version-history":[{"count":6,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":732,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/692\/revisions\/732"}],"wp:attachment":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/media?parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/categories?post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/tags?post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}