Yolo-实时目标检测算法训练自己的数据集教程

This tutorial is a English version, written by JinTian master, if you have any question about this blog, welcome contact me by WeChat: jintianiloveu I'd like to help you out. Besides this is a redesign work of original yolo, if you like this ,you can give a star of this repository at github, :)

Preface

GreatDarknet was the edit version of darknet created by pjreddie. Thanks for the author's excellent work. The purpose of redesign of darknet was for other people to train their own data and get the predict result. I will give you a detail usage of this version of darknet which can be called GreatDarknet.

Preparing Data for GreatDarknet

  • 1. get your all image train paths in a single txt file

For example, you have a dataset which has 7000 images for train, and 2000 images for test. You can simply place your train images in a single file, says "MyDatasets" just along side your GreatDarknet directory. And inside MyDatasets you can mkdir a TrainImages and a TestImages folder.So, just drop all your train images into TrainImages folder, and live anything else to GreatDarknet.

  • 2. get your image labels

To get your image labels, you must follow the format as darknet identify, every image has a label file you can generate it in a txt file, so if you have 7000 train images, it means you have to get 7000 labels txts. For every single label txt file, you must have the format like:

0 0.45315024232633283 0.4906417112299465 0.019386106623586433 0.06149732620320855
0 0.4369951534733441 0.5066844919786095 0.05654281098546042 0.10962566844919786
0 0.11227786752827142 0.5788770053475936 0.14378029079159937 0.16310160427807485
0 0.29361873990306947 0.5026737967914439 0.05573505654281099 0.0909090909090909

for more detail, it can be describe as follow:

class x_1 y_1 x_2 y_2

Here is the explain:
class: must be a int(str actually) value, etc. you have 4 classes "Apple", "Banana", "Peal", "Orange", Apple should presents 0.
x_1 is the left x coordinate, y_1 is the bottom y coordinate, x_2 is the right x coordinate, y_2 is the top y coordinate, so if x_2 bigger then x_1, and y_2 bigger then y_1, then you are all right.

  • 3. get your test images

This is the last step of your datasets setup, and it is easy too! You just only place all your test images into TestImages which mkdir in MyDatasets directory, and just alongside the TrainImages folder.Ok, you are all done!

  • 4. just place your labels and train images into one folder
    This is very important, do not ask why just put your images file and labels file into a single folder togther and GreatDarknet will automatic get them and start train.

Change Some Config File of GreatDarknet

  • 1. make GreatDarknet and change Makefile

Simply sudo vim MakeFile and change the following value:

GPU=1
CUDNN=0
OPENCV=1
DEBUG=1

this are not essential but with out OPENCV you may cannot see the image predict immediately.

  • 2. change your cfg/yourdataset.data file

If you train your own dataset, you must tell GreatDartknet where your images and labels is. To do this, you can mkdir a *.data file inside cfg/ directory. And type some cfg command like this:

classes= 1
train  = ~/MyDataSets/train.txt
names = ~/GreatDarknet/data/names.list
backup = ~/GreatDarknet/backup/
results = ~/GreatDarknet/results/

Here is the explain:
classed: this is all your classes in your datasets
train: this is the train.txt file which contains all your image path, we generated it above.
names: this is your classes names file inside data/ directory, you may change its content but Do not change file name!.
backup; this is the directory of weigths save, just left it do not change it
results: this is the save path of predict labels.
so , in this step, you just only need to Change your train list path and names.list content!

Train your model with your own datasets!

Just type this command:

./darknet detector train cfg/voc.data cfg/yolo-voc.cfg darknet19_448.conv.23

`darknet19_448.conv.23' is the pretrained model weights.

Test Model and Generate All Image Predict txt File

Just type this commond in terminal:

./darknet detector test_save cfg/voc.data cfg/yolo-voc.cfg backup/yolo-voc_12000.weights /media/jinfagang-workspace/Jinfagang-Use/YOLO/GreatDarknet/results/kitti_test_pedestrian /media/jinfagang-workspace/Jinfagang-Use/YOLO/KITTI/test.txt

cfg/voc.data is the data statement tells net where the data is and how to save weights
cfg/yolo-voc.cfg is the structure of yolo-net,
'backup/yolo-voc_12000.weights' is the model weights which you have trained.
the last two params is very important.
last 1: is the save path prefix, do not add '/' at end of path prefix.
last 2: is the test.txt file location, use the full path avoid absolute path.

Predict Single Image using GreatDarknet

To predict just type this commond:

./darknet detector predict cfg/voc.data cfg/yolo-voc.cfg backup/yolo-voc_12000.weights data/test.jpg

And there it is! You now have a Intelligent Net which can recogonise specify objects!!!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,456评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,370评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,337评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,583评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,596评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,572评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,936评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,595评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,850评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,601评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,685评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,371评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,951评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,934评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,167评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,636评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,411评论 2 342

推荐阅读更多精彩内容