yolov3-訓練過程小測
1. 獲取訓練資料
本次測試的訓練資料為公路上的檢測視訊。
2. LabelImage軟體進行標記--得到xml檔案
下載標記軟體進行影象標記,得到每張圖片的xml檔案。可從下面連結中下載Ubuntu版本
3. 由xml得到txt檔案
1)將所有的圖片分為訓練圖片和測試圖片,參考python程式碼如下:
#-*- coding:utf-8 -*-
#將所有圖片分為訓練樣本和測試樣本,存在train.txt和val.txt裡
import os
from os import listdir, getcwd
from os.path import join
if __name__ == '__main__':
source_folder='/home/xxx/images/'#地址是所有圖片的儲存地點
dest='/home/xxx/labels/train_val/train.txt' #儲存train.txt的地址
dest2='/home/xxx/labels/train_val/val.txt' #儲存val.txt的地址
file_list=os.listdir(source_folder) #賦值圖片所在資料夾的檔案列表
train_file=open(dest,'a') #開啟檔案
val_file=open(dest2,'a') #開啟檔案
for file_obj in file_list: #訪問檔案列表中的每一個檔案
file_path=os.path.join(source_folder,file_obj)
#file_path儲存每一個檔案的完整路徑
file_name,file_extend=os.path.splitext(file_obj)
#file_name 儲存檔案的名字,file_extend儲存副檔名
file_num=int(file_name)
#把每一個檔案命str轉換為 數字 int型 每一檔名字都是由四位數字組成的 如 0201 代表 201 高位補零
if(file_num<1000): #保留1000個檔案用於訓練
#print file_num
train_file.write(file_name+'\n') #用於訓練前900個的圖片路徑儲存在train.txt裡面,結尾加回車換行
else :
val_file.write(file_name+'\n') #其餘的檔案儲存在val.txt裡面
train_file.close()#關閉檔案
val_file.close()
2) 根據得到的train.txt和val.txt,分別將訓練和驗證集對應圖片的路徑存到test_train.txt和test_val.txt中
參考python程式碼如下:
# train.txt, generate by creat_list.py, save train image id and names
# val.txt, generate by creat_list.py, save validate image id and names
# need .xml label files,xml files name accord with train image
# this script generate indrared_train.txt file ,used to save train image complete path, and used by the file: voc.data yolo.c
# this script also can generate indrared_val.txt file ,used to save validate image complete path, and used by the file: voc.data #yolo.c
# this script also can generate txt format's yolo recongnition label file, convert by every train or validate xml file, txt format file #name accord xml file name, but differ context and extension name
#this script need accord xml file path and need generate txt complete save path
import xml.etree.ElementTree as ET
import pickle
import os
from os.path import join
classes = ["person", "car", "bus", "truck", "bike", "motorbike", "traffic light", "traffic sign", "taxi"] # class
def convert(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = (box[0] + box[1])/2.0
y = (box[2] + box[3])/2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x*dw
w = w*dw
y = y*dh
h = h*dh
return (x,y,w,h)
def convert_annotation(image_id):
in_file = open('/home/xxx/xml/%s.xml'%(image_id)) #xml file path
out_file = open('/home/xxx/labels/%s.txt'%(image_id),'w')
tree = ET.parse(in_file)
root = tree.getroot()
size = root.find('size') # size label data
w = int(size.find('width').text) #size label data width
h = int(size.find('height').text)#size label data height
for obj in root.iter('object'):
# difficult = obj.find('difficult').text #diffcult label
cls = obj.find('name').text
if cls not in classes :#or int(difficult) == 1:
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox') #visit bounding box label data and process
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
bb = convert((w,h), b)
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
image_ids = open('/home/xxx/labels/train.txt').read().strip().split() #train data
#image_ids = open('/home/xxx/labels/val.txt').read().strip().split() #validate data
list_file = open('/home/xxx/labels/test_train.txt', 'w') #write result to test_train.txt file,train set
#list_file = open('/home/xxx/labels/test_val.txt', 'w') #write result to test_val.txt file,validate set
for image_id in image_ids:
list_file.write('/home/xxx/images/%s.jpg\n'%(image_id))
convert_annotation(image_id)
list_file.close() #close file
4. 訓練
訓練命令:./darknet detector train cfg/myv3_det.data cfg/my_yolov3.cfg darknet53.conv.74
訓練需要.data檔案,.cfg檔案,故需要製作v3.data以及myolov3.cfg
v3.data檔案格式如下:其中包括類別數classes,訓練影象路徑train,類別名字names,以及訓練權重值儲存路徑backup。
classes= 9
train = /home/xxx/data/test_train.txt
names = /home/xxx/data/myv3.names
backup= /home/xxx/train/darknetv3/backup
myolov3.cfg參考的為yolov3.cfg的網路配置檔案,基本引數沒有修噶只是將其中的max_batches改小了。classes改成自分類別數,對應的3處filters=(classes+5)*3進行修改,random=0,為1時跑不起來。
注:訓練:batch=64;subdivisions=8
有需要可以到這個部落格資源頁下載。
3)預訓練模型下載darknet53.conv.74
為了後續的的模型評估,儲存訓練log的命令
./darknet detector train cfg/myv3_det.data cfg/my_yolov3.cfg darknet53.conv.74 -gpus 0,1 2>1 | tee train_yolov3.log
訓練日誌擷取最後一部分
Region 82 Avg IOU: 0.896143, Class: 0.999871, Obj: 0.999981, No Obj: 0.007939, .5R: 1.000000, .75R: 1.000000, count: 15
Region 94 Avg IOU: 0.890928, Class: 0.999866, Obj: 0.999650, No Obj: 0.007638, .5R: 1.000000, .75R: 1.000000, count: 31
Region 106 Avg IOU: 0.850831, Class: 0.999735, Obj: 0.997689, No Obj: 0.002961, .5R: 1.000000, .75R: 0.934783, count: 46
Region 82 Avg IOU: 0.894584, Class: 0.999749, Obj: 0.999900, No Obj: 0.005563, .5R: 1.000000, .75R: 1.000000, count: 7
Region 94 Avg IOU: 0.876964, Class: 0.998086, Obj: 0.974973, No Obj: 0.007528, .5R: 1.000000, .75R: 0.970588, count: 34
Region 106 Avg IOU: 0.751409, Class: 0.982504, Obj: 0.981287, No Obj: 0.002457, .5R: 0.869565, .75R: 0.673913, count: 46
Region 82 Avg IOU: 0.907001, Class: 0.999966, Obj: 0.999952, No Obj: 0.003827, .5R: 1.000000, .75R: 1.000000, count: 4
Region 94 Avg IOU: 0.906861, Class: 0.999881, Obj: 0.999952, No Obj: 0.003209, .5R: 1.000000, .75R: 1.000000, count: 12
Region 106 Avg IOU: 0.761513, Class: 0.986614, Obj: 0.982316, No Obj: 0.003174, .5R: 0.920000, .75R: 0.653333, count: 75
Region 82 Avg IOU: 0.899414, Class: 0.990468, Obj: 0.999981, No Obj: 0.004179, .5R: 1.000000, .75R: 1.000000, count: 4
Region 94 Avg IOU: 0.904084, Class: 0.999623, Obj: 0.999115, No Obj: 0.006000, .5R: 1.000000, .75R: 1.000000, count: 24
Region 106 Avg IOU: 0.772183, Class: 0.977742, Obj: 0.965412, No Obj: 0.003011, .5R: 0.926471, .75R: 0.691176, count: 68
Region 82 Avg IOU: 0.900164, Class: 0.999946, Obj: 0.999902, No Obj: 0.010270, .5R: 1.000000, .75R: 1.000000, count: 17
Region 94 Avg IOU: 0.875355, Class: 0.999732, Obj: 0.999801, No Obj: 0.004528, .5R: 1.000000, .75R: 0.888889, count: 18
Region 106 Avg IOU: 0.838250, Class: 0.999476, Obj: 0.998630, No Obj: 0.001781, .5R: 1.000000, .75R: 0.900000, count: 30
Region 82 Avg IOU: 0.907581, Class: 0.999919, Obj: 0.999991, No Obj: 0.009320, .5R: 1.000000, .75R: 1.000000, count: 14
Region 94 Avg IOU: 0.894800, Class: 0.999890, Obj: 0.999795, No Obj: 0.006231, .5R: 1.000000, .75R: 1.000000, count: 21
Region 106 Avg IOU: 0.833003, Class: 0.998644, Obj: 0.960275, No Obj: 0.001889, .5R: 1.000000, .75R: 0.861111, count: 36
Region 82 Avg IOU: 0.904388, Class: 0.999917, Obj: 0.999940, No Obj: 0.008733, .5R: 1.000000, .75R: 1.000000, count: 10
Region 94 Avg IOU: 0.905678, Class: 0.999758, Obj: 0.999667, No Obj: 0.008275, .5R: 1.000000, .75R: 1.000000, count: 32
Region 106 Avg IOU: 0.832016, Class: 0.999359, Obj: 0.985120, No Obj: 0.002848, .5R: 1.000000, .75R: 0.816326, count: 49
Region 82 Avg IOU: 0.894894, Class: 0.999847, Obj: 0.999894, No Obj: 0.004353, .5R: 1.000000, .75R: 1.000000, count: 6
Region 94 Avg IOU: 0.890745, Class: 0.999662, Obj: 0.994521, No Obj: 0.005623, .5R: 1.000000, .75R: 1.000000, count: 23
Region 106 Avg IOU: 0.856922, Class: 0.999253, Obj: 0.992790, No Obj: 0.003102, .5R: 1.000000, .75R: 0.892857, count: 56
10200: 0.485842, 0.531434 avg, 0.001000 rate, 4.296927 seconds, 652800 images
其中:
Region xx: cfg檔案中yolo-layer的索引;
Avg IOU:當前迭代中,預測的box與標註的box的平均交併比,越大越好,期望數值為1;
Class: 標註物體的分類準確率,越大越好,期望數值為1;
obj: 越大越好,期望數值為1;
No obj: 越小越好;
.5R: 以IOU=0.5為閾值時候的recall; recall = 檢出的正樣本/實際的正樣本
0.75R: 以IOU=0.75為閾值時候的recall;
5. 評估
首先將儲存的log日誌進行篩選:去除不可解析的log後使log檔案格式化,生成新的log檔案供視覺化工具繪圖
選取其中loss和iou資料分別存在train_log_loss.txt和train_log_iou.txt中。
python程式碼參考:
# coding=utf-8
# 該檔案用來提取訓練log,去除不可解析的log後使log檔案格式化,生成新的log檔案供視覺化工具繪圖
import inspect
import os
import random
import sys
def extract_log(log_file,new_log_file,key_word):
with open(log_file, 'r') as f:
with open(new_log_file, 'w') as train_log:
#f = open(log_file)
#train_log = open(new_log_file, 'w')
for line in f:
# 去除多gpu的同步log
if 'Syncing' in line:
continue
# 去除除零錯誤的log
if 'nan' in line:
continue
if key_word in line:
train_log.write(line)
f.close()
train_log.close()
extract_log('my_train_yolov3.log','train_log_loss.txt','images')
extract_log('my_train_yolov3.log','train_log_iou.txt','IOU')
6. 測試
對視訊進行測試命令
./darknet detector demo cfg/v3.data cfg/myolov3.cfg myolov3_final.weights data/test.avi
對圖片進行測試命令
./darknet detect cfg/my_yolov3.cfg my_yolov3_final.weights data/0011.jpg
簡單測試效果還可以。圖突然貼不上了,就不放效果圖了。
相關推薦
yolov3-訓練過程小測
1. 獲取訓練資料 本次測試的訓練資料為公路上的檢測視訊。 2. LabelImage軟體進行標記--得到xml檔案 下載標記軟體進行影象標記,得到每張圖片的xml檔案。可從下面連結中下載Ubuntu版本 3. 由xml得到txt檔案 1)將所有的圖片分為訓
YOLOv3訓練過程筆記
本人使用的是linux平臺,按照YOLO網頁0https://pjreddie.com/darknet/yolo/的步驟操作進行下載darkenet程式包以及編譯,之後可嘗試用VOC2007的資料集測試一下。 下載好的darknet程式包如下圖所示: 注:上圖摘自一篇部落格上的,htt
小白都理解的人工智慧系列(13)——如何加速神經網路訓練過程
問題1:如何加速訓練? SGD將大的資料拆分成一塊塊小的資料進行訓練。 Momentum通過不斷調整w值的形式,朝著梯度往下走,以期儘快達到終點。 AdaGrad方式類似於一個鞋子,一走彎路,
DeepLearning tutorial(2)機器學習算法在訓練過程中保存參數
read com true article detail spec ear ase 例如 我是小白,說的不是很好,請原諒 @author:wepon @blog:http://blog.csdn.net/u012162613/article/details/43169019
oracle 小測
style 進行 創建索引 回滾 小寫 比較 相關 空白 訪問 01)oracle10i,oracle11g,oracle12c,其它i,g,c什麽意思? i(Internet)互聯網 g(grid)網格 c(cloud) 雲02)sqlplus是什
Vue組件vue-router使用方法小測
ddd ext 我們 簡單的 一個 lis ima span leave 1.首先下載並載入js腳本: <script type="text/javascript" src="./vue.js" ></script> <script ty
安裝nvm的過程小記錄
官網 特定 arc 目前 line org pro 。。 記錄 我的nvm安裝安裝步驟記錄: 因為node的版本更新太快了,而我們的某些項目又需要在特定版本的node下工作,這時就用到了我們強大的nvm了。 nvm:Node Version Manager(node版本
福州大學W班-團隊作業-隨堂小測(同學錄)成績
9.png 工作 htm 命令 soft 情況 總結 提交代碼 編寫 作業鏈接 https://edu.cnblogs.com/campus/fzu/FZUSoftwareEngineering1715W/homework/1246 作業要求 1、題目 即編寫一個
20180507小測
swap ray ring 睡覺 image ati nod info UC 對我而言相當失敗的一次考試呢。(昨天失了智一晚上沒睡覺還好意思說)T1: 看到數據範圍與值域有關,是不是想到了一些有趣的事情呢?兩兩gcd為1,顯然我們把同時選出的數分解質因子後,每個質數出現最多
卷積神經網絡(CNN)的訓練過程
假設 特征向量 left 傳遞 方法 輸出 1.3 組成 初始化 卷積神經網絡的訓練過程 卷積神經網絡的訓練過程分為兩個階段。第一個階段是數據由低層次向高層次傳播的階段,即前向傳播階段。另外一個階段是,當前向傳播得出的結果與預期不相符時,將誤差從高層次向底層次進行傳播訓練的
Caffe初學者第一部:Ubuntu14.04上安裝caffe(CPU)+Python的詳細過程 (親測成功, 20180524更新)
cython ase n-n 4.5 ipython 下載速度 nds evel CI 前言: 最近在學習深度學習,最先要解決的當然是開源框架的環境安裝了。之前一直在學習谷歌的Tensorflow開源框架,最近實驗中需要跟別人的算法比較,下載的別人的代碼很多都是Caffe的
TensorFlow之tf.nn.dropout():防止模型訓練過程中的過擬合問題
AC -- 輸出 array 全連接 spa () 激活 odin 一:適用範圍: tf.nn.dropout是TensorFlow裏面為了防止或減輕過擬合而使用的函數,它一般用在全連接層 二:原理: dropout就是在不同的訓練過程中隨機扔掉一部分神經元。也就是
20180618小測
png 表示 lap ddb bit BE mea oid 分享圖片 為什麽今天還考試啊......T1: 一眼不可做。想維護分組狀態,用最小表示法,總共8個集合,狀態量400+,不可做。棄療寫了20分的puts。正解是容斥。我們設f[i][j][k]為考慮i位,j個串,
20180620小測
stp init ide 如果 tree count ret display b- 為什麽這麽多原題......T1: 這題我做過,「BZOJ2568: 比特集合」了解一下,此題終結。代碼: 1 #pragma GCC optimize("Ofast") 2 #in
20180702小測
hide max reg aps %d push != polya iostream 這場考試我其實並沒有參加......因為一些奧妙重重的原因肚子疼到厭生,沒看完題就滾回家了......馬上就NOI了還是這種身體狀態,真是要完。T1: 我們先把所有點雙聯通分量縮起來。
Yolo系列學習1-Yolov3訓練福彩快三平臺出租自己的數據
平臺 sprint rectangle 修改文件 ted issues printf res idt 目的:福彩快三平臺出租 haozbbs.com Q1446595067 實現利用yolov3訓練自己的數據集(voc格式) 方法: 1)構建VOC數據集 將你手中的數據
YOLOv3訓練自己的數據集(還在學習中)
tail x64 自己 bubuko lov link win10 info 問題 其他比較好的參考鏈接: YOLOv3官網鏈接GitHub:https://github.com/AlexeyAB/darkne Yolov3+windows10+VS2015部署安裝:htt
DeepTracker: Visualizing the Training Process of Convolutional Neural Networks(對卷積神經網絡訓練過程的可視化)
training ces ini net mini 個人 src works con \ 裏面主要的兩個算法比較難以贅述,miniset主要就是求最小公共子集。(個人認為)DeepTracker: Visualizing the Train
YOLOv3訓練自己的數據
roo 所有 打開終端 target label ext make rename read 1.下載官網的YOLOv3,打開終端輸入:git clone https://github.com/pjreddie/darknet下載完成之後,輸入:cd darknet,然後再輸
策略梯度訓練cartpole小遊戲
我原來已經安裝了anaconda,在此基礎上進入cmd進行pip install tensorflow和pip install gym就可以了. 在win10的pycharm做的。 policy_gradient.py 1 # -*- coding: UTF-8 -*- 2 3 """ 4