Last active
September 17, 2022 20:01
-
-
Save gonzmg88/8a27dab653982817034938b0af1a2bf7 to your computer and use it in GitHub Desktop.
FCNN architecture used in the paper: "Transferring Deep Learning models for cloud detection between Landsat-8 and Proba-V".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This file contains the fully convolutional neural network architecture used in the paper: | |
"Transferring Deep Learning models for cloud detection between Landsat-8 and Proba-V" (Mateo-García et al 2019) | |
The function UNet builds the FCNN and compiles the model with the loss, the optimizer and the weight decay | |
used in the paper. | |
""" | |
from tensorflow import keras | |
AXIS_CHANNELS = 3 | |
def _conv_blocks(ip_, nfilters, reg, name): | |
conv = keras.layers.SeparableConv2D( | |
nfilters, (3, 3), | |
padding='same', | |
name=name+"_conv_1", | |
depthwise_regularizer=reg, | |
pointwise_regularizer=reg)(ip_) | |
conv = keras.layers.BatchNormalization(axis=AXIS_CHANNELS, | |
name=name + "_bn_1")(conv) | |
conv = keras.layers.Activation('relu',name=name + "_act_1")(conv) | |
conv = keras.layers.SeparableConv2D( | |
nfilters, (3, 3), | |
padding='same', | |
name=name+"_conv_2", | |
depthwise_regularizer=reg, | |
pointwise_regularizer=reg)(conv) | |
conv = keras.layers.BatchNormalization(axis=AXIS_CHANNELS, | |
name=name + "_bn_2")(conv) | |
return keras.layers.Activation('relu',name=name + "_act_2")(conv) | |
def UNet(input_shape=(None,None,4), weight_decay=5e-4,lr=1e-5): | |
inputs_ = keras.layers.Input(shape=input_shape) | |
reg = keras.regularizers.l2(weight_decay) | |
conv1 = _conv_blocks(inputs_, | |
32, | |
reg, | |
name="input") | |
pool1 = keras.layers.MaxPooling2D(pool_size=(2, 2), | |
name="pooling_1")(conv1) | |
conv2 = _conv_blocks(pool1, | |
64, reg, name="pool1") | |
pool2 = keras.layers.MaxPooling2D(pool_size=(2, 2), | |
name="pooling_2")(conv2) | |
conv3 = _conv_blocks(pool2, | |
128, reg, name="pool2") | |
up8 = keras.layers.concatenate([ | |
keras.layers.Conv2DTranspose(64, (2, 2), | |
strides=(2, 2), | |
padding='same',name="upconv1", | |
kernel_regularizer=reg)(conv3), | |
conv2], | |
axis=AXIS_CHANNELS, name="concatenate_up_1") | |
conv8 = _conv_blocks(up8, | |
64,reg, name="up1") | |
up9 = keras.layers.concatenate([ | |
keras.layers.Conv2DTranspose(32, (2, 2), | |
strides=(2, 2), | |
padding='same',name="upconv2", | |
kernel_regularizer=reg)(conv8), | |
conv1], | |
axis=AXIS_CHANNELS, name="concatenate_up_2") | |
conv9 = _conv_blocks(up9, | |
32, reg, name="up2") | |
conv10 = keras.layers.Conv2D(1, (1, 1), | |
kernel_regularizer=reg, name="linear_model", | |
activation="sigmoid")(conv9) | |
model = keras.models.Model(inputs=[inputs_], outputs=[conv10], | |
name="FCNNMateo-Garcia et al") | |
sgd = keras.optimizers.Adam(lr=lr) | |
model.compile(loss=keras.losses.binary_crossentropy, | |
optimizer=sgd, | |
metrics=["binary_accuracy"]) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment