Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the meaning of border_mode in keras?

Tags:

keras

theano

I'm confused what to use, valid,same or full. I also don't know what does it do. I can't find it in the Docs. And border_mode for MaxPooling2D layer does not make sense to me. (It does make sense to me for the Convolution layers though).

like image 738
Lei Sang Avatar asked Dec 30 '16 08:12

Lei Sang


2 Answers

When you use a two-dimentional image with m rows and n cols, and a a*b size kernel to convolute the input image, this is what happens:

If border_mode is 'full', returns a (m+a-1)x(n+b-1) image;
if border_mode is 'same', returns the same dimention as the input image;
if border_mode is 'valid',returns a (m-a+1)x(n-b+1) image. for example,

Input: In following 4x4 image

A = [12 13 14 15;1 2 3 4;16 17 18 19;5 6 7 8], and a 3x3 kernel B = [1 2 3;4 5 6;7 8 9],

if border_mode is 'full', then returns a 6x6 matrix;
if border_mode is 'same', then returns a 4x4 matrix;
if border_mode is 'valid', then returns a 2x2 matrix.

you can also use function conv2(A,B,border_mode) in MATLAB to test the output matrix.

Hope this answer could help.

like image 55
Liangmp Avatar answered Nov 16 '22 14:11

Liangmp


This is for Keras 2+ as they replaced the Border_mode with padding And it can be used for down and upsampling in a network.

like image 41
MNM Avatar answered Nov 16 '22 14:11

MNM