Skip to content

Commit

Permalink
add: add open set domain adaptation
Browse files Browse the repository at this point in the history
  • Loading branch information
jindongwang committed Nov 23, 2017
1 parent 466a145 commit db9be94
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
50 changes: 50 additions & 0 deletions code/open_set_da/get_label_binary.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function [Xct,Ot] = get_label_binary(C,m,lambda,Dct)
% Inputs:
%%% C : Number of share classes between src and tar
%%% m : Number of target domain samples
%%% lambda : lambda
%%% Dct : all d_ct in matrix form, m * C
% Outputs:
%%% Xct : all x_ct in matrix form, m * C
%%% Ot : all o_t in vector, m * 1
intcon = C*m+m; % Number of all variables to be solved (all x_ct and o_t)

%% Construct objective
Lambda = ones(1,m) * lambda;
D_vec = reshape(Dct',1,C*m);
one_vec = ones(1,m);
CC = [D_vec,Lambda];

%% Construct equalities: \sum_c x_{ct} + o_t = 1 for each t
Aeq = [];
Beq = [];
for i = 1 : m
all_zeros = zeros(1,intcon);
all_zeros((i - 1) * C + 1 : (i - 1) * C + 10) = 1;
all_zeros(C * m + i) = 1;
Aeq = [Aeq;all_zeros];
Beq = [Beq;1];
end

%% Construct inequalities: \sum_t x_{ct} \ge 1 for each c
A = [];
B = [];
for i = 1 : C
all_zeros = zeros(1,intcon);
j = i : C : C * m;
all_zeros(j) = -1;
A = [A;all_zeros];
B = [B;-1];
end
% A = [-1 * ones(1,C * m),zeros(1,m)];
% B = -1 * C;
%% Make sure x_ct and o_t are either 0 or 1
lb_12 = zeros(intcon,1);
ub_12 = ones(intcon,1);

%% Solve integer 0/1 programming using Matlab's intlinprog function
X = intlinprog(CC,intcon,A,B,Aeq,Beq,lb_12,ub_12);
Xct_vec = X(1:C*m);
Xct = reshape(Xct_vec,C,m)'; % x_ct matrix, m * C
Ot = X(C*m+1:end); % o_t matrix, m * 1
end
35 changes: 35 additions & 0 deletions code/open_set_da/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Open Set Domain Adaptation

This directory contains the implementation of the ICCV-17 paper *[Open Set Domain Adaptation](http://openaccess.thecvf.com/content_iccv_2017/html/Busto_Open_Set_Domain_ICCV_2017_paper.html)*.

## About the code

I'm not the authors of that paper. So this is not official. We all hope the authors can provide the implementations ASAP. However, according to them, the code is not available for now since they developed this method in a company, there is some rules to follow.

The official repo of this paper is: [Heliot7/open-set-da](https://github.com/Heliot7/open-set-da). We hope authors can get publish the code soon.

## About the method

The method in the paper contains 2 main processes:
- Get label assignment using Eq.(1)
- And learn the mapping $W$

Due to some reasons, part 2 is hard to understand. So I could only re-implement the part 1, which is basically an integer programming. I hope to get more information about part 2, so I will add this soon.

The code is written in Matlab.

## Get label assignment

The code is just in `get_label_binary.m`. For the meaning of this function, please refer to Eq.(1) of the original paper.

## Get the mapping $W$

To be added.

## My understanding (in Chinese)

Since this paper is quite original and has obtain good results, I've also provided an article reading about this paper. Please refer to the [article](https://zhuanlan.zhihu.com/p/31230331) (in Chinese).

## Reference

Pau Panareda Busto, Juergen Gall. Open set domain adaptation. ICCV 2017.

0 comments on commit db9be94

Please sign in to comment.