wider face資料集轉化為VOC資料集(matlab實現)
head.xml
<annotation>
<folder>widerface</folder>
<filename>%06d.jpg</filename>
<source>
<database>My Database</database>
<annotation>VOC2007</annotation>
<image>flickr</image>
<flickrid>NULL</flickrid>
</source>
<owner>
<flickrid>NULL</flickrid>
<name>facevise</name>
</owner>
<size>
<width>%d</width>
<height>%d</height>
<depth>%d</depth>
</size>
<segmented>0</segmented>
object.xml
<object>
<name>%s</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>%d</xmin>
<ymin>%d</ymin>
<xmax>%d</xmax>
<ymax>%d</ymax>
</bndbox>
</object>
tail.xml
</annotation>
function WiderFace2VOC()
%% wider face
% The corresponding annotations are in the following format:
% Here, each face bounding boxe is denoted by:
% <x_left y_top width height>.
%% voc
% 000001.jpg car 44 28 132 121
%前面是圖片名,中間是目標類別,最後是目標的包圍框座標(左上角和右下角座標)。
%%
clc;
clear;
fclose all;
[~, ~, ~] = rmdir('Annotations', 's');
[~, ~, ~] = rmdir('ImageSets', 's');
[~, ~, ~] = rmdir('JPEGImages', 's');
[~, ~, ~] = mkdir('Annotations');
[~, ~, ~] = mkdir('ImageSets/Main');
[~, ~, ~] = mkdir('JPEGImages');
train_root = 'WIDER_train/images';
split_file = 'wider_face_split/wider_face_train';
data = load(split_file);
headXml = fopen('head.xml', 'r');
headXmlFormat = fread(headXml, Inf, '*char');
fclose(headXml);
objectXml = fopen('object.xml', 'r');
objectXmlFormat = fread(objectXml, Inf, '*char');
fclose(objectXml);
tailXml = fopen('tail.xml', 'r');
tailXmlFormat = fread(tailXml, Inf, '*char');
fclose(tailXml);
trainID = fopen('ImageSets/Main/train.txt', 'w');
trainvalID = fopen('ImageSets/Main/trainval.txt', 'w');
valID = fopen('ImageSets/Main/val.txt', 'w');
testID = fopen('ImageSets/Main/test.txt', 'w');
idx = 1;
for i=1:numel(data.event_list)
for j=1:numel(data.file_list{i})
imagename = fullfile(train_root, data.event_list{i}, strcat(data.file_list{i}{j}, '.jpg'));
sz = size(imread(imagename));
AnnotationsXml = fopen(sprintf('Annotations/%06d.xml', idx), 'w');
fprintf(AnnotationsXml, headXmlFormat, idx, sz(2), sz(1),sz(3));
for k = 1:size(data.face_bbx_list{i}{j}, 1)
rc = data.face_bbx_list{i}{j}(k, :);
if (rc(3)<=0||rc(4)<=0)
disp('debug1')
continue;
end
rc = round([rc(1), rc(2), rc(1)+rc(3)-1, rc(2)+rc(4)-1]);
if (rc(3)>=sz(2)||rc(4)>=sz(1))
disp('debug2')
continue;
end
fprintf(AnnotationsXml, objectXmlFormat, 'face', rc(1), rc(2), rc(3), rc(4));
end
fprintf(AnnotationsXml, tailXmlFormat);
fprintf(trainID, '%06d\n', idx);
fprintf(trainvalID, '%06d\n', idx);
fclose(AnnotationsXml);
copyfile(imagename, sprintf('JPEGImages/%06d.jpg', idx));
idx = idx + 1;
end
disp(i);
end
train_root = 'WIDER_val/images';
split_file = 'wider_face_split/wider_face_val';
data = load(split_file);
for i=1:numel(data.event_list)
for j=1:numel(data.file_list{i})
imagename = fullfile(train_root, data.event_list{i}, strcat(data.file_list{i}{j}, '.jpg'));
sz = size(imread(imagename));
AnnotationsXml = fopen(sprintf('Annotations/%06d.xml', idx), 'w');
fprintf(AnnotationsXml, headXmlFormat, idx, sz(2), sz(1),sz(3));
for k = 1:size(data.face_bbx_list{i}{j}, 1)
rc = data.face_bbx_list{i}{j}(k, :);
if (rc(3)<=0||rc(4)<=0)
disp('debug1')
continue;
end
rc = round([rc(1), rc(2), rc(1)+rc(3)-1, rc(2)+rc(4)-1]);
if (rc(3)>=sz(2)||rc(4)>=sz(1))
disp('debug2')
continue;
end
fprintf(AnnotationsXml, objectXmlFormat, 'face', rc(1), rc(2), rc(3), rc(4));
end
fprintf(AnnotationsXml, tailXmlFormat);
if mod(idx, 2)
fprintf(valID, '%06d\n', idx);
fprintf(trainvalID, '%06d\n', idx);
else
fprintf(testID, '%06d\n', idx);
end
fclose(AnnotationsXml);
copyfile(imagename, sprintf('JPEGImages/%06d.jpg', idx));
idx = idx+1;
end
disp(i);
end
fclose(trainID);
fclose(trainvalID);
fclose(valID);
fclose(testID);
fclose all;
因為我用的mxnet中faster rcnn的需要,我過濾掉了w,h小於0的框,也就是得出來x2<x1,y2<y1的框。
其中trainID為全部的訓練集,trainvalID為全部訓練集加一半驗證集,valID為一半驗證集,testID為另一半驗證集
如果要得到全部的驗證集在valID和trainvalID中,程式碼如下:
function WiderFace2VOC()
%% wider face
% The corresponding annotations are in the following format:
% Here, each face bounding boxe is denoted by:
% <x_left y_top width height>.
%% voc
% 000001.jpg car 44 28 132 121
%前面是圖片名,中間是目標類別,最後是目標的包圍框座標(左上角和右下角座標)。
%%
clc;
clear;
fclose all;
[~, ~, ~] = rmdir('Annotations', 's');
[~, ~, ~] = rmdir('ImageSets', 's');
[~, ~, ~] = rmdir('JPEGImages', 's');
[~, ~, ~] = mkdir('Annotations');
[~, ~, ~] = mkdir('ImageSets/Main');
[~, ~, ~] = mkdir('JPEGImages');
train_root = 'WIDER_train/images';
split_file = 'wider_face_split/wider_face_train';
data = load(split_file);
headXml = fopen('head.xml', 'r');
headXmlFormat = fread(headXml, Inf, '*char');
fclose(headXml);
objectXml = fopen('object.xml', 'r');
objectXmlFormat = fread(objectXml, Inf, '*char');
fclose(objectXml);
tailXml = fopen('tail.xml', 'r');
tailXmlFormat = fread(tailXml, Inf, '*char');
fclose(tailXml);
trainID = fopen('ImageSets/Main/train.txt', 'w');
trainvalID = fopen('ImageSets/Main/trainval.txt', 'w');
valID = fopen('ImageSets/Main/val.txt', 'w');
%testID = fopen('ImageSets/Main/test.txt', 'w');
idx = 1;
for i=1:numel(data.event_list)
for j=1:numel(data.file_list{i})
imagename = fullfile(train_root, data.event_list{i}, strcat(data.file_list{i}{j}, '.jpg'));
sz = size(imread(imagename));
AnnotationsXml = fopen(sprintf('Annotations/%06d.xml', idx), 'w');
fprintf(AnnotationsXml, headXmlFormat, idx, sz(2), sz(1),sz(3));
for k = 1:size(data.face_bbx_list{i}{j}, 1)
rc = data.face_bbx_list{i}{j}(k, :);
if (rc(3)<=0||rc(4)<=0)
disp('debug1')
continue;
end
rc = round([rc(1), rc(2), rc(1)+rc(3)-1, rc(2)+rc(4)-1]);
if (rc(3)>=sz(2)||rc(4)>=sz(1))
disp('debug2')
continue;
end
fprintf(AnnotationsXml, objectXmlFormat, 'face', rc(1), rc(2), rc(3), rc(4));
end
fprintf(AnnotationsXml, tailXmlFormat);
fprintf(trainID, '%06d\n', idx);
fprintf(trainvalID, '%06d\n', idx);
fclose(AnnotationsXml);
copyfile(imagename, sprintf('JPEGImages/%06d.jpg', idx));
idx = idx + 1;
end
disp(i);
end
train_root = 'WIDER_val/images';
split_file = 'wider_face_split/wider_face_val';
data = load(split_file);
for i=1:numel(data.event_list)
for j=1:numel(data.file_list{i})
imagename = fullfile(train_root, data.event_list{i}, strcat(data.file_list{i}{j}, '.jpg'));
sz = size(imread(imagename));
AnnotationsXml = fopen(sprintf('Annotations/%06d.xml', idx), 'w');
fprintf(AnnotationsXml, headXmlFormat, idx, sz(2), sz(1),sz(3));
for k = 1:size(data.face_bbx_list{i}{j}, 1)
rc = data.face_bbx_list{i}{j}(k, :);
if (rc(3)<=0||rc(4)<=0)
disp('debug1')
continue;
end
rc = round([rc(1), rc(2), rc(1)+rc(3)-1, rc(2)+rc(4)-1]);
if (rc(3)>=sz(2)||rc(4)>=sz(1))
disp('debug2')
continue;
end
fprintf(AnnotationsXml, objectXmlFormat, 'face', rc(1), rc(2), rc(3), rc(4));
end
fprintf(AnnotationsXml, tailXmlFormat);
%if mod(idx, 2)
fprintf(valID, '%06d\n', idx);
fprintf(trainvalID, '%06d\n', idx);
%else
% fprintf(testID, '%06d\n', idx);
%end
fclose(AnnotationsXml);
copyfile(imagename, sprintf('JPEGImages/%06d.jpg', idx));
idx = idx+1;
end
disp(i);
end
fclose(trainID);
fclose(trainvalID);
fclose(valID);
%fclose(testID);
fclose all;
相關文章
- voc資料集轉換成coco資料集
- win10 下的YOLOv3 訓練 wider_face 資料集檢測人臉Win10YOLOIDE
- [轉]Golang資料集Golang
- 機器學習筆記 - Pascal VOC資料集使用FCN語義分割機器學習筆記
- 人臉識別資料集 - BioID Face Database - FaceDBDatabase
- 目標檢測兩種常用的資料集COCO和VOC
- Kafka 叢集如何實現資料同步?Kafka
- PLC實時資料採集如何實現?
- python 將Mnist資料集轉為jpg,並按比例/標籤拆分為多個子資料集Python
- 人臉識別資料集 - PubFig: Public Figures Face DatabaseDatabase
- UCI資料集整理(附論文常用資料集)
- php資料集PHP
- SST資料集
- oracle資料集Oracle
- 修改資料庫字符集(轉)資料庫
- 資料的採集,清洗,資料機器自動標註及轉化為深度學習格式深度學習
- 物聯網資料採集閘道器在工廠數字化轉型中實現資料上雲
- 吉利集團數字化轉型提速,DataPipeline助力集團化實時資料採集同步平臺建設API
- 人工智慧大資料,公開的海量資料集下載,ImageNet資料集下載,資料探勘機器學習資料集下載人工智慧大資料機器學習
- 最強資料集集合:50個最佳機器學習公共資料集機器學習
- 使用coco資料集建立賦值黏貼篡改資料集賦值
- WCF使用資料集(DataSet)、資料表(DataTable)、集合(Collection)傳遞資料 (轉)
- 資料探勘資料集下載資源
- 通過memberlist庫實現gossip管理叢集以及叢集資料互動Go
- Oracle資料倉儲的實時資料採集XSOracle
- 資料集簡介
- 常見資料集
- 操作大資料集大資料
- 資料庫叢集資料庫
- 資料集訓練
- 玩轉大資料系列之一:資料採集與同步大資料
- 【資料集合】並集、交集、差集、子集
- Redis叢集 - cluster叢集、資料分片Redis
- 用DolphinScheduler輕鬆實現Flume資料採集任務自動化!
- 跟著華為,學數字化轉型(4):資料採集
- 遷移資料時oracle字符集的轉換遷移資料時oracle字符集的轉換Oracle
- PHP 實現簡單的資料採集併入庫PHP
- 如何實現車聯網的靈活資料採集