-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotFeatures.m
More file actions
71 lines (59 loc) · 1.74 KB
/
Copy pathPlotFeatures.m
File metadata and controls
71 lines (59 loc) · 1.74 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
clear all
load('MnistConv.mat')
% Load the input image from your computers
imageFile = "C:\Users\Anjali\Downloads\Untitled.png"; % Replace with the actual path to your image file
x = imread(imageFile);
% Convert the image to grayscale if necessary
if size(x, 3) > 1
x = rgb2gray(x);
end
% Resize the image to match the input size of the CNN (28x28)
x = imresize(x, [28, 28]);
% Normalize the pixel values to the range [0, 1]
x = double(x) / 255;
y1 = Conv(x, W1); % Convolution, 20x20x20
y2 = ReLU(y1); %
y3 = Pool(y2); % Pool, 10x10x20
y4 = reshape(y3, [], 1); % 2000
v5 = W5 * y4; % ReLU, 360
y5 = ReLU(v5); %
v = Wo * y5; % Softmax, 10
y = Softmax(v); %
figure;
imshow(x);
title('Input Image')
convFilters = zeros(9 * 9, 20);
for i = 1:20
filter = W1(:, :, i);
convFilters(:, i) = filter(:);
end
figure
display_network(convFilters);
title('Convolution Filters')
fList = zeros(20 * 20, 20);
for i = 1:20
feature = y1(:, :, i);
fList(:, i) = feature(:);
end
figure
display_network(fList);
title('Features [Convolution]')
fList = zeros(20 * 20, 20);
for i = 1:20
feature = y2(:, :, i);
fList(:, i) = feature(:);
end
figure
display_network(fList);
title('Features [Convolution + ReLU]')
fList = zeros(10 * 10, 20);
for i = 1:20
feature = y3(:, :, i);
fList(:, i) = feature(:);
end
figure
display_network(fList);
title('Features [Convolution + ReLU + MeanPool]')
% Display the predicted class
[~, prediction] = max(y);
fprintf('Predicted class: %d\n', prediction);