Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions exercise1.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
% -------------------------------------------------------------------------
% Part 1.1: Linear convolution
% -------------------------------------------------------------------------
clc
close all
clear all

% Read an example image
x = imread('peppers.png') ;
Expand All @@ -11,7 +14,8 @@
x = im2single(x) ;

% Visualize the input x
figure(1) ; clf ; imagesc(x) ;
figure(1) ;clf ; imagesc(x); title('original image');
pause

% Create a bank of linear filters
w = randn(5,5,3,10,'single') ;
Expand All @@ -20,15 +24,18 @@
y = vl_nnconv(x, w, []) ;

% Visualize the output y
figure(2) ; clf ; vl_imarraysc(y) ; colormap gray ;
figure(2) ; clf ; vl_imarraysc(y) ; colormap gray ; title('convolved image');
pause

% Try again, downsampling the output
y_ds = vl_nnconv(x, w, [], 'stride', 16) ;
figure(3) ; clf ; vl_imarraysc(y_ds) ; colormap gray ;
figure(3) ; clf ; vl_imarraysc(y_ds) ; colormap gray ; title('downsampled image');
pause

% Try padding
y_pad = vl_nnconv(x, w, [], 'pad', 4) ;
figure(4) ; clf ; vl_imarraysc(y_pad) ; colormap gray ;
figure(4) ; clf ; vl_imarraysc(y_pad) ; colormap gray ; title('padded image');
pause

% Manually design a filter
w = [0 1 0 ;
Expand All @@ -39,7 +46,7 @@
figure(5) ; clf ; colormap gray ;
subplot(1,2,1) ; imagesc(y_lap) ; title('filter output') ;
subplot(1,2,2) ; imagesc(-abs(y_lap)) ; title('- abs(filter output)') ;

pause

% -------------------------------------------------------------------------
% Part 1.2: Non-linear gating (ReLU)
Expand All @@ -51,15 +58,17 @@
z = vl_nnrelu(y) ;

figure(6) ; clf ; colormap gray ;
subplot(1,2,1) ; vl_imarraysc(y) ;
subplot(1,2,2) ; vl_imarraysc(z) ;
subplot(1,2,1) ; vl_imarraysc(y) ; title('convolved') ;
subplot(1,2,2) ; vl_imarraysc(z) ; title('relu') ;
pause

% -------------------------------------------------------------------------
% Part 1.2: Pooling
% -------------------------------------------------------------------------

y = vl_nnpool(x, 15) ;
figure(7) ; clf ; imagesc(y) ;
figure(7) ; clf ; imagesc(y) ; title('pooling') ;
pause

% -------------------------------------------------------------------------
% Part 1.3: Normalization
Expand All @@ -70,4 +79,7 @@
alpha = 1 ;
beta = 0.5 ;
y_nrm = vl_nnnormalize(x, [rho kappa alpha beta]) ;
figure(8) ; clf ; imagesc(y_nrm) ;
figure(8) ; clf ; imagesc(y_nrm) ; title('normalization') ;
pause
disp('done.');