def build_fcn(X):
#
# DESCRIPTION
# KERAS FCN DEFINITION
# Using the shape of the input to setup the input layer we create a FCN with 2 skips
#
# INPUTS
# X [number_of_images, 400, 400, channels]
#
# OUTPUTS
# model uninstantiated Keras model
#
img_rows, img_cols = 400, 400
inputs = Input(shape=X.shape[1:])
conv1 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(inputs)
conv1 = Convolution2D(32, 4, 4, activation='relu', border_mode='same')(conv1)
pool1 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv1)
conv2 = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(pool1)
conv2 = Convolution2D(64, 4, 4, activation='relu', border_mode='same')(conv2)
pool2 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv2)
conv3 = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(pool2)
conv3 = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(conv3)
pool3 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv3) # 50 50
conv4 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(pool3)
conv4 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(conv4)
conv4 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(conv4)
pool4 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv4) # 25 25
conv5 = Convolution2D(512, 3, 3, activation='relu', border_mode='same')(pool4)
conv5 = Convolution2D(512, 3, 3, activation='relu', border_mode='same')(conv5)
conv5 = Convolution2D(512, 3, 3, activation='relu', border_mode='same')(conv5)
pool5 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv5)
drop3 = Dropout(0.5)(pool5)
convpool3 = Convolution2D(60, 1, 1, activation='relu', border_mode='same')(pool3)
convpool4 = Convolution2D(60, 1, 1, activation='relu', border_mode='same')(pool4)
convdrop3 = Convolution2D(60, 1, 1, activation='relu', border_mode='same')(drop3)
drop3x5 = UpSampling2D(size=(5, 5))(convdrop3)
croppeddrop3x5 = Cropping2D(((5,5),(5,5)))(drop3x5) # 50 50
pool4x2 = UpSampling2D(size=(2, 2))(convpool4) # 50 50
fuse2 = merge([convpool3, pool4x2, croppeddrop3x5], mode='concat', concat_axis=-1) # 50 50 4224
upscore3 = UpSampling2D(size=(8, 8))(fuse2) # F 8s
convscore3 = Convolution2D(1, 1, 1, activation='sigmoid')(upscore3)
# Instantiate Model object
model = Model(input=inputs, output=convscore3)
sgd = SGD(lr=1e-5, decay=2, momentum=0.9, nesterov=True)
model.compile(optimizer=sgd, loss=pixel_wise_loss, metrics=['mean_squared_error'])
#model.compile(loss='mean_squared_error', optimizer=sgd)
return model
## CUSTOM LOSS FUNCTION
评论列表
文章目录