CAFFE-SSD training your own data set

Source: Internet
Author: User
Tags rand shuffle in python

This paper introduces the preparation, transformation and the whole process of using SSD to train the data set in target detection. Contents include: 


1, Data set preparation

1) Image callout

2) make VOC DataSet 

3) Convert VOC data set to LMDB format


2, how to use SSD for training 

3, use SSD to do test environment: Win7, compiled Caffe, Pytho N27, Python PIL (Pillow) module. Note: In Caffe compilation, the engineering Convert_annoset, Convert_imageset, and Ssd_detect are compiled and used in subsequent scripts. 


 1.1, the image of the callout: the image of the label using the Bbox-label-tool tool, the tool is implemented in Python, support multi-label labeling. Download Address: Http://download.csdn.net/download/u010725283/10216939 method of Use: 

(1) in the Bbox-label-tool/images directory to create a directory to save the picture, the directory is named after the number ( BBOX-LABEL-TOOL/IMAGES/1) ,Then copy the picture to be labeled to the 1 directory; 

(2) Execute command in Bbox-label-tool directory Python main.py 

(3) on the tool interface, enter the name of the directory you want to tag in the Image Dir box (for example, 1), then click the Load button and the tool will automatically map the IMAGES/1 directory       Chip loading in;   Please note that if the picture in the directory is already marked, clicking Load will not be reloaded.     

 (4) The tool supports multi-category labeling, before drawing bounding boxs box calibration, you need to select the category before drawing the frame. 

(5) After a picture is marked, click the Next>> button to mark the next picture, the picture label successfully, the corresponding directory in the Bbox-label-tool/labels will generate a label file corresponding to the name of the picture.


1.2, the production of VOC data set Caffe training using data in LMDB format, the SSD framework provides a format for converting VOC data into Lmdb format scripts.       

   

So in practice, we first convert bbox-label-tool labeled data into VOC data format and then convert it into Lmdb format. VOC data format:

(1) The label information in XML format saved in annotations is as follows: 

(2) The main directory under the ImageSet directory is a collection of pictures used to represent the training and test, as follows:

(3) Jpegimages all picture sets in the directory.           

(4) The Bbox-label-tool tool labeled bounding box coordinate file is stored under the label directory, The file under this directory is the label label file that you want to convert.           

(5) Convert label to VOC data format           Bbox-label-tool tool labeled bounding box coordinates file converted to VOC data format form. The specific conversion process consists of two steps:         

1: Save the TXT format under Bbox-label-tool bounding The box information is converted to the VOC data format in XML form;         

2: Generates a DataSet for training and a dataset for testing. This two-step change is realized with Python. createxml.py  complete the TXT-to-XML conversion;  execute the script./createxml.py           


1.3,VOC data converted to Lmdb data     SSD provides conversion scripts for VOC data to Lmdb data data/voc0712/create_list.sh and/data/voc0712/ Create_data.sh, these two scripts are completely converted to the data in the VOC0712 directory. Use Create_data.bat and Get_image_size.bat files for data format conversions under Windows.      the specific steps are as follows: 

(1) Create a VAP directory in the%caffe_root%/data/vocdevkit directory, which holds its own conversion complete VOC DataSet; 

(2)%caffe_rooCreate an VOC directory under the T%/examples directory;    

(3) Create a VAP directory under the%caffe_root%/data directory, and data/voc0712 the create_data.bat  Create_list.sh, labelmap_voc.prototxt These three files copy the%CAFFE_ROOT%/DATA/VAP directory      

(4) To modify the above two. bat and create_list.sh files, the main content of the modification is mainly some path information:      create_list.sh files are modified as follows:

#!/bin/bash root_dir=f:/caffe/caffe-ssd-microsoft/data/vocdevkit sub_dir=imagesets/main bash_dir= "$ (CD" $ (dirname " ${bash_source[0]} ")" && pwd) "Echo $HOME for dataset in Trainval test    do   dst_file= $bash _d ir/$dataset. txt   If [-f $DST _file]   then     rm-f $dst _file   fi   for name in VAP   do     if [[$dataset = = "Test" && $name = = "VOC2012"]]     then  &nbs p;    Continue     fi     echo "Create list for $name $dataset ..."  &nb sp;  dataset_file= $root _dir/$name/$sub _dir/$dataset. txt     img_file= $bash _dir/$dataset "_ Img.txt "    cp $dataset _file $img _file     sed-i" s/^/$name \/jpegimages\//g "$img _file & nbsp;   sed-i "s/$/.bmp/g" $img _file     label_file= $bash _dir/$dataset "_label.txt"      CP $dataset _file $label _file     sed-i "s/^/$name \/annotations\//g" $label _file     sed-i "s/$/.xml/g" $label _file   & nbsp Paste-d ' $img _file $label _file >> $dst _file     rm-f $label _file     rm-f $img _fi Le   done   # Generate image name and size infomation.   if [$dataset = = "Test"]   then     f:/caffe/caffe-ssd-microsoft/build/x64/release/get_image _size $root _dir $dst _file $bash _dir/$dataset "_name_size.txt"   fi   # Shuffle trainval file.   if [$dataset = = "Trainval"]   then     rand_file= $dst _file.random     cat $DST _file | Perl-mlist::util=shuffle-e ' Print Shuffle (<STDIN>), ' > $rand _file     mv $rand _file $dst _file & nbsp Fi done
The Create_data.bat file is modified as follows:

@Echo off Echo Caffe Create_annoset Batch set root_dir= F:\caffe\caffe-ssd-microsoft CD%root_dir% set redo=1 set Test_tr ain_dir= DATA\VAP set Data_root_dir =data\vocdevkit set mapfile= F:\caffe\caffe-ssd-microsoft\data\VAP\labelmap_ Voc.prototxt set anno_type=detection set Db=lmdb set min_dim=0 set max_dim=0 set width=0 set height=0 set "Extra_cmd=--enc Ode-type=jpg--encoded "If%redo%==1 (    set" extra_cmd=%extra_cmd%--redo ") for%%s in (Trainval t EST) do (echo Creating%%s lmdb ... python2%root_dir%\scripts\create_annoset.py ^     --anno-type=% anno_type% ^     --label-map-file=%mapfile% ^     --min-dim=%min_dim% ^     --max-dim=%max_dim% ^     --resize-width=%width% ^      --resize-height=%height% ^     --check-label%extra_cmd% ^     %data_ root_dir% ^     %test_train_dir%\%%s.txt ^     %test_train_dir%\%%s_%db%) Pause

Note: The modification of the above file is the modification of the path, which is relatively simple.       After the modification of the above steps, you can start the production of lmdb data data, and run it separately under the%caffe_root% directory: 

1)./data/indoor/create_list.sh Note: You can select the Cygwin tool to run the. sh file under Windows. This step generates two files, Test.txt and Trainval.txt 

2) after the Create_data.bat command is executed, you can view the Lmdb data data for the conversion done in the%CAFFE_ROOT%/DATA/VAP directory. As follows:

2 Training using CAFFE-SSD Training network requires relevant prototxt and pre-trained Caffemodel 1) copy ssd_pascal.py in%CAFFEROOT%\EXAMPLES\SSD directory to SSD_PASCAL_VAP . py, modify the following points:


Once modified, run the script to get solver.prototxt,test.prototxt,trainval.prototxt and deploy.prototxt four files. Get ready, vgg_voc0712_ssd_30.

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.