0

I'm reading U-Net: Convolutional Networks for Biomedical Image Segmentation and want to implement this in Keras.

In U-Net, I need to concatenate convolutional layers, one is in the contracting path and the other is in the expansive path (Fig1. 1. in the paper).

However, the sizes of them doesn't match, so I have to resize the output of convolutional layer before concatenating.

How do I do this in Keras?

Community
  • 1
  • 1

1 Answers1

3

There is a Cropping2D Layer in Keras: https://keras.io/layers/convolutional/#cropping2d

...
conv_13 = Conv2D(64, (3, 3), padding='same', activation='relu')(conv_12) # has outputsize of 568x568
...
crop_13 = Cropping2D((392, 392))(conv_13) # crop 568x568 to 392x392 symmetrically
merge_91 = Concatenate()([crop_13, upsampled_81) # concatenate both layers with same 2D size
...

Example for concatenating the first size (568x568) to the last upsampled size (392x392).

Jodo
  • 4,515
  • 6
  • 38
  • 50