一:数据
我们的数据都采用pascal格式,要求图像统一为JPG格式,边界框为XML格式保存,统一存放在images_data文件夹下

其中图像存放图像,箱存放标记框数据,标签存放类别文件,训练数据文件名,测试数据文件名。

处理以后的tfrecord文件,统一存放在object_detection \ ssd_mobile \ data,以后如果有必要,以文件创建时间和创建人结尾。

进入到models-master \ research文件夹下,修改第163行,该行作用是为了指定需要的数据

运行命令行,指定数据存放路径,标签存放路径,使用的数据集和训练还是验证,以后的数据也要按照Pascal的格式进行存放.python 
object_detection \ dataset_tools \ create_pascal_tf_record.py --label_map_path = object_detection \ data \ pascal_label_map.pbtxt --data_dir = F:\ Python \ TensorFlowfiles \ Multiple_networks \ Faster_R_CNN \ data --year = VOC2012 --set = train --output_path = object_detection \ ssd_mobile \ data \ pascal_train.record

python object_detection \ dataset_tools \ create_pascal_tf_record.py --label_map_path = object_detection \ data \ pascal_label_map.pbtxt --data_dir = F:\ Python \ TensorFlowfiles \ Multiple_networks \ Faster_R_CNN \ data --year = VOC2012 --set = val --output_path = object_detection \ ssd_mobile \数据\ pascal_val.record

二,训练
python object_detection \ train.py --logtostderr --train_dir = object_detection \ ssd_mobile \ models \ train --pipeline_config_path = object_detection \ ssd_mobile \ models \ ssd_mobilenet_v1_pascal.config

linux下训练命令,文件路径斜杠要变反斜杠

python object_detection / train.py --logtostderr --train_dir = object_detection / ssd_mobile / models / train --pipeline_config_path = object_detection / ssd_mobile / models / ssd_mobilenet_v1_pascal.config

 

指定模型保存的位置train_dir,配置训练的信息,文件路径在object_detection \ ssd_mobile \ models

根据数据集情况修改下面参数:

训练数据集的类别数:num_classes:20 
每批次使用的数据个数:batch_size:8 
使用预训练的模型进行微调:
fine_tune_checkpoint:“object_detection / ssd_mobile / ssd_mobilenet_v1_coco_2017_06_11 / model.ckpt” 

from_detection_checkpoint:true 

load_all_detection_checkpoint_vars:true

设置训练次数:num_steps:2000 
训练集,验证集,标签存放的路径:train_input_reader; eval_input_reader

验证集样本数据,必须要准确:eval_config

三,转换模型
将生产的模型,转成PB格式保存,

python object_detection / export_inference_graph.py --input_type = image_tensor --pipeline_config_path = object_detection / ssd_mobile / models / ssd_mobilenet_v1_pascal.config --trained_checkpoint_prefix = object_detection / ssd_mobile / models / train / model.ckpt-500000 --output_directory = object_detection / ssd_mobile / models /模型

指定训练时的配置文件:pipeline_config_path 
指定生产的模型:trained_checkpoint_prefix 
指定PB文件输出路径:OUTPUT_DIRECTORY

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐