Yolo-實(shí)時(shí)目標(biāo)檢測算法訓(xùn)練自己的數(shù)據(jù)集教程

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!!!!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末华畏,一起剝皮案震驚了整個(gè)濱河市辛友,隨后出現(xiàn)的幾起案子办陷,更是在濱河造成了極大的恐慌膨报,老刑警劉巖瞳步,帶你破解...
    沈念sama閱讀 216,997評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件抠璃,死亡現(xiàn)場離奇詭異术奖,居然都是意外死亡礁遵,警方通過查閱死者的電腦和手機(jī)轻绞,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,603評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來佣耐,“玉大人政勃,你說我怎么就攤上這事〖孀” “怎么了奸远?”我有些...
    開封第一講書人閱讀 163,359評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長讽挟。 經(jīng)常有香客問我懒叛,道長,這世上最難降的妖魔是什么耽梅? 我笑而不...
    開封第一講書人閱讀 58,309評(píng)論 1 292
  • 正文 為了忘掉前任薛窥,我火速辦了婚禮,結(jié)果婚禮上眼姐,老公的妹妹穿的比我還像新娘诅迷。我一直安慰自己,他們只是感情好众旗,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,346評(píng)論 6 390
  • 文/花漫 我一把揭開白布罢杉。 她就那樣靜靜地躺著,像睡著了一般逝钥。 火紅的嫁衣襯著肌膚如雪屑那。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,258評(píng)論 1 300
  • 那天艘款,我揣著相機(jī)與錄音持际,去河邊找鬼。 笑死哗咆,一個(gè)胖子當(dāng)著我的面吹牛蜘欲,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播晌柬,決...
    沈念sama閱讀 40,122評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼姥份,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了年碘?” 一聲冷哼從身側(cè)響起澈歉,我...
    開封第一講書人閱讀 38,970評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎屿衅,沒想到半個(gè)月后埃难,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,403評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,596評(píng)論 3 334
  • 正文 我和宋清朗相戀三年涡尘,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了忍弛。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,769評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡考抄,死狀恐怖细疚,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情川梅,我是刑警寧澤疯兼,帶...
    沈念sama閱讀 35,464評(píng)論 5 344
  • 正文 年R本政府宣布,位于F島的核電站贫途,受9級(jí)特大地震影響镇防,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜潮饱,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,075評(píng)論 3 327
  • 文/蒙蒙 一来氧、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧香拉,春花似錦啦扬、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,705評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至盛险,卻和暖如春瞄摊,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背苦掘。 一陣腳步聲響...
    開封第一講書人閱讀 32,848評(píng)論 1 269
  • 我被黑心中介騙來泰國打工换帜, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人鹤啡。 一個(gè)月前我還...
    沈念sama閱讀 47,831評(píng)論 2 370
  • 正文 我出身青樓惯驼,卻偏偏與公主長得像,于是被迫代替她去往敵國和親递瑰。 傳聞我的和親對(duì)象是個(gè)殘疾皇子祟牲,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,678評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容