由于tensorflow models 训练指令过于麻烦,本人将一些 文件放到了 自建的training目录
并记录下训练指令
//cd 到training目录 //生成csv文件 python3 xml_to_csv.py //cd training //生成tfrecord文件 //训练集 ,测试集各执行一次 python3 product_tfrecord.py --csv_input=data/train_labels.csv --output_path=data/train.record python3 product_tfrecord.py --csv_input=data/test_labels.csv --output_path=data/test.record //开始训练 //cd 到training。或者 object_detection 目录 // //注意修改配置文件ssd_mobilenet_v1_coco.config // //开始训练 //运行命令 //注意num_eval_steps 不能过大
python3 model_main.py --pipeline_config_path=/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/ssd_mobilenet_v1_coco.config --model_dir=/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/result --num_train_steps=2000 --num_eval_steps=500 --alsologtostderr python3 model_main.py --pipeline_config_path=/Users/limengkai/PycharmProjects/models-master/research/object_detection/training_2/ssd_mobilenet_v1_coco.config --model_dir=/Users/limengkai/PycharmProjects/models-master/research/object_detection/training_2/result --num_train_steps=2000 --num_eval_steps=500 --alsologtostderr //使用 ssd v2 模型进行训练 python3 model_main.py --pipeline_config_path=/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/ssd_mobilenet_v2_coco.config --model_dir=/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/result --num_train_steps=1000 --num_eval_steps=500 --alsologtostderr //训练会生成model.ckpt-xx文件训练文件会不断更新 xxx数值 //下边根据此类型文件 ,生成最终 pd可应用模型 //生成。pd 模型文件 //cd object_detection 目录 //注意修改training/model.ckpt-1167。的数值, 保证存在 model.ckpt-1167 python export_inference_graph.py –input_type image_tensor –pipeline_config_path training/ssd_mobilenet_v1_coco.config –trained_checkpoint_prefix training/result/model.ckpt-6494 –output_directory xsk_v1_graph; python export_inference_graph.py –input_type image_tensor –pipeline_config_path training/ssd_mobilenet_v2_coco.config –trained_checkpoint_prefix training/result/model.ckpt-647 –output_directory xsk_v2_graph; //最后利用 教程文件py 查看效果
image_size must contain 3 elements[4]
这是因为训练的数据集中不是所有的图片位深都是三通道的。
写一个脚本查看所有的数据集中所有的数据,列举出不是RGB的图片:
from PIL import Image import os path = ‘/home/seven/cy_folder/data/plane/’ #图片目录 for file in os.listdir(path): extension = file.split(’.’)[-1] if extension == ‘jpg’: fileLoc = path+file img = Image.open(fileLoc) if img.mode != ‘RGB’: print(file+’, '+img.mode) //显示框设置,最后一行,可以规定,标记的最小值。6 代表百分之60 vis_util.visualize_boxes_and_labels_on_image_array( image_np, np.squeeze(boxes), np.squeeze(classes).astype(np.int32), np.squeeze(scores), category_index, use_normalized_coordinates=True, line_thickness=8, min_score_thresh=.6) train_input_reader: { tf_record_input_reader { input_path: “/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/data/train.record” } label_map_path: “/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/object-detection.pbtxt” } eval_config: { num_examples: 500
Note: The below line limits the evaluation process to 10 evaluations.
Remove the below line to evaluate indefinitely.
max_evals: 100 } eval_input_reader: { tf_record_input_reader { input_path: “/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/data/test.record” } label_map_path: “/Users/limengkai/PycharmProjects/models-master/research/object_detection/training/object-detection.pbtxt” shuffle: true num_readers: 1 } python export_inference_graph.py --input_type image_tensor --pipeline_config_path training/ssd_mobilenet_v1_coco.config --trained_checkpoint_prefix training/result/model.ckpt-2000 --output_directory kuli;