Tensorflow + Faster RCNN training their own data sets

Faster RCNN (Tensorflow) configuration can refer to my blog, https://blog.csdn.net/kebi199312/article/details/88368904

This paper is divided into three parts:

  • Production data collection
  • Code changes
  • Training and Testing

First, the environment configuration:

1, environment

  • win10 system, graphics card GeForce GTX 960M;
  • TensorFlow-gpu 1.13.0-rc2,CUDA 10.0,Cudnn 7.4.2;
  • python 3.5.2
  • Faster RCNN download address:

    <p><a href="https://github.com/dBeker/Faster-RCNN-TensorFlow-Python3.5" rel="nofollow" target="_blank">https://github.com/dBeker/Faster-RCNN-TensorFlow-Python3.5</a></p>
    </li>
    

Second, the production data collection

Image data sets from https://github.com/datitran/raccoon_dataset , data sets, there are 200 pictures of raccoons; format of the data set is similar to the format VOC2007, Annotations folder is a ready-made label, JPEGImages file folder is the source image, imageSets \ Main folder is generated txt file

                                                                                 File folder under VOC2007

Batch rename files (format: 00000x.jpg), and picture size is not too large, will rename the source image on JPEGImages folder, use labelImg tool to image annotation, generated xml file, saved in the Annotation folder, Steps:

Open labelImg, in OpenDir, select the folder JPEGimage

(1) W shortcut key creatbox, the test image detected in the target box is checked;

Label (2) input target, and back the config.py , pascal_voc match .py like adjustment;

(2) left Annotations folder to save, save for the xml file (Annotations in place);

(3) continue to the next picture until the end.

Batch Picture Code Name:


  
  
  1. import os
  2. path = "JPEGImages"
  3. = the os.listdir Filelist (path) # the folder and all files (including folders)
  4. count= 0
  5. for file in filelist:
  6. print(file)
  7. for File in filelist: # loop through all files
  8. = Os.path.join olddir (path, File) # original file path
  9. IF os.path.isdir (olddir): # If the folder is skipped
  10. continue
  11. os.path.splitext = filename (File) [ 0 ] # filename
  12. = os.path.splitext filetype (File) [ 1 ] # File Extension
  13. = The os.path.join newdir (path, STR (COUNT) .zfill ( . 6 ) + filetype) # zfill string functions to complement the desired digit 0
  14. os.rename (olddir, Newdir) # rename
  15. count+= 1

Third, the code changes

Modify the label : code is in lib \ Datasets \ pascal_voc.py, pascal_voc.py line 34 the script, do not change _background_, will replace the 34 rows of labels into their own label, here only uses a label: raccoon.

                                                                                  Modify the label

 Modify training parameters: code is in lib \ config \ config.py file, you can change the total number of steps of training (max_iters), weight decay (weight_decay), learning rate (learning_rate), batch size (batch_size) and other parameters.

                                                                                    Training parameter modification 

Fourth, the training and testing

参数修改完后,运行train.py,模型训练完后,模型保存在..\default\voc_2007_trainval\default中,把四个文件拷贝出来放到output\vgg16\voc_2007_trainval\default文件夹中,并进行重命名,如下图所示。

                                                                                               生成的模型

测试代码修改:修改主目录里的demo.py脚本,修改标签的个数(1个背景,1个标签),同时把需要测试的图片放在data\demo文件夹里,图片的名称为6位数字。

                                                                                    修改的参数 

最后测试的结果如下图所示:

 

Faster RCNN(Tensorflow)的配置可以参考我的博客,https://blog.csdn.net/kebi199312/article/details/88368904

Guess you like

Origin blog.csdn.net/kellyroslyn/article/details/92760384