How to training AI with YOLO tensorflow ?
บทความนี้จะพูดถึงขั้นตอนการ training AI โดยใช้โมเดล YOLO tensorflow ซึ่งอิงมาจาก github
ขั้นตอนการทำ
1. โหลดโมเดล darkflow โดยการเข้าไปที่ ลิ้งนี้ แล้วทำการดาวน์โหลด Zip ไฟล์พร้อมทั้งแตกไฟล์ไว้ในโฟล์เดอร์ที่ต้องการ หรือทำการ compile ผ่านหน้า command line ดังนี้
git clone https://github.com/thtrieu/darkflow cd tensorflow-for-poets-2
2. ทำการเข้าไปที่โฟล์เดอร์ cfg แล้ว duplicate tiny-yolo-voc.cfg และแก้ไขชื่อไฟล์ตามที่ต้องการเช่น yolo-car.cfg
3. ทำการแก้ไขข้อมูลข้างในไฟล์ yolo-car.cfg
3.1 ) ใน layer region แก้ไขจำนวน class ตามตามจำนวนที่ทำการ train
... [region] anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52 bias_match=1 classes=3 //แก้ไขจำนวน class coords=4 num=5 softmax=1 ...
3.2 ) ใน layer convolution แก้ไขจำนวน filter โดยมีสูตรการคำนวนคือ filter = num*(class+5)
... [convolutional] size=1 stride=1 pad=1 filters=40 // num*(class+5) activation=linear [region] anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52 ...
4. แก้ไขข้อมูลในไฟล์ labels.txt โดยทำการใส่ชื่อ class ทั้งหมดลงไป
label1
label2
label3
5. ทำการ train data โดยการ compile ผ่านหน้า command line ดังนี้
## บันทึกรูปภาพไว้ในโฟลเดอร์ train/Image และบันทึก xml ไฟล์ไว้ที่ train/Annotations สำหรับวิธีการสร้าง xml ไฟล์สามารถดูต่อได้ใน คลิ้กที่นี่
flow --model cfg/yolo-car.cfg --train --annotation train/Annotations --dataset train/Image --gpu 1.0
6. เมื่อทำการ train data เสร็จ ทำการ save model เป็น .pb และ .meta โดยการ compile ผ่านหน้า command line ดังนี้
## บันทึกที่ check point ล่าสุด
flow --model cfg/yolo-car.cfg --load -1 --savepb
7. ทดสอบความถูกต้องของ model ดังนี้
## ทดสอบกับรูปภาพที่อยู่ในโฟลเดอร์ sample_img
flow --pbLoad built_graph/yolo.pb --metaLoad built_graph/yolo.meta --imgdir sample_img/
ความคิดเห็น
แสดงความคิดเห็น