{"id":3038,"date":"2020-05-04T01:12:52","date_gmt":"2020-05-04T01:12:52","guid":{"rendered":"https:\/\/cloudxlab.com\/blog\/?p=3038"},"modified":"2020-05-24T16:16:31","modified_gmt":"2020-05-24T16:16:31","slug":"label-custom-images-for-yolo","status":"publish","type":"post","link":"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/","title":{"rendered":"How to label custom images for YOLO &#8211; YOLO 3"},"content":{"rendered":"\n<p>In this blog we will show how to label custom images for making your own YOLO detector. We have other blogs that cover how to setup Yolo with Darknet, running object detection on images, videos and live CCTV streams. If you want to detect items not covered by the general model, you need custom training.<\/p>\n\n\n\n<p>In our case we will build a truck type detector. There are 4 types of trucks we will try to identify<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img src=\"https:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2020\/05\/pic62tanker.jpg\" alt=\"How to label custom images for Yolo\" class=\"wp-image-3041\" width=\"281\" height=\"281\"\/><figcaption>Tanker example<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img src=\"https:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2020\/05\/vehicle_50_frame_12360.png\" alt=\"How to label custom images for Yolo\" class=\"wp-image-3043\" width=\"277\" height=\"81\"\/><figcaption>Flatbed example<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"260\" height=\"118\" src=\"https:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2020\/05\/dumper_8.jpg\" alt=\"How to label custom images for Yolo\" class=\"wp-image-3044\"\/><figcaption>Dumper example<br><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"260\" height=\"194\" src=\"https:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2020\/05\/images-3semiflat.jpeg\" alt=\"How to label custom images for Yolo \" class=\"wp-image-3046\"\/><figcaption>Semiflat example<\/figcaption><\/figure>\n\n\n\n<h2>Directory Structure for custom YOLO training<\/h2>\n\n\n\n<p>We will follow the directory structure seen in the bloc below. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\u2514\u2500\u2500 workspace\n    \u251c\u2500\u2500 darknet\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 backup\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 cfg\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 data\n    \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 labels\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 examples\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 include\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 obj\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 python\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 results\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 scripts\n    \u2502\u00a0\u00a0 \u2514\u2500\u2500 src\n    \u251c\u2500\u2500 images\n    \u2502\u00a0\u00a0 \u251c\u2500\u2500 test\n    \u2502\u00a0\u00a0 \u2514\u2500\u2500 train\n    \u2514\u2500\u2500 labels\n        \u251c\u2500\u2500 test\n        \u2514\u2500\u2500 train<\/code><\/pre>\n\n\n\n<p>We will now explain the directory structure and explain what is saved where.<\/p>\n\n\n\n<ol><li>workspace &#8211; parent directory that contains all the other directories<\/li><li>darknet &#8211; We will install darknet in this folder.  The commands for installation of darknet can be found in this<a href=\"https:\/\/cloudxlab.com\/blog\/setup-yolo-with-darknet\/\"> blog.<\/a><\/li><li>images &#8211; This contains all the images, sub-divided in the train and test sets. The train images contain the set of images YOLO will be trained on.  We will run evaluation on the images in the test set. We will save all our images in these directories<\/li><li>labels &#8211; We will keep all labels both test and train in this directory<\/li><\/ol>\n\n\n\n<h2>How to label custom images for Yolo with LabelImg<\/h2>\n\n\n\n<p>We will use <a href=\"https:\/\/github.com\/tzutalin\/labelImg\">LabelImg<\/a> to label images. LabelImg is available on mac, windows and unix. LabelImg is written in Python and QT5. I will again recommend that you use virtualenv to create a separate Python working environment for LabelImg. <\/p>\n\n\n\n<p>I installed LabelImg on my Mac with the commands listed on the <a href=\"https:\/\/github.com\/tzutalin\/labelImg\">github page<\/a>. We will first create a classes.names file. In this file we will list all the labels we will use in labelling.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">tanker\ndumper\nflatbed\nsemiflat<\/code><\/pre>\n\n\n\n<p>We have 4 labels for our dataset. Make sure you do this correctly. In case you edit this file later, you may have to re-do the annotation. We will keep this file in the darknet\/data directory. The command to launch the labelImg is<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]<\/code><\/pre>\n\n\n\n<ol><li>Build and launch using the instructions above.<\/li><li>Click &#8216;Change default saved annotation folder&#8217; in Menu\/File to the appropriate location in the labels directory. The labels for the test set should be labels\/test and train should be in labels\/train. The Yolo training tool will look for the label files in this directory. Alternately, you can also copy the label txt files <\/li><li>Change the save format to YOLO from the Pascal VOC<\/li><li>To open files click &#8216;Open Dir&#8217;<\/li><li>Click &#8216;Create RectBox&#8217; and release left mouse to select a region to annotate the rect box<\/li><li>You can use right mouse to drag the rect box to copy or move it<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"1199\" height=\"755\" src=\"https:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2020\/05\/Screenshot-2020-05-04-at-6.09.56-AM.png\" alt=\"\" class=\"wp-image-3047\"\/><figcaption>How to label custom images for YOLO using LabelImg<\/figcaption><\/figure>\n\n\n\n<p>The process of labelling can be painstaking and long. Use some of <a href=\"https:\/\/github.com\/tzutalin\/labelImg#hotkeys\">LabelImg&#8217;s shortcuts<\/a> to reduce the tedium. <\/p>\n\n\n\n<h2>Interpreting the label file<\/h2>\n\n\n\n<p>Open the label file to understand what labelling is. A sample file can look like this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">2 0.498408 0.509804 0.990446 0.980392<\/code><\/pre>\n\n\n\n<p>The format of the label file is <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">Label_ID_1 X_CENTER_NORM Y_CENTER_NORM WIDTH_NORM HEIGHT_NORM\nLabel_ID_2 X_CENTER_NORM Y_CENTER_NORM WIDTH_NORM HEIGHT_NORM<\/code><\/pre>\n\n\n\n<p>The label_id is the index number in the classes.names file. The id of the first label will be 0 and an increasing integer after that. Note all the position attributes in the label file are not absolute but normalised. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">X_CENTER_NORM = X_CENTER_ABS\/IMAGE_WIDTH\nY_CENTER_NORM = Y_CENTER_ABS\/IMAGE_HEIGHT\nWIDTH_NORM = WIDTH_OF_LABEL_ABS\/IMAGE_WIDTH\nHEIGHT_NORM = HEIGHT_OF_LABEL_ABS\/IMAGE_HEIGHT<\/code><\/pre>\n\n\n\n<p>The labelling of the images is now done and we can start training the YOLO now. The training will be covered in another blog as part of this series.<\/p>\n\n\n\n<ol><li><a href=\"https:\/\/cloudxlab.com\/blog\/setup-yolo-with-darknet\/\">YOLO with Darknet<\/a><\/li><li><a href=\"https:\/\/cloudxlab.com\/blog\/object-detection-yolo-and-python-pydarknet\/\">Running YOLO with python<\/a><\/li><li><a href=\"https:\/\/cloudxlab.com\/blog\/how-to-run-yolo-on-cctv-feed\/\">YOLO on the CCTV feed<\/a><\/li><li>Custom training with YOLO<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we will show how to label custom images for making your own YOLO detector. We have other blogs that cover how to setup Yolo with Darknet, running object detection on images, videos and live CCTV streams. If you want to detect items not covered by the general model, you need custom training. &hellip; <a href=\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to label custom images for YOLO &#8211; YOLO 3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":26,"featured_media":3047,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[67,1],"tags":[61],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to label custom images for YOLO - YOLO 3 | CloudxLab Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to label custom images for YOLO - YOLO 3 | CloudxLab Blog\" \/>\n<meta property=\"og:description\" content=\"In this blog we will show how to label custom images for making your own YOLO detector. We have other blogs that cover how to setup Yolo with Darknet, running object detection on images, videos and live CCTV streams. If you want to detect items not covered by the general model, you need custom training. &hellip; Continue reading &quot;How to label custom images for YOLO &#8211; YOLO 3&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/\" \/>\n<meta property=\"og:site_name\" content=\"CloudxLab Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cloudxlab\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-04T01:12:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-24T16:16:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2020\/05\/Screenshot-2020-05-04-at-6.09.56-AM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1199\" \/>\n\t<meta property=\"og:image:height\" content=\"755\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CloudxLab\" \/>\n<meta name=\"twitter:site\" content=\"@CloudxLab\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"3 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/#website\",\"url\":\"https:\/\/cloudxlab.com\/blog\/\",\"name\":\"CloudxLab Blog\",\"description\":\"Learn AI, Machine Learning, Deep Learning, Devops &amp; Big Data\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/cloudxlab.com\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2020\/05\/Screenshot-2020-05-04-at-6.09.56-AM.png\",\"contentUrl\":\"https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2020\/05\/Screenshot-2020-05-04-at-6.09.56-AM.png\",\"width\":1199,\"height\":755},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/#webpage\",\"url\":\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/\",\"name\":\"How to label custom images for YOLO - YOLO 3 | CloudxLab Blog\",\"isPartOf\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/#primaryimage\"},\"datePublished\":\"2020-05-04T01:12:52+00:00\",\"dateModified\":\"2020-05-24T16:16:31+00:00\",\"author\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/#\/schema\/person\/e2c5cc7b933ebd4b15f9b463dc7cf1b4\"},\"breadcrumb\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/\",\"url\":\"https:\/\/cloudxlab.com\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/label-custom-images-for-yolo\/#webpage\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/#\/schema\/person\/e2c5cc7b933ebd4b15f9b463dc7cf1b4\",\"name\":\"Praveen Pavithran\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/03c8d253347dcf9e04ec550cd6144973?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/03c8d253347dcf9e04ec550cd6144973?s=96&d=mm&r=g\",\"caption\":\"Praveen Pavithran\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts\/3038"}],"collection":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/comments?post=3038"}],"version-history":[{"count":4,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts\/3038\/revisions"}],"predecessor-version":[{"id":3081,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts\/3038\/revisions\/3081"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/media\/3047"}],"wp:attachment":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/media?parent=3038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/categories?post=3038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/tags?post=3038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}