Giter VIP home page Giter VIP logo

ssd_keras's Introduction

SSD_train 以交通标志识别为例

关键词: 交通标志识别 神经网路 目标检测 SSD Keras

我们的目的是训练一个神经网络模型,让他能够对交通标志进行识别.这里,我们采用的是 keras 版的 SSD 模型.

为了模型更好的训练,我们简化了训练样本,对下列三种标志进行识别.训练样本总计138张,每类约46张.

  • 局部图示例

  • 完整大图示例

Step 1. 数据准备

数据标记

每张图标记,分别得到一个如下的 XML 数据结构:

<annotation>
	<folder>train</folder>
	<filename>IMG_20171210_131006.jpg</filename>
	<path>/home/kuhung/Desktop/SSD_train/data/train/IMG_20171210_131006.jpg</path>
	<source>
		<database>Unknown</database>
	</source>
	<size>
		<width>1216</width>
		<height>1216</height>
		<depth>3</depth>
	</size>
	<segmented>0</segmented>
	<object>
		<name>x</name>
		<pose>Unspecified</pose>
		<truncated>0</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>623</xmin>
			<ymin>475</ymin>
			<xmax>682</xmax>
			<ymax>532</ymax>
		</bndbox>
	</object>
</annotation>

关键信息是 文件名,种类名以及4个坐标点,具体的文件路径不重要,后面会单独定义.

格式生成

# 目标格式
文件名,目标的4个坐标点,目标类型的哑变量编码
  • 使用 get_data_from_XML.py脚本,将 labelImg 得到的 XML 转成目标格式.

  • 注意以下几点:

  1. 修改类别数和类别名称
classes = 3
classes_name = ['x','p','t']
  1. 运行脚本生成train.pkl
Python get_data_from_XML.py path_to_your_label

# 在我的本地是
Python get_data_from_XML.py /home/kuhung/Desktop/SSD_train/data/label_train/

Step 2. 开始训练

依赖

cv2==3.3.0
keras==2.2.0
matplotlib==2.1.0
tensorflow==1.3.0
numpy==1.13.3

预训练权重

cp weights_SSD300.hdf5 into SSD_keras

核心脚本

  1. 修改类别数和类别名称
# some constants
NUM_CLASSES = 3+1  # 1 means mask
input_shape = (300, 300, 3)
  1. 修改图片存储位置
path_prefix = '../data/train/'   #path to your data 
  1. 训练模型 在完成上述修改后,通过逐步运行 SSD_training.ipynb, 自定义的SSD模型就开始训练了.

效果

5次迭代示意图

Epoch 1/5
108/110 [============================>.] - ETA: 2s - loss: 3.9356Epoch 00000: saving model to ./checkpoints/weights.00-3.50.hdf5
110/110 [==============================] - 127s - loss: 3.9005 - val_loss: 3.4982
...
Epoch 5/5
108/110 [============================>.] - ETA: 1s - loss: 1.8918Epoch 00004: saving model to ./checkpoints/weights.04-2.13.hdf5
110/110 [==============================] - 116s - loss: 1.8814 - val_loss: 2.1328

测试集的效果

0.96的置信度,判断为第三类(红绿灯类).

小结

通过这个例子,我们掌握了如何用 keras 版的 SSD, 训练自己的数据集. 在小数据集上也取得了不错的结果.整个流程需要注意的有两个点:一是检查各依赖的版本,是否符合要求;二是自定义任务,要改的地方比较多比较杂,需要耐心和细心.

你有遇到什么问题吗?欢迎在 issue 提出.

ssd_keras's People

Contributors

chutongz avatar kuhung avatar stevessschen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.