{"id":200,"date":"2020-05-23T13:02:55","date_gmt":"2020-05-23T05:02:55","guid":{"rendered":"http:\/\/blog.cyasylum.top\/?p=200"},"modified":"2020-06-02T10:06:37","modified_gmt":"2020-06-02T02:06:37","slug":"voc%e6%a0%bc%e5%bc%8fxml%e6%95%b0%e6%8d%ae%e9%9b%86%e8%bd%acyolo%e6%a0%bc%e5%bc%8f%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"http:\/\/blog.cyasylum.top\/index.php\/2020\/05\/23\/voc%e6%a0%bc%e5%bc%8fxml%e6%95%b0%e6%8d%ae%e9%9b%86%e8%bd%acyolo%e6%a0%bc%e5%bc%8f%e6%96%b9%e6%a1%88\/","title":{"rendered":"VOC\u683c\u5f0fxml\u6570\u636e\u96c6\u8f6cYOLO\u683c\u5f0f\u65b9\u6848"},"content":{"rendered":"<p>\u8d34\u4e24\u6761\u4ee3\u7801<br \/>\n\u4e3a\u4e86\u505arobomaster\u7684\u96f7\u8fbe\uff0c\u9700\u8981\u8dd1\u4e00\u4efd\u76ee\u6807\u68c0\u6d4b\u795e\u7ecf\u7f51\u7edc\uff0c\u8fd9\u91cc\u9009\u62e9\u4e86\u6700\u65b0\u6700\u5f3a\u6700\u5feb\u7684YOLO v4.<br \/>\n\u4f46\u662f\u5b98\u65b9\u63d0\u4f9b\u7684\u53c2\u8003\u6570\u636e\u96c6\u662fVOC\u683c\u5f0f\u7684\uff0c\u65e0\u6cd5\u76f4\u63a5\u4ea4\u4e88\u7f51\u7edc\u4f7f\u7528\uff0c\u9700\u8981\u4eba\u4e3a\u5730\u8fdb\u884c\u4fee\u6539<br \/>\n\u83b7\u53d6\u7c7b\u522b\/\u6846\u5750\u6807\/\u6846\u6846\u957f\u5bbd<\/p>\n<p>\u5b66\u4e60\u4e86\u4e00\u4e0bxml\u6587\u4ef6\u7684\u5904\u7406<br \/>\n\u53c2\u8003\u4e86CSDN\u4e0a\u7684\u6587\u7ae0<a title=\"[YoloV3] DJI\uff38\uff2d\uff2c\u6570\u636e\u96c6\u8f6c\uff39\uff4f\uff4c\uff4f\u811a\u672c\" href=\"https:\/\/blog.csdn.net\/chenhanxuan1999\/article\/details\/103970884\" target=\"_blank\"  rel=\"nofollow\" >[YoloV3] DJI\uff38\uff2d\uff2c\u6570\u636e\u96c6\u8f6c\uff39\uff4f\uff4c\uff4f\u811a\u672c<\/a><\/p>\n<p><strong>\u7d27\u6025\u62a5\u9519\uff0c\u53ea\u80fd\u7ed9yolo v4\u6295\u5582classes\u7684\u5e8f\u53f7\uff0c\u4e0e\u81ea\u5df1\u751f\u6210\u7684names\u6587\u4ef6\u987a\u5e8f\u76f8\u5bf9\u5e94\uff0c\u800c\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528\u7c7b\u7684\u540d\u79f0<\/strong><\/p>\n<p>\u7b2c\u4e00\u6b21\u7528\u6b64\u5904\u751f\u6210\u7684\u4ee3\u7801\u8dd1\u7f51\u7edc\u65f6\uff0c300\u8f6eloss\u964d\u5230\u4e860.001\uff0c\u4f60\u6562\u4fe1\uff1f\uff08\u56e0\u6b64\u8fd8\u8bf7\u81ea\u884c\u4fee\u6539<\/p>\n<pre><code class=\"language-python\">#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n\n'''\nCreated on Sat Jan 11 16:31:30 2020\nXmlToTxt, for DJI ROCO Dataset\n@author: HNU robomaster \u8dc3\u9e7f\n\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/chenhanxuan1999\/java\/article\/details\/103970884\nFix by: HDU robomaster Syan\n'''\nimport os\nimport sys\nimport xml.etree.ElementTree as ET\n\nNorth = 'robomaster_North China Regional Competition'\nCentral = 'robomaster_Central China Regional Competition'\nFinal = 'robomaster_Final Tournament'\n\nCompetition_Path = Final\n\nfiledir = 'D:\/darknet-master\/data\/obj\/DJI ROCO\/'+ Competition_Path +'\/image_annotation'\noutdir = 'D:\/darknet-master\/data\/obj\/DJI ROCO\/'+ Competition_Path +'\/processedTXT'\n\nprint(filedir)\n\ndef del_all_files(path):\n    ls = os.listdir(path)\n    for i in ls:\n        c_path = os.path.join(path, i)\n        if os.path.isdir(c_path):\n            del_file(c_path)\n        else:\n            os.remove(c_path)\n\ndef mkdir(path):\n    # \u53bb\u9664\u9996\u4f4d\u7a7a\u683c\n    path = path.strip()\n    # \u53bb\u9664\u5c3e\u90e8 \\ \u548c \/ \u7b26\u53f7\n    path = path.rstrip(\"\\\\\")\n    path = path.rstrip(\"\/\")\n    # \u5224\u65ad\u8def\u5f84\u662f\u5426\u5b58\u5728\n    is_exist = os.path.exists(path)\n    # \u5224\u65ad\u7ed3\u679c\n    if not is_exist:\n        os.makedirs(path)\n    else:\n        # \u5982\u679c\u76ee\u5f55\u5b58\u5728\u5219\u9996\u5148\u9012\u5f52\u5220\u9664\u8be5\u76ee\u5f55\u4e0b\u6240\u6709\u5185\u5bb9\n        del_all_files(path)\n\ndef xml_to_txt(indir, outdir):\n    parser = ET.XMLParser(encoding=\"utf-8\")\n    root = ET.parse(indir, parser=parser)\n    root = root.getroot()\n\n    f_w = open(outdir, 'w')\n    size_info = root.find(\"size\")\n    width = float(size_info.find(\"width\").text)\n    height = float(size_info.find(\"height\").text)\n\n    for obj in root.findall(\"object\"):\n        #error occurs when using func .find() specifically for string \"armor_color\"\n        armor_color = getattr(obj.find(\"armor_color\"), 'text', None)\n        armor_class = getattr(obj.find(\"armor_class\"), 'text', None)\n        name = obj.find(\"name\").text\n        xmin = float(obj.find(\"bndbox\").find(\"xmin\").text)\n        ymin = float(obj.find(\"bndbox\").find(\"ymin\").text)\n        xmax = float(obj.find(\"bndbox\").find(\"xmax\").text)\n        ymax = float(obj.find(\"bndbox\").find(\"ymax\").text)\n        x_center = (xmax + xmin) \/ 2\n        y_center = (ymax + ymin) \/ 2\n        x = x_center \/ width\n        y = y_center \/ height\n        w = (xmax - xmin) \/ width\n        h = (ymax - ymin) \/ height\n        flag = ''\n        if name == 'armor':\n                flag = name + '-' + armor_color + '-' + armor_class\n        else:\n            flag = name\n        f_w.write(\"\".join([str(flag), ' ', str(round(x, 6)), ' ', str(round(y, 6)), ' ', str(round(w, 6)), ' ', str(round(h, 6)), '\\n']))\n    f_w.close()\n\ndef main():\n    global filedir\n    global outdir\n\n    file_list = os.listdir(filedir)\n    mkdir(outdir)\n    for file_name in file_list:\n        file_prefix = file_name.rpartition(\".\")[0]\n        new_name = \"\".join([file_prefix, '.txt'])\n        xml_to_txt(os.path.join(filedir, file_name), os.path.join(outdir, new_name))\n\nif __name__ == \"__main__\":\n    main()\n<\/code><\/pre>\n<p>\u5e76\u81ea\u5df1\u5199\u4e86\u4e00\u6bb5\u7528\u4e8e\u8bfb\u53d6\u56fe\u7247\u5217\u8868\u7684\u5c0f\u4ee3\u7801\uff0c\u7528\u4e8e\u5582\u517byolo<\/p>\n<pre><code class=\"language-python\">#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n\n'''\nCreated on Sat May 23 12:03:30 2020\nGet img list, for DJI ROCO Dataset\n@author: HDU robomaster Syan\n'''\nimport os\nimport sys\n\nNorth = 'robomaster_North China Regional Competition'\nCentral = 'robomaster_Central China Regional Competition'\nFinal = 'robomaster_Final Tournament'\n\nCompetition_Path = [North,Central,Final]\nfiledir = 'D:\/darknet-master\/data\/obj\/DJI ROCO\/'\n\ndef main():\n    global filedir\n\n    f_w = open(filedir + 'train.txt', 'w', encoding='utf-8')\n\n    for Path in Competition_Path:\n        for file_name in os.listdir(filedir+Path+'\/image'):\n            #print(file_name)\n\n            file_name.strip()\n            if file_name.endswith('.jpg'):\n                f_w.write(filedir[18:]+Path+'\/image\/'+file_name+'\\n')\n\n    f_w.close()\n\nif __name__ == \"__main__\":\n    main()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8d34\u4e24\u6761\u4ee3\u7801 \u4e3a\u4e86\u505arobomaster\u7684\u96f7\u8fbe\uff0c\u9700\u8981\u8dd1\u4e00\u4efd\u76ee\u6807\u68c0\u6d4b\u795e\u7ecf\u7f51\u7edc\uff0c\u8fd9\u91cc\u9009\u62e9\u4e86\u6700\u65b0\u6700\u5f3a\u6700\u5feb\u7684YOLO v4. \u4f46\u662f\u5b98\u65b9\u63d0\u4f9b\u7684 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"templates\/template-full-width.php","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[15],"tags":[34,33],"class_list":["post-200","post","type-post","status-publish","format-standard","hentry","category-15","tag-xml","tag-yolo"],"_links":{"self":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/comments?post=200"}],"version-history":[{"count":4,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/200\/revisions"}],"predecessor-version":[{"id":235,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/200\/revisions\/235"}],"wp:attachment":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/categories?post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/tags?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}