Coupled Dictionary and Feature Space Learning with Applications to Cross-Domain Image Synthesis and Recognition
和
表示n对无标签的数据,分别来自不同的域,比如真实人脸和素描人脸,每个样本维度分别为
和
。
表示字典学习的能力项,关于数据重构误差。
表示字典
和
或结果系数
的关系。
对于我们不考虑字典间的关系,考虑结果系数的关系。因为一旦得到结果系数之间的关系,就可以通过
得到字典间的关系。
是关系函数,表示
的跨域关系。
:考虑一个域的稀疏系数
等于另一个域
的线性映射
。
为了更好地表示和关联跨域数据,结合公共特征空间学习和原始的联合字典学习,让:
替换
,
是关于
的映射矩阵。
是
在
维的公共特征空间的映射结果。
此时公共特征空间学习转化为对的学习。
即,此处我们使用来作为联合字典学习的关系项。即,结合了公共特征空间学习和原始的联合字典学习。
注意:因为最小化得到的解
不是唯一的(例如,平凡解
),所以我们需要额外的约束来确保
有唯一解。
我们不仅希望公共特征空间能关联跨域数据,同时也希望能使用另一个域的数据映射结果来恢复这个域的图像。
即,假设是公共特征空间中来自数据集
的一个映射,那么我们可以得到
,这使得属于另一个域的输出图像可以通过计算
来重建。
通过上述的描述,我们为跨域图像合成定义:
一旦得到,我们有
。
两边同时乘或
,应用最小化
得到
。
所以说结果特征空间可以看作是来自不同域的数据的公共表示。
我们模型的最终优化问题:
优化
更新![](https://i-blog.csdnimg.cn/blog_migrate/febc2bdfbe523b21d2daf30e9d8e3412.png)
先用联合字典学习来计算 ,此时保持
和
为常量。此时(3)就转变成:
这是一个二次约束的二次规划问题 (QCQP),可以通过Lagrange dual techniques解决。
更新![](https://i-blog.csdnimg.cn/blog_migrate/2b661c0b26a25a748c488e73940a408d.png)
保持映射矩阵和字典
不变。因为我们除了标准的稀疏编码形式,还添加了公共特征空间学习,所以(3)转变为:
进一步简化问题:
这是一个标准的稀疏编码形式。可以通过SPAMS解决。
更新![](https://i-blog.csdnimg.cn/blog_migrate/0fc695fbae080009d9c50e9d7e9f0829.png)
保持不变,我们有:
(6)中,得到
代码
下载:https://download.csdn.net/download/shaodongheng/10768312
% Coupled Dictionary and Feature Space Learning with Application to Cross-Domain Image Synthesis and Recognition.
% De-An Huang and Yu-Chiang Frank Wang
% IEEE International Conference on Computer Vision (ICCV), 2013.
%
% Contact: Yu-Chiang Frank Wang (ycwang@citi.sinica.edu.tw)
%
% Demo Sketch to Photo Recognition
%% Access directories
addpath(genpath('SPAMS')); %加载SPAMS方法的路径
addpath(genpath('Data')); %加载数据集路径
addpath(genpath('YIQRGB'));
%% Load parmeters and dataset
load params %加载参数
load CUFS_CUHK %加载数据集
%% Randomly choose training and testing samples%重新划分训练集和测试集
P = cell(188,1);
S = cell(188,1);
for k = 1:100
P{k} = testing_photo{k};
S{k} = testing_sketch{k};
end
for k = 1:88
P{k+100} = training_photo{k};
S{k+100} = training_sketch{k};
end
R = randperm(188);
for k = 1:100
testing_photo{k} = P{R(k)};
testing_sketch{k} = S{R(k)};
end
for k = 1:88
training_photo{k} = P{R(k+100)};
training_sketch{k} = S{R(k+100)};
end
%% Parameters setting %参数设置
par.mu = par.mu*1;
par.K = 50;
param.K = 50;
par.L = 50;
param.L = 50;
param.lambda = par.lambda1; % not more than 20 non-zeros coefficients
param.lambda2 = par.lambda2;
param.mode = 2; % penalized formulation
param.approx=0;
%% Prework on training samples %将训练数据集放入一个矩阵31000*88
size1 = size(training_photo{1},1);%200
size2 = size(training_photo{1},2);%155图片的大小200*155
XH_t = zeros(size1*size2,88);
XL_t = zeros(size1*size2,88);
for k = 1:88 %88张训练图片
fprintf('%d\n',k);
img_yiq = RGB2YIQ(double(training_photo{k})); %RGB转YIQ
XH_t(:,k) = reshape(img_yiq(:,:,1),[size1*size2 1] );%取亮度信号,并reshape成向量
tmp = double(training_sketch{k}); %素描信息转双精度
if size(tmp,3) > 1
img_yiq = RGB2YIQ(tmp);
tmp = img_yiq(:,:,1);
end
XL_t(:,k) = reshape(tmp,[size1*size2 1]); %素描图reshape成向量
end
XH_t = XH_t - repmat(mean(XH_t), [size(XH_t,1) 1]);%每个列向量的元素(样本)减去自己的均值
XL_t = XL_t - repmat(mean(XL_t), [size(XL_t,1) 1]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Start our proposed algorithm on training samples %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Intialize D,A, and W(U)
D = mexTrainDL([XH_t;XL_t], param); %调用函数计算字典D
Dh = D(1:size(XH_t,1),:); %Dh
Dl = D(size(XH_t,1)+1:end,:); %Dl
Wl = eye(size(Dh, 2)); %Uh
Wh = eye(size(Dl, 2)); %Ul
Alphah = mexLasso([XH_t;XL_t], D, param);%Ah
Alphal = Alphah; %Al
clear D;
% Iteratively solve D,A, and W (U)
[Alphah, Alphal, XH_t, XL_t, Dh, Dl, Wh, Wl, Uh, Ul, f] = coupled_DL_recoupled(Alphah, Alphal, XH_t, XL_t, Dh, Dl, Wh, Wl, par);
clear XH_t XL_t;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Finish our proposed alorithm on training samples %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Prework on testing samples
XH_t = zeros(size1*size2,100);
XL_t = zeros(size1*size2,100);
for k = 1:100
img_yiq = RGB2YIQ(double(testing_photo{k}));
XH_t(:,k) = reshape(img_yiq(:,:,1),[size1*size2 1] );
tmp = double(testing_sketch{k});
if size(tmp,3) > 1
img_yiq = RGB2YIQ(tmp);
tmp = img_yiq(:,:,1);
end
XL_t(:,k) = reshape(tmp,[size1*size2 1]);
end
XH_t = XH_t - repmat(mean(XH_t), [size(XH_t,1) 1]);
XL_t = XL_t - repmat(mean(XL_t), [size(XL_t,1) 1]);
%% Project the testing samples on the common feature space
Alphah = full(mexLasso(XH_t, Dh, param));
Alphal = full(mexLasso(XL_t, Dl, param));
photo_coeffs = inv(Uh) * Alphah;
sketch_coeffs = inv(Ul) * Alphal;
%% Direct NN method to find datapairs on common feature space
correct = 0;
for test = 1:100
dist = zeros(100,1);
for train = 1:100
dist(train) = norm(photo_coeffs(:,train) - sketch_coeffs(:,test));
end
minD = min(dist);
predict = find(dist == minD);
if predict(1) == test
correct = correct + 1;
end
end
fprintf('Recogntion Rate: %d\n',correct);
%% correlation based
%{
correct1 = 0;
for test = 1:100
corr = zeros(100,1);
for train = 1:100
tmp = corrcoef(photo_coeffs(:,train) , sketch_coeffs(:,test));
corr(train) = tmp(2);
end
%corr
maxC = max(corr);
predict = find(corr == maxC);
if predict(1) == test
correct1 = correct1 + 1;
end
%pause;
end
%}