Yolov4 train you data
Yolov4
source code:https://github.com/AlexeyAB/darknet
paper source:https://arxiv.org/pdf/2004.10934.pdf
As everyone need knows : README.MD file,
This file has told you each steps how to run this source code.
I have test the yolov3 version but i forget to write down the method of using .
Maybe one day i will compelete this blog: Not compelete
Environment needed(Requirements):
- Cmake>=3.12
- CUDA=10.0 or above
- opencv>=2.4
- cudnn>7.0
- GPU with CC >= 3.0
My Env: Ubuntu 18.04 CUDA 10.0 Cudnn7.5 opencv3.2
If you wanna know how to set up the CUDA and Cudnn you can see my blog: CUDA10.0+Cudnn7.5 install
Opencv how to setup by source code and setup the contrib you can see my blog :
setup opencv by source code
setup opencv by python pip
How to use this Yolov4:
Tips: each times you wanna to make the source code :you should do make clean
first.
Tips: if you wanna to change you env you can change the a file in the root:Makefile
you will see the cuda cudnn opencv and so on setting. you can set the cuda =1 or opencv=1
------------ You have Cuda +Cudnn:
- If you have Cuda and Cudnn in the above requirments : ( TIPS: Don’t know below this version can work out )
- In your root dir ,open the
Makefile
this file ,use this commandsudo vim Makefile
and you can see the cuda cudnn and others ,you should set the value =1 F.E.cuda = 1
. - And use the command
make
- And can use the command
make clean
to clean the make file .
-------------You have opencv(cpu):
- If you have Opencv=1 in the above requirments : ( TIPS: Opencv version>=2.4)
- In your root dir ,open the
Makefile
this file ,use this commandsudo vim Makefile
and edit the line with opencv set the value 1. - and then use the command
make
-------------You only have cpu:
warning:if you only have cpu ,better to only use not to train . cuz that if you train will use so long time and will be harm to your cpu.
- First set your all value = 0 in the file with name of
Makefile
- And use the command
make
--------------Use the demo:
Just use the command ./darknet detect cfg/yolov4.cfg yolov4.weights data/dog.jpg
How to train or set data:
- You should using command template
./darknet detector train data/obj.data yolov3-tiny-obj.cfg yolov3-tiny.conv.15
Set your data :
- Use the tool Labelmg,this using method is very easy ,you can find easily .
F.e. website: https://blog.csdn.net/learning_tortosie/article/details/80947301
You can follow steps , it’s useful.
- And when you set your data you should using is VOCdevkit
- In the Yolov3 ,there are a
voclabel.py
file to set the image the mark matrix is using thexmin,ymin,xmax,ymax,classes
behind the path of image . But in the Yolov4 there arevoclabel.py
in the scripts file and this python willl create a new “.txt” and this mark Matrix using another way to mark F.e.<object-class> <x_center> <y_center> <width> <height>
, this Matrix can using to tell the classes. - So you need to edit the
voclabel,py
the classes you should change to your own classses - Creat the cfg file in the file (copy yolov4-custom.cfg) --name of “cfg” you can use name yolo-obj.cfg
- And edit the the cfg:
- change line batch to [
batch=64
] - change line subdivisions to [
subdivisions=16
] - change line max_batches to (
classes*2000
but not less than number of training images, and not less than6000
), f.e. [max_batches=6000
] - change line steps to 80% and 90% of max_batches, f.e. [
steps=4800,5400
] - set network size
width=416 height=416
or any value multiple of 32 - change line
classes=80
to your number of objects in each of 3[yolo]
-layers - change [
filters=255
] to filters=(classes + 5)x3 in the 3[convolutional]
before each[yolo]
layer, keep in mind that it only has to be the last[convolutional]
before each of the[yolo]
layers.
*(TIPS: you should edit the line before each of the yolo layers)
- create classes names in the file
build\darknet\x64\data\
- By using the step 2 and step 3 you will get the new file in the
VOCdevkit/VOC2007/labels/
in this file you will see the.txt
file is Matrix - you can use the 2007_train.txt to set in the
obj.data
- the train command is
./darknet detector train data/obj.data /home/fox/yolo4/darknet-master/darknet-master/build/darknet/x64/data/yolo-obj.cfg /home/fox/yolo4/darknet-master/darknet-master/data/yolov4.conv.137
TIPS: you need to download the weights in firstly!!!
yolov4-conv.137 :download
My test result:(2 classes: plate car):
Thanks:
code:https://github.com/AlexeyAB/darknet