SSD配置+训练VOC0712+训练自己的数据集
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.写入环境变量
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
===================================================
二、测试
[注]下载训练好的模型进行下面的测试
(1)训练好的模型名称: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
测试一:视频、摄像头
[测试1]
演示网络摄像头识别效果,终端输入:python examples/ssd/ssd_pascal_webcam.py
[测试2]
python examples/ssd/ssd_pascal_video.py
- 1
- 2
- 3
- 4
- 5
测试二: 训练VOC数据集
首先我们不妨先跑一下项目的demo, 需要下载数据集,提前训练好的数据集等。
下载预训练的模型,链接:https://gist.github.com/weiliu89/2ed6e13bfd5b57cf81d6,
下载完成后保存在:caffe/models/VGGNet/1.
下载VOC2007和VOC2012数据集, 放在/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.
创建lmdb格式的数据: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)训练VOC数据集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
************************************************************
************************************************************
三、训练自己的数据集
1.制作VOC2007数据集:labelImg工具
/data/VOCdevkit/driver
/data/VOCdevkit/driver/Annotations
/data/VOCdevkit/driver/ImageSets
/data/VOCdevkit/driver/JPEGImages
- 1
- 2
- 3
- 4
2.VOC数据转换成LMDB数据
SSD提供了VOC数据到LMDB数据的转换脚本 data/VOC0712/create_list.sh 和 ./data/VOC0712/create_data.sh,这两个脚本是完全针对VOC0712目录下的数据进行的转换。实现中为了不破坏VOC0712目录下的数据内容,针对我们自己的数据集,修改了上面这两个脚本,
将脚本中涉及到VOC0712的信息替换成我们自己的目录信息。
在处理我们的数据集时,将VOC0712替换成driver。
-------------------------------------------------------------------------------------
(1)mkdir /home/gjw/SSD/caffe/data/driver
(2)将data/VOC0712下的create_list.sh,create_data.sh,labelmap_voc.prototxt
这三个文件copy到driver目录下
(3)
修改后的这两个文件分别为:
[create_list.sh]for name in VOC2007 VOC2012 --> for name in driver[create_data.sh]dataset_name="VOC0712" --> dataset_name="driver"[labelmap_voc.prototxt]将该文件中的类别修改成和自己的数据集相匹配
(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目录下查看转换完成的LMDB数据数据
- 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进行自己数据集的训练
VGG_ILSVRC_16_layers_fc_reduced.caffemodel:https://gist.github.com/weiliu89/2ed6e13bfd5
b57cf81d6
http://pan.baidu.com/s/1o8hpU7g 72fm
训练时使用ssd demo中提供的预训练好的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文件, 根据自己的数据集修改ssd_pascal_driver.py主要修改点:(1)train_data和test_data修改成指向自己的数据集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该变量修改成自己数据集中测试数据的数量
(3) num_classes 该变量修改成自己数据集中 标签类别数量数 + 1
(4)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'
训练命令:
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、 训练sudo gedit ~/SSD/caffe/examples/ssd/ssd_pascal.py
(1)gpus=’0,1,2,3’
(2) 如果出现问题cudasuccess(2vs0)则说明您的显卡计算量有限,再次batch_size =32 //32 16 8 4
(3)
cd ~/SSD/caffepython examples/ssd/ssd_pascal.py2、 精度测试
终端输入:python examples\ssd\score_ssd_pascal.py
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
3、视频、摄像头测试[准备工作]修改E:\caffe\caffe-ssd-microsoft\models\VGGNet\VOC0712
\SSD_300x300下的配置文件deploy.prototxt中的下面两个变量为全路径: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)用生成的模型测试本地摄像头:ssd_pascal_webcam.py
修改ssd_pascal_webcam.py的pretrain_model变量为自己刚训练好的模型: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、 单张图像测试
(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
SSD配置+训练VOC0712+训练自己的数据集相关推荐
- [2] SSD配置+训练VOC0712+训练自己的数据集
GitHub https://github.com/weiliu89/caffe/tree/ssd http://blog.csdn.net/u010733679/article/details/52 ...
- SSD配置和训练以及遇到的坑
SSD配置 1.clone作者github下的caffe文件包 git clone https://github.com/weiliu89/caffe.git cd caffe git checkou ...
- 车牌检测模型训练(含源码和数据集)
车牌检测模型训练(含源码和数据集) 本教程利用NVIDIA TAO进行车牌检测模型的训练: 模型框架:SSD 数据集: CRPD, 连接:https://github.com/yxgong0/CRPD ...
- 目标检测第8步:如何在Windows10系统下,训练YOLOv5 5.0自定义数据集?(本地)
请先看这篇文章: 本博打开方式!!!请详读!!!请详读!!!请详读!!!_Cat-CSDN博客 很多刚入门的粉丝私信我说,他们的电脑配置很好,想在本地训练 ...
- 使用yolov5训练自己的目标检测数据集
使用yolov5训练自己的目标检测数据集 yolov4出来后不久,又出现了yolov5,没有论文.虽然作者没有放上和yolov4的直接测试对比,但在COCO数据集的测试效果还是很可观的.很多人考虑到Y ...
- 使用yolov5训练自动驾驶目标检测数据集BDD100K
文章目录 一.什么是BDD100K 二.数据预处理 三.环境配置 四.修改模型结构 五.迁移学习 六.训练BDD100K 七.评估性能 八.结语 一.什么是BDD100K BDD100K是伯克利发布的 ...
- st-gcn训练自建行为识别数据集
st-gcn训练自建行为识别数据集 一.代码下载与环境配置 二.准备行为数据 三.数据转换 四.添加Layout 五.修改训练参数 六.开始训练 七.模型测试 一.代码下载与环境配置 首先参照下面的命 ...
- MMSegmentation V0.27.0训练与推理自己的数据集(二)
1.官方模型转换MMSegmentation风格 如果你想自己转换关键字使用官方存储库的预训练模型,我们还提供了一个脚本swin2mmseg.py在tools directory ,将模型的关键字从官 ...
- ML之NB:基于NB朴素贝叶斯算法训练20类新闻文本数据集进行多分类预测
ML之NB:基于NB朴素贝叶斯算法训练20类新闻文本数据集进行多分类预测 目录 输出结果 设计思路 核心代码 输出结果 设计思路 核心代码 vec = CountVectorizer() X_trai ...
最新文章
- python 字符串 转 dict
- java jdk 1.8 安装_下载、安装、配置 java jdk1.8
- InputStream与DataInputStream区别
- Linux下读写芯片的I2C寄存器
- 〖Linux〗穿越城墙之后,直接连接国内网站的路由配置
- 数据层优化-jdbc连接池简述、druid简介
- pip/pip3 install 报错 “Could not find a version that satisfies the requriement xxx” 的解决方法
- Linux 内核漏洞暴露栈内存,造成数据泄露
- RSF 分布式服务框架-传输协议层设计
- Grep 用法和正则表达式(一)
- 【Python】基于VB、Python、PythonGUI的BMI计算器小程序
- word绿豆沙颜色设置_Win7系统下将txt和word背景颜色设置为豆沙绿的方法
- mybatis笔记-8、动态sql
- 将计算机设置成交换机主机名,交换机配置基本使用命令解析
- OpenCV 视频处理框架
- win10打开蓝牙,蓝牙开关消失,蓝牙和其他设备设置,蓝牙开关不见了
- 人工神经网络英文简称,人工神经网络 英文
- AlexNet VGGNet ResNet 对比 简介
- iOS 实现直接跳转打开定位
- 自动驾驶外卖上线,美团即将配送一切-1
热门文章
- boost::intrusive::treap_algorithms用法的测试程序
- boost::geometry::concepts::check用法的测试程序
- boost::bad_function_call用法的测试程序
- Boost:在向量中打印值
- DCMTK:可加载的DICOM数据字典
- VTK:相互作用之MouseEventsObserver
- OpenCV EM clustering集群的实例(附完整代码)
- OpenCV使用基本算法检测颜色检查器
- C语言实现最大堆max_heap(附完整源码)
- QT实现在图表顶部绘制一个附加元素(标注)