Coupled Dictionary and Feature Space Learning with Applications to Cross-Domain......梳理

Coupled Dictionary and Feature Space Learning with Applications to Cross-Domain Image Synthesis and Recognition



表示n对无标签的数据,分别来自不同的域,比如真实人脸和素描人脸,每个样本维度分别为d_{1}d_{2}


E_{DL}表示字典学习的能力项,关于数据重构误差。表示字典或结果系数的关系。



 


 

对于我们不考虑字典间的关系,考虑结果系数的关系。因为一旦得到结果系数之间的关系,就可以通过得到字典间的关系。


是关系函数,表示的跨域关系。


:考虑一个域的稀疏系数\mathbf{A}_{x}等于另一个域\mathbf{A}_{y}的线性映射\mathbf{WA}_{y}


为了更好地表示和关联跨域数据,结合公共特征空间学习和原始的联合字典学习,让:

替换

是关于\mathbf{A}_{x}的映射矩阵。

\mathbf{X}k_{c}维的公共特征空间的映射结果。

此时公共特征空间学习转化为对\mathbf{U}_{x}的学习。

即,此处我们使用来作为联合字典学习的关系项。即,结合了公共特征空间学习和原始的联合字典学习。


注意:因为最小化得到的解不是唯一的(例如,平凡解\mathbf{U}_{x}= \mathbf{U}_{y}= \mathbf{0}),所以我们需要额外的约束来确保有唯一解。


我们不仅希望公共特征空间能关联跨域数据,同时也希望能使用另一个域的数据映射结果来恢复这个域的图像。

即,假设\mathbf{p}是公共特征空间中来自数据集\mathbf{X}的一个映射,那么我们可以得到,这使得属于另一个域的输出图像可以通过计算来重建。


通过上述的描述,我们为跨域图像合成定义:

一旦得到,我们有

两边同时乘\mathbf{U}_{x}\mathbf{U}_{y},应用最小化得到

所以说结果特征空间可以看作是来自不同域的数据的公共表示。



我们模型的最终优化问题:




优化

更新

先用联合字典学习来计算 ,此时保持\mathbf{A}\mathbf{U}为常量。此时(3)就转变成:


这是一个二次约束的二次规划问题 (QCQP),可以通过Lagrange dual techniques解决。



更新

保持映射矩阵\mathbf{U}和字典\mathbf{D}不变。因为我们除了标准的稀疏编码形式,还添加了公共特征空间学习,所以(3)转变为:


进一步简化问题:

这是一个标准的稀疏编码形式。可以通过SPAMS解决。



更新

保持不变,我们有:


(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
%}              

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值