0

I am trying to merge two layers using the functional API. Now my output shape from one layer is not the same as the output shape from the other layer. How may I go about downsampling or compressing the one with the higher image dimension?

eg - downsample=(Merge([layerone,layersix],mode='concat')) layerthree1=Convolution2D(128, 3, 3,activation='relu')(downsample)

hello
  • 25
  • 1
  • 4

1 Answers1

1

Common methods for downsampling are max pooling, and average pooling layers(https://keras.io/layers/pooling/)

If what you need is to reduce size of the image a fixed number (rather than halve it or divide by a number) you could use a convolution with a border_mode='valid' for side pixel you want to remove.

maz
  • 1,980
  • 14
  • 17
  • So i guess I have two options - 1st is to pad the smaller image and then merge and then downsample them together after merge 2nd is to Use extra convolution on the larger image to make it smaller and then merge them? – hello Apr 17 '17 at 02:01
  • What i meant was there are two options for Downsampling. One is to use pooling (or strided convolution for that matter) , that will reduce your image by a fraction. For example a (2,2) pooling or a 2,2 strided convolution will reduce your image by half in each direction, a total reduction by a factor of 4 in you number of pixels. That would be great to match 32x32 images with 16x16, by reducing the first ones. But it wouldn't work if for example you needed to match a 17x17 image with a 16x16. So what you would need to do is to use a convolution with border_mode='valid'. – maz Apr 17 '17 at 12:21