Skip to content

Instantly share code, notes, and snippets.

@mzaradzki
Last active March 13, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzaradzki/d1225aba6fefb0fcaf15753a0ae2fa16 to your computer and use it in GitHub Desktop.
Save mzaradzki/d1225aba6fefb0fcaf15753a0ae2fa16 to your computer and use it in GitHub Desktop.
fcn32model = fcn32_blank()
fcn32shape = fcn32model.layers[-1].output_shape
fcn32size = fcn32shape[2] # INFO: =32 when images are 512x512
sp4 = Convolution2D(21, 1, 1,
border_mode='same', # INFO : border_mode does not matter for 1x1
activation=None,
name='score_pool4')
# INFO : Keras sum is a special case of the merge function
summed = merge([sp4(fcn32model.layers[14].output), fcn32model.layers[-1].output], mode='sum')
# INFO :
# deconv setting is valid if (528-32)/16 + 1 = deconv_input_dim (= fcn32size)
deconv_output_size = (fcn32size-1)*16+32 # INFO: =528 when images are 512x512
upnew = Deconvolution2D(21, 32, 32,
output_shape=(None, 21, deconv_output_size, deconv_output_size),
border_mode='valid', # WARNING : valid, same or full ?
subsample=(16, 16),
activation=None,
name = 'upsample_new')
# INFO : cropping as deconv gained pixels
extra_margin = deconv_output_size - fcn32size*16 # INFO: =16 when images are 512x512
crop_margin = Cropping2D(cropping=((extra_margin/2, extra_margin/2),
(extra_margin/2, extra_margin/2)))
fcn16model = Model(fcn32model.input, crop_margin(upnew(summed)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment