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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

SSD配置+训练VOC0712+训练自己的数据集

發(fā)布時(shí)間:2024/9/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SSD配置+训练VOC0712+训练自己的数据集 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

GitHub?https://github.com/weiliu89/caffe/tree/ssd

http://blog.csdn.net/u010733679/article/details/52125597

一、安裝配置

sudo apt-get install -y liblapack-dev liblapack3 libopenblas-base libopenblas-dev------------------------------------------------------------------------------- 1. git clone https://github.com/weiliu89/caffe.git cd caffe git checkout ssd2.Makefile.config caffe --> SSD/caffe3. make -j8 make py make test -j8 make runtest -j84.寫入環(huán)境變量 sudo gedit /etc/profileexport PYTHONPATH=/home/gjw/SSD/caffe/python 注銷
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

===================================================

二、測(cè)試

[注]下載訓(xùn)練好的模型進(jìn)行下面的測(cè)試 (1)訓(xùn)練好的模型名稱:models_VGGNet_VOC0712_SSD_300x300.tar.gz (2)鏈接 https://drive.google.com/file/d/0BzKzrI_SkD1_WVVTSmQxU0dVRzA/view (3)解壓,/models/VGGNet--->~/caffe/model
  • 1
  • 2
  • 3
  • 4
  • 5

測(cè)試一:視頻、攝像頭

[測(cè)試1] 演示網(wǎng)絡(luò)攝像頭識(shí)別效果,終端輸入:python examples/ssd/ssd_pascal_webcam.py [測(cè)試2] python examples/ssd/ssd_pascal_video.py
  • 1
  • 2
  • 3
  • 4
  • 5

測(cè)試二: 訓(xùn)練VOC數(shù)據(jù)集

首先我們不妨先跑一下項(xiàng)目的demo, 需要下載數(shù)據(jù)集,提前訓(xùn)練好的數(shù)據(jù)集等。 下載預(yù)訓(xùn)練的模型,鏈接:https://gist.github.com/weiliu89/2ed6e13bfd5b57cf81d6, 下載完成后保存在:caffe/models/VGGNet/1. 下載VOC2007和VOC2012數(shù)據(jù)集, 放在/data目錄下:cd data wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tartar -xvf VOCtrainval_11-May-2012.tar tar -xvf VOCtrainval_06-Nov-2007.tar tar -xvf VOCtest_06-Nov-2007.tar2. 創(chuàng)建lmdb格式的數(shù)據(jù):cd caffe ./data/VOC0712/create_list.sh ./data/VOC0712/create_data.sh3. (1)gpu-->"0,1,2,3" (2)batch_size = 8 #32accum_batch_size = 8 #32 (3)訓(xùn)練VOC數(shù)據(jù)集python examples/ssd/ssd_pascal.py
  • 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

  • 1
  • 2

************************************************************

************************************************************

三、訓(xùn)練自己的數(shù)據(jù)集

1.制作VOC2007數(shù)據(jù)集:labelImg工具

/data/VOCdevkit/driver /data/VOCdevkit/driver/Annotations /data/VOCdevkit/driver/ImageSets /data/VOCdevkit/driver/JPEGImages
  • 1
  • 2
  • 3
  • 4

2.VOC數(shù)據(jù)轉(zhuǎn)換成LMDB數(shù)據(jù)

  SSD提供了VOC數(shù)據(jù)到LMDB數(shù)據(jù)的轉(zhuǎn)換腳本 data/VOC0712/create_list.sh 和 ./data/VOC0712/create_data.sh,這兩個(gè)腳本是完全針對(duì)VOC0712目錄下的數(shù)據(jù)進(jìn)行的轉(zhuǎn)換。實(shí)現(xiàn)中為了不破壞VOC0712目錄下的數(shù)據(jù)內(nèi)容,針對(duì)我們自己的數(shù)據(jù)集,修改了上面這兩個(gè)腳本, 將腳本中涉及到VOC0712的信息替換成我們自己的目錄信息。 在處理我們的數(shù)據(jù)集時(shí),將VOC0712替換成driver。 ------------------------------------------------------------------------------------- (1)mkdir /home/gjw/SSD/caffe/data/driver (2)將data/VOC0712下的create_list.sh,create_data.sh,labelmap_voc.prototxt 這三個(gè)文件copy到driver目錄下 (3) 修改后的這兩個(gè)文件分別為: [create_list.sh]for name in VOC2007 VOC2012 --> for name in driver[create_data.sh]dataset_name="VOC0712" --> dataset_name="driver"[labelmap_voc.prototxt]將該文件中的類別修改成和自己的數(shù)據(jù)集相匹配 (4)$ ./data/driver/create_list.sh 在/home/gjw/SSD/caffe/data/driver目錄下test.txt,test_name_size.txt,trainval.txt$ ./data/driver/create_data.sh 在/home/gjw/data/VOCdevkit/driver/lmdb目錄下查看轉(zhuǎn)換完成的LMDB數(shù)據(jù)數(shù)據(jù)
  • 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

3. 使用SSD進(jìn)行自己數(shù)據(jù)集的訓(xùn)練

VGG_ILSVRC_16_layers_fc_reduced.caffemodel:https://gist.github.com/weiliu89/2ed6e13bfd5

b57cf81d6

http://pan.baidu.com/s/1o8hpU7g?72fm

訓(xùn)練時(shí)使用ssd demo中提供的預(yù)訓(xùn)練好的VGGnet model : VGG_ILSVRC_16_layers_fc_reduced.caffemodel 將該模型保存到$CAFFE_ROOT/models/VGGNet下。將$CAFFE_ROOT/examples/ssd/ssd_pascal.py copy一份 ssd_pascal_driver.py文件, 根據(jù)自己的數(shù)據(jù)集修改ssd_pascal_driver.py主要修改點(diǎn):(1)train_data和test_data修改成指向自己的數(shù)據(jù)集LMDBtrain_data = "examples/driver/driver_trainval_lmdb"test_data = "examples/driver/driver_test_lmdb"save_dir = "models/VGGNet/driver/{}".format(job_name)snapshot_dir = "models/VGGNet/driver/{}".format(job_name)job_dir = "jobs/VGGNet/person/{}".format(job_name)output_result_dir = "{}/data/VOCdevkit/driver/VOC2007/{}/Main".format(os.environ ['HOME'], job_name)name_size_file = "data/driver/test_name_size.txt"label_map_file = "data/driver/labelmap_voc.prototxt"2) num_test_image該變量修改成自己數(shù)據(jù)集中測(cè)試數(shù)據(jù)的數(shù)量 (3) num_classes 該變量修改成自己數(shù)據(jù)集中 標(biāo)簽類別數(shù)量數(shù) + 14)batch_size = 1 # 32 accum_batch_size = 1 test_batch_size = 1 base_lr = 0.000004 'max_iter': 120000 'test_interval': 100000----------------------------------------------------------------- examples/ssd/ssd_pascal.pygpu = '0,1,2,3' --> gpu = '0' 訓(xùn)練命令: python examples/ssd/ssd_pascal_driver.pyVGG_VOC0712_SSD_300x300_iter_????.caffemodel存放在目錄$CAFFE_ROOT/SSD/caffe/models/VGGNet/person/SSD_300x300
  • 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
1、 訓(xùn)練sudo gedit ~/SSD/caffe/examples/ssd/ssd_pascal.py (1)gpus=’0,1,2,3’ (2) 如果出現(xiàn)問(wèn)題cudasuccess(2vs0)則說(shuō)明您的顯卡計(jì)算量有限,再次batch_size =32 //32 16 8 4 (3) cd ~/SSD/caffepython examples/ssd/ssd_pascal.py2、 精度測(cè)試 終端輸入:python examples\ssd\score_ssd_pascal.py
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
3、視頻、攝像頭測(cè)試[準(zhǔn)備工作]修改E:\caffe\caffe-ssd-microsoft\models\VGGNet\VOC0712 \SSD_300x300下的配置文件deploy.prototxt中的下面兩個(gè)變量為全路徑:label_map_file: "E:/caffe/caffe-ssd-microsoft/data/VOC0712/labelmap_voc.prototxt"name_size_file: "E:/caffe/caffe-ssd-microsoft/data/VOC0712/test_name_size.txt"(2)用生成的模型測(cè)試本地?cái)z像頭:ssd_pascal_webcam.py 修改ssd_pascal_webcam.py的pretrain_model變量為自己剛訓(xùn)練好的模型:pretrain_model = "E:/caffe/caffe-ssd-microsoft/models/VGGNet/VOC0712/SSD_300x300/VGG_VOC0712_SSD_300x300_iter_4000.caffemodel"python examples\ssd\ssd_pascal_webcam.py
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
4、 單張圖像測(cè)試 (1)jupyter notebook (2)python ssd_detect.py# coding: utf-8# # Detection with SSD # # In this example, we will load a SSD model and use it to detect objects.# ### 1. Setup # # * First, Load necessary libs and set up caffe and caffe_root# In[1]:import cv2 import numpy as np import matplotlib.pyplot as pltplt.rcParams['figure.figsize'] = (10, 10) plt.rcParams['image.interpolation'] = 'nearest' plt.rcParams['image.cmap'] = 'gray'# Make sure that caffe is on the python path: caffe_root = '/home/gjw/SSD/caffe/' # this file is expected to be in {caffe_root}/examples import os os.chdir(caffe_root) import sys sys.path.insert(0, 'python')import caffe caffe.set_device(0) caffe.set_mode_gpu()# * Load LabelMap.# In[2]:from google.protobuf import text_format from caffe.proto import caffe_pb2# load PASCAL VOC labels labelmap_file = '/home/gjw/SSD/caffe/data/car/labelmap_voc.prototxt' file = open(labelmap_file, 'r') labelmap = caffe_pb2.LabelMap() text_format.Merge(str(file.read()), labelmap)def get_labelname(labelmap, labels):num_labels = len(labelmap.item)labelnames = []if type(labels) is not list:labels = [labels]for label in labels:found = Falsefor i in xrange(0, num_labels):if label == labelmap.item[i].label:found = Truelabelnames.append(labelmap.item[i].display_name)breakassert found == Truereturn labelnames# * Load the net in the test phase for inference, and configure input preprocessing.# In[3]:model_def ='/home/gjw/SSD/caffe/models/VGGNet/car/SSD_300x300/deploy.prototxt' ### model_weights = '/home/gjw/SSD/caffe/models/VGGNet/car/SSD_300x300/VGG_VOC0712_SSD_300x300_iter_15000.caffemodel' ####net = caffe.Net(model_def, # defines the structure of the modelmodel_weights, # contains the trained weightscaffe.TEST) # use test mode (e.g., don't perform dropout)# input preprocessing: 'data' is the name of the input blob == net.inputs[0] transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data', (2, 0, 1)) transformer.set_mean('data', np.array([104,117,123])) # mean pixel transformer.set_raw_scale('data', 255) # the reference model operates on images in [0,255] range instead of [0,1] transformer.set_channel_swap('data', (2,1,0)) # the reference model has channels in BGR order instead of RGB# # # ### 2. SSD detection# * Load an image.# In[4]:# set net to batch size of 1 image_resize = 300 net.blobs['data'].reshape(1,3,image_resize,image_resize)image = caffe.io.load_image('/home/gjw/test/000030.jpg') ##新建test #plt.imshow(image)# * Run the net and examine the top_k results# In[5]:transformed_image = transformer.preprocess('data', image) net.blobs['data'].data[...] = transformed_image# Forward pass. detections = net.forward()['detection_out']# Parse the outputs. det_label = detections[0,0,:,1] det_conf = detections[0,0,:,2] det_xmin = detections[0,0,:,3] det_ymin = detections[0,0,:,4] det_xmax = detections[0,0,:,5] det_ymax = detections[0,0,:,6]# Get detections with confidence higher than 0.6. top_indices = [i for i, conf in enumerate(det_conf) if conf >= 0.25]top_conf = det_conf[top_indices] top_label_indices = det_label[top_indices].tolist() top_labels = get_labelname(labelmap, top_label_indices) top_xmin = det_xmin[top_indices] top_ymin = det_ymin[top_indices] top_xmax = det_xmax[top_indices] top_ymax = det_ymax[top_indices]# # * Plot the boxescolors = plt.cm.hsv(np.linspace(0, 1, 21)).tolist()plt.imshow(image) currentAxis = plt.gca()for i in xrange(top_conf.shape[0]):xmin = int(round(top_xmin[i] * image.shape[1]))ymin = int(round(top_ymin[i] * image.shape[0]))xmax = int(round(top_xmax[i] * image.shape[1]))ymax = int(round(top_ymax[i] * image.shape[0]))score = top_conf[i]label = int(top_label_indices[i])label_name = top_labels[i]display_txt = '%s: %.2f'%(label_name, score)coords = (xmin, ymin), xmax-xmin+1, ymax-ymin+1color = colors[label]currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2))currentAxis.text(xmin, ymin, display_txt, bbox={'facecolor':color, 'alpha':0.5})plt.show()
  • 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
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)說(shuō)明。 https://blog.csdn.net/GoJawee/article/details/78136430

總結(jié)

以上是生活随笔為你收集整理的SSD配置+训练VOC0712+训练自己的数据集的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。