Tweaking your convolutions

Image Modeling with Keras

Ariel Rokem

Senior Data Scientist, University of Washington

Convolution

Image Modeling with Keras

Convolution with zero padding

Image Modeling with Keras

Zero padding in Keras

model.add(Conv2D(10, kernel_size=3, activation='relu', 
                 input_shape=(img_rows, img_cols, 1)),
                 padding='valid')
Image Modeling with Keras

Zero padding in Keras

model.add(Conv2D(10, kernel_size=3, activation='relu', 
                 input_shape=(img_rows, img_cols, 1)),
                 padding='same')
Image Modeling with Keras

Strides

Image Modeling with Keras

Strides in Keras

model.add(Conv2D(10, kernel_size=3, activation='relu', 
                 input_shape=(img_rows, img_cols, 1)),
          strides=1)
Image Modeling with Keras

Strides in Keras

model.add(Conv2D(10, kernel_size=3, activation='relu', 
                 input_shape=(img_rows, img_cols, 1)),
          strides=2)
Image Modeling with Keras

Example

Image Modeling with Keras

Calculating the size of the output

$$O = ((I - K + 2P) / S) + 1$$

where

  • $I$ = size of the input
  • $K$ = size of the kernel
  • $P$ = size of the zero padding
  • $S$ = strides
Image Modeling with Keras

Calculating the size of the output

$$ 28 = ((28 - 3 + 2) / 1) + 1$$

$$ 10 = ((28 - 3 + 2) / 3) + 1$$

Image Modeling with Keras

Dilated convolutions

Image Modeling with Keras

Dilation in Keras

model.add(Conv2D(10, kernel_size=3, activation='relu', 
                 input_shape=(img_rows, img_cols, 1)),
          dilation_rate=2)
Image Modeling with Keras

Let's practice!

Image Modeling with Keras

Preparing Video For Download...