?? loadimages.m
字號:
% Version : 4.1
% Author : Omid Bonakdar Sakhi
function IMGDB = loadimages
%{
This function will prepare faces and non-faces for the train set
這功能將會準備臉和非臉為那火車組
all data will be gathered in a large cell array . each colume represent
所有的數據將會是在大的細胞中聚集排列。 每 colume 表現
a window for the network , which could be a face or not.
為網絡 ,可能是一個臉的一扇窗戶。
rows are as follows : 排依下列各項 :
Row 1 ----> File Name 排 1----> 文件名字
Row 2 ----> Desired output of the net in responding to the vector
排 2----> 需要了輸出那網在回應矢量方面
Row 3 ----> Prepaired vector for training phase 排 3----> Prepaired 矢量為訓練狀態
you can see for yourself this large database out of the program. 你能自個兒瞧瞧這個大的數據庫從計畫。
type 類型
IMGDB = loadimages
in the command window . 在指令窗戶中。
Also the function save the database to a file 'imgdb.mat' to save time
也功能救援數據庫到一文件 'imgdb.mat' 對救援時間
so this function is a one time function except you want to change something
因此這功能是一一時間功能除你需要到變化某事
in the 'im2vec.m' . In that case you should build the database again.
在 'im 2 vec.m' 中 . 在情況,你應該再建立數據庫。
%}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
face_folder = 'face\'; %location of faces for the train set %臉的位置為火車組
non_face_folder = 'non-face\'; %location of non-faces %非臉的位置
file_ext = '.png';
out_max = 0.9; % desired output of the net for detecting a face % 需要了輸出那網為發現一臉
out_min = -0.9; % desired output of the net for not detecting a face % 需要了輸出那網為不發現一臉
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMGDB = cell (3,[]);
fprintf ('Loading Faces ');
folder_content = dir ([face_folder,'*',file_ext]);
nface = size (folder_content,1);
for k=1:nface
string = [face_folder,folder_content(k,1).name];
image = imread(string);
[m n] = size(image);
if (m~=27 || n~=18)
continue;
end
fprintf ('.');
% as you see , each face in the face folder becomes 10 vectors
% 當你見到 ,% 每個臉當面文件夾變成 10個矢量
IM {1} = im2vec (image); % the original face % 最初的臉
IM {2} = im2vec (fliplr(image)); % the mirror of the face which is a face % 臉的鏡子是一臉
% for better response of the network , 1-pixel shifted face in any
% 為網絡的比較好的回應 , 單一圖素的移轉臉在任何的
% direction is used to train network invariant to 1-pixel.
% 方向對是無變化的火車網絡被用到單一圖素的。
IM {3} = im2vec (circshift(image,1));
IM {4} = im2vec (circshift(image,-1));
IM {5} = im2vec (circshift(image,[0 1]));
IM {6} = im2vec (circshift(image,[0 -1]));
IM {7} = im2vec (circshift(fliplr(image),1));
IM {8} = im2vec (circshift(fliplr(image),-1));
IM {9} = im2vec (circshift(fliplr(image),[0 1]));
IM {10} = im2vec (circshift(fliplr(image),[0 -1]));
for i=1:10
IMGDB {1,end+1}= string;
IMGDB {2,end} = out_max;
IMGDB (3,end) = {IM{i}};
end
end
fprintf ('\nLoading non-faces ');
folder_content = dir ([non_face_folder,'*',file_ext]);
nnface = size (folder_content,1);
for k=1:nnface
string = [non_face_folder,folder_content(k,1).name];
image = imread(string);
[m n] = size(image);
if (m~=27 || n~=18)
continue;
end
fprintf ('.');
% here we need some examples to train the network with non-face vectors
% 在這里我們需要一些例子到火車網絡與非臉矢量
% so now we do not have a face here . we can do what ever we want with
% 因此現在我們做不有一臉在這里。 我們能做什么曾經我們需要與
% the photo. strike it with a hammer ,... % 相片。 罷工它用一支槌 ,.。。
% I have chosen only the fliped version of non-faces. flip left-right
% 我有只有選擇那用指頭彈版本非臉。 突然轉動左邊-右邊
% and up-down % 而且向上的-向下的
IM {1} = im2vec (image);
IM {2} = im2vec (fliplr(image));
IM {3} = im2vec (flipud(image));
IM {4} = im2vec (flipud(fliplr(image)));
for i=1:4
IMGDB {1,end+1}= string;
IMGDB {2,end} = out_min;
IMGDB (3,end) = {IM{i}};
end
end
fprintf('\n');
save imgdb IMGDB
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -