Code links: https://github.com/DetectionTeamUCAS/FPN_Tensorflow
This article was produced voc format data sets, research target detection based tensorflow training FPN network. VOC production format of the data set is not carried in detail, with a lot of online tutorials. Anaconda employed herein to build the environment, and detect the target gun, knife two categories described as an example.
1, built environment
- Installation depends
python3.5 (anaconda recommended)
cuda9.0 (if you want to use cuda8, set CUDA9 = False in cfgs.py file.)
opencv-python
tensorflow-plot
tensorflow == 1.10
- Download the pre-training model
Download resnet50_v1 , resnet101_v1 pre-training model, which put $ PATH_ROOT / data / pretrained_weights.
- Compile
cd $PATH_ROOT/libs/box_utils/cython_utils python setup.py build_ext --inplace
2 format, the data set
|—— data/VOCdevkit
| |——train
| |——Annotation
| |——JPEGImages
| |——test
| |——Annotation
| |——JPEGImages
3, cfgs.py modify the configuration
Select a network based on a folder ($ PATH_ROOT / libs / configs /), copy the contents of the corresponding profile and the cover cfgs.py.
The actual data set (in this example 2 is the number of categories, set a custom name for the data "train"), to modify the following lines, to selectively modify the training parameters, such as MOMENTUM, LR, DECAY_STEP, MAX_ITERATION etc.
test_annotate_path = '$PATH_ROOT/data/VOCdevkit/train/Annotations'
DATASET_NAME = 'train' # 'ship', 'spacenet', 'pascal', 'coco'
CLASS_NUM = 2
Note: Recommended to customize the name of a data set, otherwise an error may occur: OutOfRangeError (see above for traceback): PaddingFIFOQueue '1_get_batch / batch / padding_fifo_queue' is closed and has insufficient elements
4, label_dict.py changes
In /lib/label_name_dict/label_dict.py file, the code modified as follows:
class_names = [
'back_ground', 'gun', 'knife']
classes_originID = {
'gun': 1, 'knife': 2}
if cfgs.DATASET_NAME == 'train':
NAME_LABEL_MAP = {
'back_ground': 0,
'gun': 1,
'knife': 2
}
5, read_tfrecord.py changes
$ PATH_ROOT / data / io / read_tfrecord.py line 76, add custom data set name.
if dataset_name not in ['ship', 'spacenet', 'pascal', 'coco','train']:
raise ValueError('dataSet name must be in pascal, coco spacenet and ship')
6, production tfrecord
cd $PATH_ROOT/data/io/
python convert_data_to_tfrecord.py --VOC_dir='/PATH/TO/VOCdevkit/VOCdevkit_train/'
--xml_dir='Annotation'
--image_dir='JPEGImages'
--save_name='train'
--img_format='.jpg'
--dataset='pascal'
E.g:
python convert_data_to_tfrecord.py --VOC_dir='/home/manager/FPN_Tensorflow-master/data/VOCdevkit/train/' --save_name='train' --img_format='.bmp' --dataset='train'
7, training python train.py
8、eval.py
If the image format data set does not belong to '.jpg', 'jpeg', '.png', '.tif', '.tiff', modifying eval.py 119 rows. Example used in this example is bmp format
test_imgname_list = [item for item in os.listdir(eval_dir)
if item.endswith(('.jpg', 'jpeg', '.png', '.tif', '.tiff','.bmp'))]
cd $PATH_ROOT/tools
python eval.py --eval_imgs='/PATH/TO/IMAGES/'
--annotation_dir='/PATH/TO/TEST/ANNOTATION/'
--GPU='0'
E.g
python eval.py --eval_imgs='/home/FPN_Tensorflow-master/data/VOCdevkit/test/JPEGImages/' --annotation_dir='/home/FPN_Tensorflow-master/data/VOCdevkit/test/Annotations/' --GPU='5'
9、Demo
If the image format data set does not belong to '.jpg', 'jpeg', '.png', '.tif', '.tiff', modifying eval.py 84 rows.
test_imgname_list = [os.path.join(test_dir, img_name) for img_name in os.listdir(test_dir)
if img_name.endswith(('.jpg', '.png', '.jpeg', '.tif', '.tiff', '.bmp'))]
cd $PATH_ROOT/tools
python inference.py --data_dir='/PATH/TO/IMAGES/'
--save_dir='/PATH/TO/SAVE/RESULTS/'
--GPU='0'