Target Detection SSD: Training your own data set

Source: Internet
Author: User
Tags mkdir git clone

Recently has been engaged in the object detection play, before using the FASTER-RCNN, the accuracy of 73.2%, the effect is good, but the recognition speed is a bit short, I use the GPU is gtx980ti, recognition speed is about 15fps. Recently discovered SSD ( Single shot Multibox detector) This paper has a good effect and speed, I have experimented with it, the speed is indeed much faster than FASTER-RCNN. The following is a two-part introduction. The first section describes the installation of SSDs, and the second section describes how to train your own data sets based on SSDs. First Part SSD installation

System: Ubuntu 14.04
Language: Python
SSD Project home: HTTPS://GITHUB.COM/WEILIU89/CAFFE/TREE/SSD
First, we clone the project code and compile it:

git clone https://github.com/weiliu89/caffe.git
cd caffe
git Checkout SSD

Next, we started compiling Caffe, compiling caffe very easy, here we filtered, if interested, can refer to my previous blog: http://blog.csdn.net/zhang_shuai12/article/details/ 52289825, this article is about Caffe + CPU + ubuntu14.04 installation, GPU version of the installation needs to modify the Makefile.config file, after the modification is completed:

Make make 
py

Here we have the SSD installed, and then we'll talk about how to train our own datasets. the second part trains your own data sets

First of all, we might as well run a demo of the project, need to download datasets, pre-trained data sets, and so on.
Download the pre-trained model, Link: https://gist.github.com/weiliu89/2ed6e13bfd5b57cf81d6, the download is complete after the warranty exists:

caffe/models/vggnet/

Download the VOC2007 and VOC2012 datasets, placed in the/data directory:

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.tar

tar-xvf voctrainval_11-may-2012.tar
tar-xvf VOCtrainval_06- Nov-2007.tar
TAR-XVF Voctest_06-nov-2007.tar

To create data in Lmdb format:

CD Caffe
./data/voc0712/create_list.sh
# It'll create Lmdb files for Trainval and test with encoded original IMA GE:
#   -$HOME/data/vocdevkit/voc0712/lmdb/voc0712_trainval_lmdb
#   -$HOME/data/vocdevkit/voc0712 /lmdb/voc0712_test_lmdb
./data/voc0712/create_data.sh

Training and testing:

Python examples/ssd/ssd_pascal.py

In this paper, the author has pre-trained the model, download link: http://www.cs.unc.edu/%7Ewliu/projects/SSD/models_VGGNet_VOC0712_SSD_ 300x300.tar.gz, we do not have to go to training, after the download is completed into the specified folder.
Testing, we use the SSD_DETECT.IPYNB in the/example/ssd/directory, run this file, need to install Ipython and Ipython-notebook, or directly copy the code inside, write to a new Python file, Like naming ssd_detector.py.

OK, modify a series of files below to train your own data set
Two scenarios, first: Keep the original file directory structure and file name unchanged, only replace the data inside. Second: Re-create a similar directory structure, changed to their own named folder, the second method, there is a certain risk, you need to modify the program involved in the data path code. In the previous Faster-rcnnan blog post, we used the first option. This time we use the second option.
Create a folder of your own in the/data directory:

Cd/data
mkdir myDataSet

Copy the three files of create_list.sh, create_data.sh and Labelmap_voc.prototxt under the/data/voc0712 directory to/mydataset:

CP data/create*./mydataset
cp data/label*./mydataset

Labelmap_voc.prototxt, this file defines the label.

Create the myDataSet in the/data/vocdevkit directory and put it in your own dataset:

CD Data/vocdevkit
mkdir mydataset
cd mydataset
mkdir Annotations
mkdir
imagesets mkdir Jpegimages
cd imagesets
mkdir Layout
mkdir Main
mkdir Segmentation

where annotations in the storage of some column XML file, including object bbox,name, etc.;
Imagesets in three sub-directories are stored train.txt, val.txt, Trainval.txt, test.txt These files, the file content is the picture file name (without suffix);
Jpegimages store all the pictures;

Create the myDataSet folder under/examples:

mkdir myDataSet

The generated lmdb file is stored in the folder.

Once the above folder is created, start building the Lmdb file and modify the relevant path before you create it:

./data/mydataset/create_list.sh
./data/mydataset/create_data.sh

At this time, under the examples/mydataset/folder can see two subfolders, Mydataset_trainval_lmdb, Mydataset_test_lmdb, which contains DATA.DMB and LOCK.DMB;

So far, our data sets are ready. The next step is to start training. Before running the training program for/examples/ssd/ssd_pascal.py, we need to modify the relevant path code:

CD/EXAMPLES/SSD
vim sd_pascal.py, modified as follows:
57 lines: Train_data path,
59 lines: Test_data path,
197-203 rows: Save_dir, Snapshot_dir, Job_dir, output_result_dir path;
216-220 rows: name_size_file, label_map_file path;
223 rows: num_classes Modified to 1 + categories
315 rows: num_test_image: Number of test set pictures

Also, if you have only one GPU, you need to modify 285 lines:
gpus= "0,1,2,3" ===> changed to "0"
Otherwise, the training will be wrong.
Run when you are finished modifying

After training, modify the model path in the ssd_detector.py, find a picture to identify, see how the effect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.