forked from KamitaniLab/GenericObjectDecoding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_decodedfeatures.m
More file actions
110 lines (86 loc) · 4.27 KB
/
Copy pathconvert_decodedfeatures.m
File metadata and controls
110 lines (86 loc) · 4.27 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
% Convert feature prediction results fot deep image reconstruction
%
% Output files:
%
% decodedfeatures -+- imagery --- matconvnet -+- cnn1 -+- Subject1 -+- FFA --- Mat files
% | | | |
% | | | +- LOC --- Mat files
% | | | |
% | | | ...
% | | |
% | | +- Subject2 --- ...
% | | |
% | | ...
% | |
% | +- cnn2 --- ...
% | |
% | ...
% |
% +- perception --- ...
%
clear all;
%% Initial settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Data settings
% subjectList : List of subject IDs [cell array]
% roiList : List of ROIs [cell array]
% featureList : List of image features [cell array]
subjectList = {'Subject1', 'Subject2', 'Subject3', 'Subject4', 'Subject5'};
roiList = {'V1', 'V2', 'V3', 'V4', 'FFA', 'LOC', 'PPA', 'LVC', 'HVC', 'VC'};
featureList = {'cnn1', 'cnn2', 'cnn3', 'cnn4', 'cnn5', 'cnn6', 'cnn7', 'cnn8'};
network = 'matconvnet';
%% Directory settings
workDir = pwd;
resultsDir = fullfile(workDir, 'results'); % Directory to save analysis results
outputDir = fullfile(workDir, 'decodedfeatures'); % Directory to save converted decoded features
%% File name settings
resultFileNameFormat = @(s, r, f) fullfile(resultsDir, sprintf('%s/%s/%s.mat', s, r, f));
%% Main %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for isub = 1:length(subjectList)
for iroi = 1:length(roiList)
for ifeat = 1:length(featureList)
subject = subjectList{isub};
roi = roiList{iroi};
feature = featureList{ifeat};
resultfile = resultFileNameFormat(subject, roi, feature);
dirDecodedFeatruePercept = fullfile(outputDir, 'perception', network, ...
featureList{ifeat}, subjectList{isub}, roiList{iroi});
dirDecodedFeatrueImagery = fullfile(outputDir, 'imagery', network, ...
featureList{ifeat}, subjectList{isub}, roiList{iroi});
if ~exist(resultfile)
error(sprintf('Result file not found: %s\n', resultfile));
end
res = load(resultfile);
categoryTestPercept = res.categoryTestPercept;
categoryTestImagery = res.categoryTestImagery;
predfeatPerceptAve = res.predictPerceptAveraged;
predfeatImageryAve = res.predictImageryAveraged;
%% Save decoded features for image reconstruction
setupdir(dirDecodedFeatruePercept);
setupdir(dirDecodedFeatrueImagery);
subsPercept.type = '()';
subsPercept.subs = repmat({':'}, 1, ndims(predfeatPerceptAve));
subsImagery.type = '()';
subsImagery.subs = repmat({':'}, 1, ndims(predfeatImageryAve));
for p = 1:length(categoryTestPercept)
catid = categoryTestPercept(p);
subsPercept.subs{1} = p;
feat = squeeze(shiftdim(subsref(predfeatPerceptAve, subsPercept), 1));
resfilePercept = fullfile(dirDecodedFeatruePercept, ...
sprintf('%s-%s-%s-%s-%s-%s-%d.mat', ...
'decodedfeatures', 'perception', network, ...
featureList{ifeat}, subjectList{isub}, roiList{iroi}, catid));
save(resfilePercept, 'feat', '-v7.3');
end
for p = 1:length(categoryTestImagery)
catid = categoryTestImagery(p);
subsImagery.subs{1} = p;
feat = squeeze(shiftdim(subsref(predfeatImageryAve, subsImagery), 1));
resfileImagery = fullfile(dirDecodedFeatrueImagery, ...
sprintf('%s-%s-%s-%s-%s-%s-%d.mat', ...
'decodedfeatures', 'imagery', network, ...
featureList{ifeat}, subjectList{isub}, roiList{iroi}, catid));
save(resfileImagery, 'feat', '-v7.3');
end
end
end
end