本文主要讲解关于 Y = VL_NNCONV(X, F, B)函数中B的格式,如下所示:
% Read an example image
x = imread('peppers.png') ;
% Convert to single format
x = im2single(x) ;
% Visualize the input x
figure(1) ; clf ; imagesc(x) ;
% Create a bank of linear filters
w = randn(5,5,3,100,'single') ;
b=randn(100,1,'single');
% Apply the convolutional operator
% y = vl_nnconv(x, w, []) ;
y = vl_nnconv(x, w, b) ;
% Visualize the output y
figure(2) ; clf ; vl_imarraysc(y) ; colormap gray ;
注意b是与滤波器数目一致的,可将偏置b的格式写为b=randn(1,100,'single'),亦或b=randn(1,1,1,100,'single')均是正确的,注意其中的'single'一方面是为了与w的数据类型一致,另一方面是因为MatConvNet默认的数据类型为'single',而Matlab默认的类型为'double',若直接写为b=randn(1,100)将出现"DATA and BIASES do not have compatible formats."的错误提示。
如下是运行结果: