Object Detection API(2)—— 自定义数据组织:
本节的目的在于记录将自己的数据组织成Object Detection API可以训练的数据,即record格式。
(1)标注图像:使用lablme开源工具,自行百度下载,GitHub有各平台安装方法。
下面给出windows平台与Anaconda环境下的安装方式
You need install Anaconda, then run below:
# python2
conda create --name=labelme python=2.7source activate labelme# conda install -c conda-forge pyside2
conda install pyqt
pip install labelme# if you'd like to use the latest version. run below:# pip install git+https://github.com/wkentaro/labelme.git
# python3
conda create --name=labelme python=3.6source activate labelme# conda install -c conda-forge pyside2# conda install pyqt
pip install pyqt5 # pyqt5 can be installed via pip on python3
pip install labelme
(2)使用开源标注工具Lablme来标注图像,生成了.xml格式的标注数据,数据包括了目标名称,坐上角坐标,右下角坐标等。
(3)然后通过Object Detection API生成record数据:
运行data-precess.py程序,代码参考[1],本文对其进行了修改,加入了xml读取函数,可以直接读取xml格式的标注文件,生成record数据。输入文件为”标注.xml”与 “原图像.jpg”输出文件为:Out.record
程序运行过程中遇到一些问题:
E1:
Traceback (most recent call last):
File "G:/git/models-master/research/Data_preprocessing.py", line 143, in
tf.app.run()
File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run
_sys.exit(main(argv))
File "G:/git/models-master/research/Data_preprocessing.py", line 136, in main
tf_example = create_tf_example(img_url,ans_url)
File "G:/git/models-master/research/Data_preprocessing.py", line 119, in create_tf_example
'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
File "G:\git\models-master\research\object_detection\utils\dataset_util.py", line 34, in bytes_list_feature
return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))
TypeError: 'face' has type str, but expected one of: bytes
解决如下:
E2:
Traceback (most recent call last):
File "G:/git/models-master/research/Data_preprocessing.py", line 143, in
tf.app.run()
File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run
_sys.exit(main(argv))
File "G:/git/models-master/research/Data_preprocessing.py", line 125, in main
writer = tf.python_io.TFRecordWriter(FLAGS.output_path)#'./out.record'
File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\lib\io\tf_record.py", line 111, in __init__
compat.as_bytes(path), compat.as_bytes(compression_type), status)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 516, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.UnknownError: Failed to create a NewWriteableFile: G:/git/models-master/research/date_demo/ : \udcbe?\udcf8\udcb7\udcc3\udcce?\udca3
; Input/output error
解决如下:
参考资料:
[1]https://github.com/luyishisi/tensorflow/tree/master/4.Object_Detection
版权声明:本文为博主原创文章,转载请联系作者取得授权。