Ssd:single Shot multibox Detector Training Kitti Data Set (2)

Source: Internet
Author: User
Preface

Bloggers have spent a lot of time explaining how to Kitti raw data into an SSD-trained format, and then use the relevant Caffe code to implement SSD training. Download Vgg pre-training model

The SSD is used for its own inspection task, it is required fine-tuning a pretrained network, the friends who have read the paper may know that the SSD framework in the paper is made up of the Vgg network as the base (base). In addition to this, the authors also provide two other types of network: ZF-SSD and RESNET-SSD, which can be viewed in the CAFFE/EXAMPLES/SSD folder with the appropriate Python training code.

First training, or use Vgg network bar, download the pre-training model, put it under the/home/mx/caffe/models/vggnet folder. Modify the training code

Here first the computer hardware configuration, which determines some of the training parameters set. The host CPU used by the blogger is the Intel i7 6700,GPU Titan X, which runs memory 16GB and is equipped with a Ubuntu16.04 system.

General Caffe Training is the use of Train.prototxt and solver.prototxt files, some students may want to ask, why the SSD project can not find these files. The reason is that the SSD model is very large, Train.prototxt has more than 1000 lines, directly modify the parameters of the workload is too large, and train.prototxt once changed, Test.prototxt and Solver.prototxt also have to follow the changes. As a result, the authors use a very efficient way to generate these files automatically using Python scripts. The first training, Bo Master chose ssd_pascal.py Script Training ssd_300x300, then will ssd_pascal.py copy, renamed to Ssd_pascal_kitti.py, and then modify this Ython file.

ssd_pascal.py script also has more than 500 lines, bloggers can not be all posted out, here to paste the part to be modified as a reference.

PS. According to Bo friends feedback, or provide modified training script ssd_pascal_kitti.py, for reference. custom paths and common parameters

Train_data = "Examples/voc0712/voc0712_trainval_lmdb" # Training data path, modified before train_data = "Examples/kitti/kitti_trainval_lmdb" #
Modified------Test_data = "Examples/voc0712/voc0712_test_lmdb" # test data path Test_data = "Examples/kitti/kitti_test_lmdb"------ Model_name = "vgg_voc0712_{}". Format (job_name) # model name model_name = "kitti_{}". Format (job_name)------Save_dir = "models/ vggnet/voc0712/{} ". Format (job_name) # model save Path Save_dir =" models/vggnet/kitti/{} ". Format (job_name)------Snapshot_dir = "models/vggnet/voc0712/{}". Format (job_name) # Snapshot Snapshot save path Snapshot_dir = "models/vggnet/kitti/{}". Format (job_ Name)------Job_dir = "jobs/vggnet/voc0712/{}". Format (job_name) # job save path Job_dir = "jobs/vggnet/kitti/{}". Format (job_ Name)------Output_result_dir = "{}/data/vocdevkit/results/voc2007/{}/main". Format (os.environ[' HOME '], job_name) # Test result txt save path Output_result_dir = "{}/data/kittidevkit/results/kitti/{}/main". Format (os.environ[' HOME '], job_name)-- -----name_size_file = "Data/voc0712/test_name_size.txt"# test_name_size.txt file path name_size_file = "Data/kitti/test_name_size.txt"-------label_map_file = "data/VOC0712/ Labelmap_voc.prototxt "# label file path label_map_file =" Data/kitti/labelmap_kitti.prototxt "------num_classes = 21 # Total number of categories Nu m_classes = 4------GPUs = "0,1,2,3" # using which GPU GPUs = "0" # only 1 GPU------batch_size = 32 # Number of pictures processed at once batch_size = custom # TITAN x is just 32, please adjust the memory size------num_test_image = 4952 # number of test pictures num_test_image = Custom # This number should be consistent with test_name_size.txt---- --Run_soon = True # automatically starts training after generating a file Run_soon = False # manual Block
Custom Training Parameters

SSD training parameters are more, the specific meaning before also know. But the first test, not very clear how to adjust, so decided to basically do not change the other parameters (such training once after the results of re-adjustment, repeated training), only the initial learning rate to make adjustments. It turns out that for Kitti datasets, the initial learning rate of 0.001 is too large to cause network convergence and should be adjusted to 0.0001, as follows:

# If True, use batch norm for all newly added layers.
# currently only the non batch norm version has been tested.
Use_batchnorm = False
lr_mult = 1
# Use different initial learning rate.
If use_batchnorm:
    base_lr = 0.0004
else:
    # A Learning rate for batch_size = 1, Num_gpus = 1.
    BASE_LR = 0.00004 ...
if Normalization_mode = = P.loss.none:
  base_lr/= batch_size_per_device elif normalization_mode
= = P. Loss.valid:
  base_lr *=./loc_weight
elif normalization_mode = p.loss.full:
  # Roughly there is PR IOR bboxes per image.
  # TODO (weiliu89): Estimate The exact # of Priors.
  BASE_LR *=.
# from the above code can be seen, the training script does not use Batchnorm, before modification, the initial learning rate = BASE_LR * 25/loc_weight=0.001
# Change the BASE_LR variable to the original One-tenth, that is 0.00004-> 0.000004, you can adjust the learning rate to 0.0001.

PS. The learning rate of 0.0001 is really small, can be appropriately adjusted a little bit, my own experiment shows that 0.0005~0.0007 are optional parameters, higher than 0.0008 will be divergent. Training Model

When you finish modifying the script parameters, run the script program.

$ cd caffe/
$ python examples/ssd/ssd_pascal_kitti.py

Then the model is trained, you may encounter the "out of Memory" problem, which is batch_size set too high, resulting in insufficient memory, this time lower batch_size and then re-run can be resolved.

This training iteration 120,000 times, Bo Master estimated training time about more than 50 hours, because the host has other tasks, but also only intermittent training (directly resulting in incomplete training log, can not draw accuracy and loss curve). Feel direct to apply the training parameters of others, loss convergence is relatively slow.

Finally the training completed, screenshots souvenir.

Test Model

From the end of the training screenshot, the training results are not ideal, after 120,000 iterations, loss is still around 2, convergence is poor, the test accuracy rate is only 57.3%, and the results of VOC training in the paper is very far. Although the model is a bit of slag, but still take out to use, see in the end is a degree.

Here we use ssd_detect.py to detect a single picture, and some of the results are as follows:



By the figure, the car and pedestrian training is more adequate, the test results are not satisfactory; bicycles do not know that the sample is too little or poorly trained, it is difficult to detect the basic. Summary and thinking

This training, the process is run through, but the results are not very ideal, summary of the possible reasons and improve the direction: training parameters, direct copy certainly not, after the need for selective adjustment; VOC image size is 500x375, and Kitti picture size is 1242x375, not only the resolution up, The aspect ratio also reaches 3:1, still using ssd_300x300 may not be appropriate, then will try to train ssd_512x512 or other size of the model, the accuracy should be able to rise, but the running time will be longer; change the bottom to see how ZF-SSD and RESNET-SSD behave, On the one hand, the accuracy, on the other hand, is the running time; for higher accuracy, the perception of training pictures is still not enough (especially on bicycles), so you can try to supplement similar datasets.

Update : For the problem of low precision, Bo Master read some papers, found that the data set imbalance should be the main reason, to be exact, I made Kitti car accounted for is too large, and other categories too little, map is pulled down, if the balance data set, should be able to improve.

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.