您的位置:首页 > 其它

DRML(2016-CVPR)重现过程记录---(2)数据预处理

2017-05-03 12:13 211 查看
根据文章中的介绍:输入的图片大小是200*200的对齐后的人脸,作者设计的网络会自动把200*200的随机选择170*170作为网络训练输入。
这里我用Disfa-plus数据集的五万多张图片做预处理,进行测试

Disfa-plus中有9个人的共57668张图片,其中有AU的有32875张,没有AU的有24793张图片



Disfa-plus提供了类似上述的图片,数据集提供方在FaceLandmarks中会提供200*200的人脸数据,直接写代码提出来就可以了,我用matlab写了根据disfa-plus提供的数据提取人脸并保存的代码(作者文中说要人脸对对齐,由于disfa-plus本身就是正脸且提供了200*200的人脸,所以我没有做对齐工作,直接提取的人脸)

landmarks_path='D:\Projects\DRML\database\Disfa\Disfa_plus\FaceLandmarks';
saveface_path='D:\Projects\DRML\dataPre\disfa\face_plus';
%遍历所有landmark文件并获取脸部图片
alldirs=dir(landmarks_path);%当前目录所有子目录
folder={};
%the number of all the files in the current searching folder
L=length(alldirs);
%the number of folders to be searched on this class
k=0;
for i=1:1:L
if alldirs(i).isdir&&(~strcmp(alldirs(i).name,'.'))&&~strcmp(alldirs(i).name,'..')
k=k+1;
folder{k}=alldirs(i).name;%=[landmarks_path,filesep,allfiles(i).name];%将所有一级子目录的目录名保存下来
end
end
L=length(folder);
for i=1:L
allfiles=dir([landmarks_path,filesep,folder{i},filesep,'*.','mat']);%[direc,filesep,'*.',ext]
cnt=length(allfiles);
for j=1:cnt
landmarks=load([landmarks_path,filesep,folder{i},filesep,allfiles(j).name]);
imgnum=length(landmarks.FaceImg_CropResize);
for k=1:imgnum
facefilename=[folder{i},'_',allfiles(j).name(1:(length(allfiles(j).name)-16)),'_', landmarks.FaceImg_CropResize{k}.imgID];
imwrite(landmarks.FaceImg_CropResize{k}.ImgCropped, [saveface_path, filesep, facefilename]);
end
end
end




下面是标签文件处理,同样用matlab处理,代码如下

function getlabel_disfa_plus(dire,ext)
%例如getlabel_disfa_plus('D:\Projects\DRML\database\Disfa\Disfa_plus\Labels','txt');
%得到的label.txt格式为: SN子目录_子目录_图片名.jpg -1 1 ...
%label.txt格式例:SN001_A1_AU1_TrailNo_1_028.jpg 1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 -1
%表示该图片上出现了第1和第5和第10个AU,分别对应AU1,AU6,AU20
%AU顺序:AU1,AU12,AU15,AU17,AU2,AU20,AU25,AU26,AU4,AU5,AU6,AU9,
%
%check if the input and output is valid
if ~isdir(dire)
msgbox('The input isnot a valid directory','Warning','warn');
return
else
if nargin==1
ext='*';
elseif nargin>2||nargin<1
msgbox('1 or 2 inputs are required','Warning','warn');
return
end
if nargout>1
msgbox('Too many output arguments','Warning','warn');
return
end

%containing the searching results
SubDir={};SubSubDir={};
%create a txt file to save all the directory
flabel=fopen('label.txt','w');
%containing all the directories on the same class
folder{1}=dire;
flag=1; %1 when there are folders havenot be searched,0 otherwise
dir_SN = 1;%=1表示SN目录,=2表示更小的子目录
while flag
currfolders=folder;
folder={};

for m=1:1:length(currfolders)
direc=currfolders{m};
files=dir([direc,filesep,'*.',ext]);%当前目录下的ext文件

%the number of *.ext files in the current searching folder
L=length(files);
for i=1:1:L%进来该循环的是同一个图片序列的AU
temp=[direc,filesep,files(i).name];
%在这里统计一个视频序列的具体AU情况
label_file=importdata(temp);
label(m,1:length(label_file(1).data), i)=sign(label_file(1).data);
end

allfiles=dir(direc);%当前目录所有文件及子目录
%the number of all the files in the current searching folder
L=length(allfiles);
%the number of folders to be searched on this class
k=length(folder);
for i=1:1:L
if allfiles(i).isdir&&(~strcmp(allfiles(i).name,'.'))&&~strcmp(allfiles(i).name,'..')
k=k+1;
folder{k}=[direc,filesep,allfiles(i).name];%将所有一级子目录的目录名保存下来
if dir_SN == 1
SubDir{k} = allfiles(i).name;%第一层子目录,SN系列
else
SubSubDir{k} = [SubDir{m},'_',allfiles(i).name];%第二层子目录
end
end
end
end

dir_SN=dir_SN+1;
%if there are no folders that havenot searched yet,flag=0 so the loop
%will be ended 当没有目录可遍历时,则查找结束
if ~length(folder)
flag=0;
end
end
%保存label信息
for m=1:length(label(:,1,1))%label三级索引:视频序列、图片、AU
for n=1:length(label(1,:,1))
fprintf(flabel,'%s',SubSubDir{m});
fprintf(flabel,'_%03i.jpg',n-1);
for k=1:length(label(1,1,:))
if label(m,n,k) ==0
fprintf(flabel,' %d', -1);
else
fprintf(flabel,' %d', 1);
end
end
fprintf(flabel,'\n');
end
end
fclose(flabel);
if nargout==1
;
end
clear D fout folder flag currfolders m files L num temp allfiles k i direc

end

处理好之后的标签如下

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: