- 制作数据集:
视频抽帧:https://blog.csdn.net/xinxing__8185/article/details/48440133
标注labelImg,
xml转换成csv文件:https://blog.csdn.net/STILLxjy/article/details/95234150
要先将xml文件随机划分成训练集和测试集:
实现xml文件随机划分的python脚本https://blog.csdn.net/echoKangYL/article/details/79419550
将python脚本转换成tfrecord
代码如下,记录一下
# coding: utf-8
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import os
import io
import pandas as pd
import tensorflow as tf
import numpy as np
from PIL import Image
from object_detection.utils import dataset_util
from collections import namedtuple, OrderedDict
flags = tf.app.flags
flags.DEFINE_string('csv_input', 'E:/data/20190715/csv、tfrecord/20190715-1.csv', 'Path to the CSV input')
flags.DEFINE_string('output_path', 'E:/data/20190715/csv、tfrecord/20190715-1.tfrecord', 'Path to output TFRecord')
flags.DEFINE_string('image_path', 'E:/data/20190715/pic/', 'Path to output TFRecord')
FLAGS = flags.FLAGS
# TO-DO replace this with label map
def class_text_to_int(row_label):
if row_label == 'box':
return 1
# 这个是背景!! 不能打标签为0
else:
return 0
def split(df, group):
data = namedtuple('data', ['filename', 'object'])
gb = df.groupby(group)
return [data(filename, gb.get_group(x)) for filename, x in zip(gb.groups.keys(), gb.groups)]
def create_tf_example(group, path):
with tf.gfile.GFile(os.path.join(path, format(group.filename)+".jpg"), 'rb') as fid:
encoded_jpg = fid.read()
encoded_jpg_io = io.BytesIO(encoded_jpg)
image = Image.open(encoded_jpg_io)
width, height = image.size
#.encode('utf8')
#print(group.filename.astype(np.int16))
# group.filename.astype(np.int8).encode('utf8')
filename = str(group.filename).encode('utf8')
image_format = b'jpg'
xmins = []
xmaxs = []
ymins = []
ymaxs = []
classes_text = []
classes = []
for index, row in group.object.iterrows():
xmins.append(row['xmin'] / width)
xmaxs.append(row['xmax'] / width)
ymins.append(row['ymin'] / height)
ymaxs.append(row['ymax'] / height)
classes_text.append(row['class'].encode('utf8'))
classes.append(class_text_to_int(row['class']))
tf_example = tf.train.Example(features=tf.train.Features(feature={
'image/height': dataset_util.int64_feature(height),
'image/width': dataset_util.int64_feature(width),
'image/filename': dataset_util.bytes_feature(filename),
'image/source_id': dataset_util.bytes_feature(filename),
'image/encoded': dataset_util.bytes_feature(encoded_jpg),
'image/format': dataset_util.bytes_feature(image_format),
'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
'image/object/class/label': dataset_util.int64_list_feature(classes),
}))
return tf_example
#主函数
def main(_):
# outPath = FLAGS.
writer = tf.python_io.TFRecordWriter(FLAGS.output_path)
# writer = tf.python_io.TFRecordWriter(outPath)
# 图像的路径
path = os.path.join(FLAGS.image_path)
#csv 的位置
examples = pd.read_csv(FLAGS.csv_input,parse_dates=True)
grouped = split(examples, 'filename')
for group in grouped:
tf_example = create_tf_example(group, path)
writer.write(tf_example.SerializeToString())
writer.close()
output_path = os.path.join(os.getcwd(), FLAGS.output_path)
print('Successfully created the TFRecords: {}'.format(output_path+' ouptut'))
if __name__ == '__main__':
tf.app.run()
2.决策树学习:
深度学习分类算法系列之 -决策树 https://blog.csdn.net/konglingshneg/article/details/81231119
深度学习–决策树 剪枝 https://blog.csdn.net/zgj008/article/details/86307834
决策树系列(三)——ID3 https://www.cnblogs.com/yonghao/p/5096358.html
决策树系列(四)——C4.5 https://www.cnblogs.com/yonghao/p/5122703.html
决策树系列(五)——CART https://www.cnblogs.com/yonghao/p/5135386.html
3.进行训练
选择object detection的架构进行训练
https://www.cnblogs.com/White-xzx/p/9503203.html
准备好数据集(图片,xml文件,tfrecord文件,label_map.pbtxt文件)
准备pipeline文件,修改其中文件具体路径,调整参数等
具体tensor board操作可以看链接,具体config文件修改也可以看链接
运行的时候应修改object detection文件夹下的model_main.py文件,运行model_main.py文件
该文件可以产生评估曲线以及相应的可视化图片,具体修改对比下图
用的是coco的训练框架,附一个coco性能指标:https://www.jianshu.com/p/d7a06a720a2b