Boom
Boom

Reputation: 1315

When and why kernel_size may be 1 or 2 dims when using Conv2D?

When using Conv2D we can define the kernel_size to be 1 dim or 2 dims (or higher value of dims)

for example:

Conv2D(filters=32, kernel_size=3, activation='relu')

or

Conv2D(filters=32, kernel_size=(3,3), activation='relu')
  1. When using Conv2D , what is the recommendations ?
  2. What are the cases we will choose to use 1D (kernel_size=7) and what are the cases we will prefer to choose 2D (kernel_size=(3,3)) or other dim ?
  3. Does the choosing the dim of kernel_size will affect the choosing of pooling size ? (MaxPooling2D(pool_size=?))

Upvotes: 1

Views: 2194

Answers (2)

George
George

Reputation: 5681

The kernel size for Conv2D is always 2 dimensional

here

kernel_size: An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

You just have the option to write kernel size 3 but in reality means (3,3). For Conv1D, the kernel size is 1d also.

If you use Conv2D you must choose MaxPooling2D , if you use Conv1D you must choose MaxPooling1D.

Upvotes: 1

Alex K.
Alex K.

Reputation: 861

  1. (and 2) ):

kernel_size: An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

Keras doc. Conv2D performs convolution with 2D filter, it can be square (use single int to define) or not square (use tuple). Regarding size of filter (3, 7, etc.) choice depends on task and architecture. See answer for basic intuition behind particular example

  1. Kernel_size as well as stride and padding affect Conv2D output shape, and you should take that into account if you want MaxPooling2D output of specific shape.

Upvotes: 2

Related Questions