File size: 2,538 Bytes
038300a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
function batch_training_performance=fun_ANN_Model(image,param)
%
% model=param.model;
nmb_of_hidden_layers=param.nmb_of_hidden_layers;

patch=param.patch;
nmb_of_modules=param.nmb_of_modules;
nmb_of_module_subsets=param.nmb_of_module_subsets;
nmb_of_colors=param.nmb_of_colors;
channels_names=param.channels_names;
% cross_entropy=param.cross_entropy;
nmb_of_labs_per_module=param.nmb_of_labs_per_module;
sz=size(image);
if length(sz)==2
    nmb_of_data=1;
else
    nmb_of_data=sz(2);
end

if nmb_of_data>1
    batch_training_performance=zeros(2,nmb_of_data,nmb_of_modules,nmb_of_module_subsets,nmb_of_colors);
else
    batch_training_performance=zeros(2,nmb_of_modules,nmb_of_module_subsets,nmb_of_colors);
end
for module=1:nmb_of_modules
    for subset=1:nmb_of_module_subsets
        for color=1:nmb_of_colors
            reportname1 = sprintf('../Model_Parameter/Trained_Parameter_patch_%d_module_%d_subset_%d_ch_%s.mat',...
                patch, module, subset, char(channels_names(color)));
            %      str=struct('W', W, 'b', b);
            temp_load=load(reportname1);
            W=temp_load.W;
            b=temp_load.b;
            % Assign the trained parameters
            %
            W1=W.LayerName1;
            W2=W.LayerName2;
            b1=b.LayerName1;
            b2=b.LayerName2;

            if nmb_of_data>1
                a_0=image(:,:,color); 
            else
                a_0=image(:,color);
            end
            nmb_of_labels=length(b2);
            z1=W1*a_0+b1;
            [a1,~]=fun_activation(z1);

            z2=W2*a1+b2;
            if nmb_of_hidden_layers==1
                [a2,~]=fun_softmax(z2);
                predicted_vector=a2;
            else
                W3=W.LayerName3;
                b3=b.LayerName3;
                nmb_of_labels=length(b3);
                [a2,~]=fun_activation(z2);

                z3=W3*a2+b3;
                [a3,~]=fun_softmax(z3);
                predicted_vector=a3;
            end
            prediction=fun_predicted_vector_2_label(predicted_vector,nmb_of_labels);
            abs_label=prediction.label+(module-1)*nmb_of_labs_per_module;
            if nmb_of_data>1
                batch_training_performance(:,:,module,subset,color)=[abs_label;prediction.distance];
            else
                batch_training_performance(:,module,subset,color)=[abs_label;prediction.distance];
            end
        end
    end
end
if nmb_of_data>1
    batch_training_performance=permute(batch_training_performance,[1,3,4,5,2]);%
end
end