日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

用SSD训练自己的数据集

發布時間:2024/9/21 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用SSD训练自己的数据集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1構建 數據集

先來看一下我們構建數據集合應該是什么樣的,假設總數據為1000張。
為了方便,我們將數據放在/home/bingolwang/data 文件夾下。/home/bingolwang/data/VOCdevkit 這個目錄下是VOC2007

VOC2007/ |-- Annotations #1000個xml文件。 |-- ImageSets | `-- Main | |-- test.txt #測試集 | `-- trainval.txt #訓練集 `-- JPEGImages #1000個jpg文件
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

仔細看看 test.txt ,trainval.txt 這兩個文件的格式,

test.txt 00002 #其實就是去掉了對應的 .jpg 00003 00100 00012 ..... trainval.txt #圖片的名字到底有什么要求?不一定是6位碼,也不一樣定是從00000開始,只要 00000 #區分的開各個圖片即可 00001 00004 00005 .....
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

JPEGImages ,Annotations文件夾中的內容

#Annotations dir 下的內容 00000.xml 00001.xml 00002.xml 00003.xml ......xml 01000.xml #JPEGImages dir 下的內容 00000.jpg 00001.jpg 00002.jpg 00003.jpg ......jpg 01000.jpg
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在來看看xml中的內容,這舉例00005.xml。

<annotation><folder>images</folder><filename>00005.jpg</filename><source><database>bingolwangDataSet</database></source><size><width>435</width><height>363</height><depth>3</depth></size><object><name>Object</name><difficult>0</difficult><bndbox><xmin>37</xmin><ymin>318</ymin><xmax>428</xmax><ymax>358</ymax></bndbox></object> </annotation>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

注意:實際上在ssd官方(github:https://github.com/weiliu89/caffe/tree/ssd)的文件中,使用的create_list.sh 創建了生成lmdb所需要的各種文件。這里,我們手動創建,因為根本用不了那么復雜的腳本。

create_data.sh 就是創建訓練輸入的lmdb。他的輸入是 labelmap_voc.prototxt | test.txt | trainval.txt ,這三個文件。
還是得看一下,這三個文件都是什么格式。

# trainval.txt VOC2007/JPEGImages/105df.jpg VOC2007/Annotations/105df.xml VOC2007/JPEGImages/ww231.jpg VOC2007/Annotations/ww231.xml VOC2007/JPEGImages/763005.jpg VOC2007/Annotations/763005.xml#test.txt VOC2007/JPEGImages/0b73.jpg VOC2007/Annotations/0b73.xml VOC2007/JPEGImages/c5ccbe1.jpg VOC2007/Annotations/c5ccbe1.xml VOC2007/JPEGImages/ec5f0.jpg VOC2007/Annotations/ec5f0.xml VOC2007/JPEGImages/a0341.jpg VOC2007/Annotations/a0341.xml#labelmap_voc.prototxt #single object item {name: "none_of_the_above"label: 0display_name: "background" } item {name: "Object"label: 1display_name: "Object" }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

準備好了上述文件,就可以git clone https://github.com/weiliu89/caffe/tree/ssd 編譯,然后到我們的caffe_root目錄下,找到data 下,然后看到 ILSVRC2016 VOC0712 cifar10 coco ilsvrc12 moist 這幾個文件夾,然后進入VOC0712 目錄下,可以看到 create_data.sh create_list.sh labelmap_voc.prototxt test.txt trainval.txt , 然后執行 create_data.sh 腳本。

附件

–這個xml文件是怎么生成的。這里推薦用python腳本

#coding=utf-8 import os from lxml import etree import mathanno_file = "imageInfo.txt" save_root = "/data1/user/bingolwang/data/VOCdevkit/VOC2007/Annotations/"f = open(anno_file,'r')for line in f:data = line.strip().split(" ")fname = data[0]img_width = int(float(data[1]))img_height = int(float(data[2]))save_file = save_root + fname[:-3] + "xml"fout = open(save_file, 'w')# creat XMLroot = etree.Element("annotation")# folder infofolder = etree.SubElement(root, "folder")folder.text = "GeneraOcr_WeiYun_Det_imgs"# file namefilename = etree.SubElement(root, "filename")filename.text = str(fname)# sourcesource = etree.SubElement(root, "source")database = etree.SubElement(source, "database")database.text = "GeneraOcr_WeiYun_Det"# image sizesize = etree.SubElement(root, "size")width = etree.SubElement(size, "width")width.text = str(img_width)height = etree.SubElement(size, "height")height.text = str(img_height)depth = etree.SubElement(size, "depth")depth.text = "3"# objectobject_count = 2while object_count < data.__len__():object = etree.SubElement(root, "object")name = etree.SubElement(object, "name")name.text = "text"difficult = etree.SubElement(object, "difficult")difficult.text = "0"bndbox = etree.SubElement(object, "bndbox")xminv = max(1,int(float(data[object_count + 1])) + 1)yminv = max(1,int(float(data[object_count + 2])) +1)xmaxv = min(int(float(data[object_count + 3])) ,img_width-2)ymaxv = min(int(float(data[object_count + 4])) ,img_height-2)xmin = etree.SubElement(bndbox, "xmin")xmin.text = str(xminv)ymin = etree.SubElement(bndbox, "ymin")ymin.text = str(yminv)xmax = etree.SubElement(bndbox, "xmax")xmax.text = str(xmaxv)ymax = etree.SubElement(bndbox, "ymax")ymax.text = str(ymaxv)object_count += 5ss = etree.tostring(root, encoding='utf8',pretty_print=True)fout.write(ss.decode('utf-8'))fout.close()# source end#s = etree.tostring(root, encoding='utf8',pretty_print=True)#print(str(s))f.close()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80

訓練自己的數據集時候報錯:

Check failed: background_label_id != label (0 vs. 0) “Found background label in the dataset.”

檢查失敗: background_label_id != label但是現在二者相等(0 vs 0)主要原因:在dataset的label中,發現了背景類也就是某些圖片為純背景,而且 標注為 0
  • 1
  • 2
  • 3
  • 4

編譯器出錯:

json_parser_read.hpp:257:264: error: ‘type name’ declared as function returning an array escape // 解決步驟: // 1- vi /usr/include/boost/property_tree/detail/json_parser_read.hpp // 2- 注釋掉 json_parser_read.hpp:257:264 之間的代碼 // 3- 保存。然后重新編譯即可。 // 出現這種情況的原因往往是由于: 我們的gcc 與cuda版本不匹配, 可以選擇升級gcc 或者降級 cuda,但是很麻煩。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

運行時出錯:

Check failed: error == cudaSuccess (8 vs. 0) invalid device function // 可能運行時候的cuda lib 與 編譯時候的 nvcc 版本對不上 // 或者 直接copy了一個已經在其他平臺上已經編譯好的cuda 但是本平臺與其他平臺的 gcc版本不一致。
  • 1
  • 2
  • 3

訓練時loss為nan

兩種可能:
1 在生成lmdb的時候,沒有選擇設置尺寸。就是resize選項。
2 在已有的模型上finetune,沒有設置好學習率。

版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/dongfang1984/article/details/74640219

總結

以上是生活随笔為你收集整理的用SSD训练自己的数据集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。