Author Topic: How to train YOLOv2 on custom dataset  (Read 63 times)

0 Members and 1 Guest are viewing this topic.

Offline Flavio58

How to train YOLOv2 on custom dataset
« Reply #1 on: February 05, 2019, 04:05:05 AM »
Advertisement
How to train YOLOv2 on custom dataset

Update 1: I found way better article on how to train YOLOv2  here   YOLOv2 is open source state-of-the-art real-time object detector that is written on deep learning framework darknet in C language https://pjreddie.com/darknet/yolo/ . Simple guide to reproduce results in the YOLOv2 paper is provided at author’s blog. To train on custom dataset some elegant instructions … Continue reading How to train YOLOv2 on custom dataset

Update 1: I found way better article on how to train YOLOv2  here


 


YOLOv2 is open source state-of-the-art real-time object detector that is written on deep learning framework darknet in C language https://pjreddie.com/darknet/yolo/ . Simple guide to reproduce results in the YOLOv2 paper is provided at author’s blog.


To train on custom dataset some elegant instructions are given on windows port of the YOLO at https://github.com/AlexeyAB/darknet .


Here I will show hands on approach to train YOLOv2 detector (If you cannot see the images clearly, please zoom in the browser)


Task


Detect/Count 8 types of Beverage Bottles: pepsi,7up, mirinda, dolina_olma, dolina_behi, dolina_olcha, dolina_limon, dolina_apelsin


Dataset Preparation


As said above I use PEPSI dataset, it contains around 150 images, even though it is small, for our example during this post that should be enough.


I annotated the dataset using YOLO-MARK annotation tool.  For a tutorial on this visit here https://github.com/AlexeyAB/Yolo_mark .


Put all the class labels into obj.names  file. So content looks like this:


Untitled


Then start the program and start labeling:


Untitled.png


 



As a result of annotation we will have corresponding .txt file for each images where *.txt file contains YOLO format annotations


Untitled.png


 


next I moved all the *.txt files and put them into labels folder and rename the img  folder to images


So now my folder looks like this


Untitled


Since we changed the img folder name to images folder name, now we have to to change train.txt accordingly.


Untitled.png


One last step is to put full paths to images instead of relative paths. Because later darknet will access this file from outside.


Untitled.png


Training


Network CFG



  1. copy  yolo-voc.cfg from https://github.com/Jumabek/darknet/blob/master/cfg/yolo-voc.cfg and rename it as pepsi.cfg

  2. change filters=125 in last convolutional layer to filters=65      which is (5+8)*5.  Here first 5 corresponds to (x,y,w,h,objectness_score), 8 corressponds to number of classes, in my case I have 8 classes. Last 5 corressponds to number of BoundingBox predictions for each cell.

  3. change classess=20 to classess=8


Now this is how our cfg file looks like


Untitled.png


I have 4 GB GTX 1050 GPU on my laptop, so I set batch=64 and subdivisions=8. That way my GPU will process 64/8 = 8 images in one pass. Lets say if you have 8GB GPU memory then you can set batch=64 and subdivisions=4. In order to take advantage of all of your gpu memory in order to speed up the training


Untitled


Creating *.data and *.names files



  1. Copy obj.names and obj.data files (that we created in Data Preparation step with YOLO_MARK) to C:\darknet\build\darknet\x64\data

  2. rename obj.names to pepsi.names

  3. rename obj.data to pepsi.dataUntitled.png

  4. Fix the paths in pepsi.data to point to right files as followsUntitled.png

  5. Download darknet19_448.conv.23 pre-trained weights from https://pjreddie.com/media/files/darknet19_448.conv.23 and put into C:\darknet\build\darknet\x64\backup folder


Finally Start training


darknet.exe detector train data/pepsi.data cfg/pepsi.cfg backup\\darknet19_448.conv.23 >> pepsi.log


Training log will be saved in pepsi.log file, so you can monitor loss, recall and other things by accessing this file.


Untitled.png


Enjoy your cup of coffe and come back later ????


Important: I try making tutorial on how to get best out of YOLO training in another post. So, stay tuned!


 


Source: How to train YOLOv2 on custom dataset


Consulente in Informatica dal 1984

Software automazione, progettazione elettronica, computer vision, intelligenza artificiale, IoT, sicurezza informatica, tecnologie di sicurezza militare, SIGINT. 

Facebook:https://www.facebook.com/flaviobernardotti58
Twitter : https://www.twitter.com/Flavio58

Cell:  +39 366 3416556

f.bernardotti@deeplearningitalia.eu

#deeplearning #computervision #embeddedboard #iot #ai

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
162 Views
Last post March 17, 2018, 06:25:04 AM
by Ruggero Respigo
0 Replies
262 Views
Last post March 18, 2018, 01:23:04 AM
by Ruggero Respigo
How to train YOLOv2 on custom dataset

Started by Ruggero Respigo Jumabek

0 Replies
169 Views
Last post June 07, 2018, 11:45:12 AM
by Ruggero Respigo
0 Replies
9 Views
Last post June 26, 2019, 08:26:56 AM
by Flavio58
0 Replies
5 Views
Last post June 29, 2019, 04:08:10 PM
by Flavio58

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326