-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathunsupervised_DA_office31.m
45 lines (43 loc) · 2.15 KB
/
unsupervised_DA_office31.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
% =====================================================================
% Code for conference paper:
% Qian Wang, Penghui Bu, Toby Breckon, Unifying Unsupervised Domain
% Adaptation and Zero-Shot Visual Recognition, IJCNN 2019
% By Qian Wang, [email protected]
% =====================================================================
%% Loading Data:
% Features are extracted using resnet50 pretrained on ImageNet without
% fine-tuning
clear all
addpath('./utils/');
%data_dir = '/mnt/HD2T/DomainAdaptation/Office31data/';
data_dir = 'E:\DomainAdaptation\Office31data\';
domains = {'A','D','W'};
for source_domain_index = 1%:length(domains)
load([data_dir 'office-' domains{source_domain_index} '-resnet50-noft']);
domainS_features = L2Norm(resnet50_features);
%domainS_features = resnet50_features;
domainS_labels = labels+1;
for target_domain_index = 1:length(domains)
if target_domain_index == source_domain_index
continue;
end
fprintf('Source domain: %s, Target domain: %s\n',domains{source_domain_index},domains{target_domain_index});
load([data_dir 'office-' domains{target_domain_index} '-resnet50-noft']);
domainT_features = L2Norm(resnet50_features);
%domainT_features=resnet50_features;
domainT_labels = labels+1;
num_class = length(unique(domainT_labels));
%% Baseline method: using 1-NN, only labelled source data for training
fprintf('Baseline method using 1NN:\n');
classifierType='1nn';
acc= func_recognition(domainS_features,domainT_features,domainS_labels,domainT_labels,classifierType);
%% Baseline method: using SVM, only labelled source data for training
%fprintf('Baseline method using SVM:\n');
%classifierType='svm';
%acc= func_recognition(domainS_features,domainT_features,domainS_labels,domainT_labels,classifierType);
%% Proposed method:
fprintf('Proposed method using 1NN:\n');
acc_per_class = DA_LPP(domainS_features,domainS_labels,domainT_features,domainT_labels);
%acc_per_class = DA_LDA(domainS_features,domainS_labels,domainT_features,domainT_labels);
end
end