1. 程式人生 > >【CV】如何使用Tensorflow提供的Object Detection API--3--手工標註資料

【CV】如何使用Tensorflow提供的Object Detection API--3--手工標註資料

前面兩篇看完,我們已經知道如何選用預訓練模型以及將現存的其他資料集變成TFRecord格式的資料了。

但是如果需要用你自己的資料集,該怎麼辦呢?

本篇主要講如何建立自己的資料集,並用object_detection提供的模型來進行訓練,識別。

首先需要的是標記資料。

LabelImg工具

這個工具能夠方便我們標註圖片。

話不多說,先安裝:

git clone https://github.com/tzutalin/labelImg.git

具體安裝這裡給出的是在Linux上的:

sudo apt-get install pyqt5-dev-tools
sudo
pip3 install lxml make qt5py3

安裝完畢後,就可以到這個檔案下,開啟LabelImg:

python labelImg.py

彈出一個圖形介面,用於標註。在Mac上我很久之前裝的,安裝步驟未記錄,簡單查詢一下即可。

標註完圖片儲存後,會儲存為一個.xml檔案,如果選擇了VOC格式的話。

<annotation>
	<folder>demo</folder>
	<filename>demo4.png</filename>
	<path>xxx/labelImg/demo/demo4.png</
path
>
<source> <database>Unknown</database> </source> <size> <width>1919</width> <height>1079</height> <depth>3</depth> </size> <segmented>0</segmented> <object> <name>flower</name> <pose
>
Unspecified</pose> <truncated>0</truncated> <difficult>0</difficult> <bndbox> <xmin>452</xmin> <ymin>332</ymin> <xmax>983</xmax> <ymax>864</ymax> </bndbox> </object> </annotation>

再認真標註一個:

<annotation>
	<folder>frames</folder>
	<filename>0013.png</filename>
	<path>xxx/labelImg/frames/0013.png</path>
	<source>
		<database>Unknown</database>
	</source>
	<size>
		<width>960</width>
		<height>544</height>
		<depth>3</depth>
	</size>
	<segmented>0</segmented>
	<object>
		<name>apple</name>
		<pose>Unspecified</pose>
		<truncated>0</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>164</xmin>
			<ymin>381</ymin>
			<xmax>293</xmax>
			<ymax>500</ymax>
		</bndbox>
	</object>
	<object>
		<name>lamp</name>
		<pose>Unspecified</pose>
		<truncated>0</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>756</xmin>
			<ymin>410</ymin>
			<xmax>879</xmax>
			<ymax>535</ymax>
		</bndbox>
	</object>
	<object>
		<name>orange</name>
		<pose>Unspecified</pose>
		<truncated>1</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>148</xmin>
			<ymin>1</ymin>
			<xmax>522</xmax>
			<ymax>413</ymax>
		</bndbox>
	</object>
	<object>
		<name>remote control</name>
		<pose>Unspecified</pose>
		<truncated>0</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>392</xmin>
			<ymin>447</ymin>
			<xmax>574</xmax>
			<ymax>539</ymax>
		</bndbox>
	</object>
</annotation>

在這裡插入圖片描述

儲存為YOLO格式時,程式就崩了,但是可以看到儲存出來是兩個.txt檔案。

VOC轉TFRecord格式的指令碼官方有提供:create_pascal_tf_record.py

END.

參考:

https://medium.com/@WuStangDan/step-by-step-tensorflow-object-detection-api-tutorial-part-3-creating-your-own-dataset-6369a4d30dfd