Esempio n. 1
0
File: dense.py Progetto: ILDAR9/LID
def build_model(bands=60,
                frames=41,
                channels=1,
                n_labels=3,
                dropout=0.0,
                depth=7,
                block=2,
                growth=15,
                pooling='avg',
                bottleneck=False,
                reduction=0.0,
                subsample=True):
    """
    DenseNet
    """

    # https://github.com/keras-team/keras-contrib/blob/master/keras_contrib/applications/densenet.py
    from keras_contrib.applications import densenet

    input_shape = (bands, frames, channels)

    model = densenet.DenseNet(input_shape=input_shape,
                              pooling=pooling,
                              depth=depth,
                              nb_dense_block=block,
                              growth_rate=growth,
                              bottleneck=bottleneck,
                              reduction=reduction,
                              subsample_initial_block=subsample,
                              include_top=True,
                              classes=n_labels,
                              dropout_rate=dropout)

    return model
Esempio n. 2
0
    def Atrous_DenseNet(self,
                        weight_decay=1E-4,
                        batch_momentum=0.9,
                        batch_shape=None,
                        include_top=True,
                        activation='sigmoid'):

        classes = self.classes
        if include_top is True:
            return densenet.DenseNet(depth=None,
                                     nb_dense_block=3,
                                     growth_rate=32,
                                     nb_filter=-1,
                                     nb_layers_per_block=[6, 12, 24, 16],
                                     bottleneck=True,
                                     reduction=0.5,
                                     dropout_rate=0.2,
                                     weight_decay=1E-4,
                                     include_top=True,
                                     top='segmentation',
                                     weights=None,
                                     input_tensor=None,
                                     input_shape=input_shape,
                                     classes=classes,
                                     transition_dilation_rate=2,
                                     transition_kernel_size=(1, 1),
                                     transition_pooling=None)

        img_input = Input(shape=(self.height, self.width, self.channels))
        input_shape = _obtain_input_shape(init_img_input,
                                          default_size=32,
                                          min_size=16,
                                          data_format=K.image_data_format(),
                                          include_top=False)
        img_input = Input(shape=input_shape)

        x = densenet.__create_dense_net(classes,
                                        img_input,
                                        depth=None,
                                        nb_dense_block=3,
                                        growth_rate=32,
                                        nb_filter=-1,
                                        nb_layers_per_block=[6, 12, 24, 16],
                                        bottleneck=True,
                                        reduction=0.5,
                                        dropout_rate=0.2,
                                        weight_decay=1E-4,
                                        top='segmentation',
                                        input_shape=input_shape,
                                        transition_dilation_rate=2,
                                        transition_kernel_size=(1, 1),
                                        transition_pooling=None,
                                        include_top=include_top)

        x = self.top(x, input_shape, classes, activation, weight_decay)

        model = Model(img_input, x, name='Atrous_DenseNet')

        return model
Esempio n. 3
0
def Atrous_DenseNet(input_shape=None, weight_decay=1E-4,
                    batch_momentum=0.9, batch_shape=None, classes=21,
                    include_top=False, activation='sigmoid'):
    # TODO(ahundt) pass the parameters but use defaults for now
    if include_top is True:
        # TODO(ahundt) Softmax is pre-applied, so need different train, inference, evaluate.
        # TODO(ahundt) for multi-label try per class sigmoid top as follows:
        # x = Reshape((row * col * classes))(x)
        # x = Activation('sigmoid')(x)
        # x = Reshape((row, col, classes))(x)
        return densenet.DenseNet(depth=None, nb_dense_block=3, growth_rate=32,
                                 nb_filter=-1, nb_layers_per_block=[6, 12, 24, 16],
                                 bottleneck=True, reduction=0.5, dropout_rate=0.2,
                                 weight_decay=1E-4,
                                 include_top=True, top='segmentation',
                                 weights=None, input_tensor=None,
                                 input_shape=input_shape,
                                 classes=classes, transition_dilation_rate=2,
                                 transition_kernel_size=(1, 1),
                                 transition_pooling=None)

    # if batch_shape:
    #     img_input = Input(batch_shape=batch_shape)
    #     image_size = batch_shape[1:3]
    # else:
    #     img_input = Input(shape=input_shape)
    #     image_size = input_shape[0:2]

    input_shape = _obtain_input_shape(input_shape,
                                      default_size=32,
                                      min_size=16,
                                      data_format=K.image_data_format(),
                                      include_top=False)
    img_input = Input(shape=input_shape)

    x = densenet.__create_dense_net(classes, img_input,
                                    depth=None, nb_dense_block=3, growth_rate=32,
                                    nb_filter=-1, nb_layers_per_block=[6, 12, 24, 16],
                                    bottleneck=True, reduction=0.5, dropout_rate=0.2,
                                    weight_decay=1E-4, top='segmentation',
                                    input_shape=input_shape,
                                    transition_dilation_rate=2,
                                    transition_kernel_size=(1, 1),
                                    transition_pooling=None,
                                    include_top=include_top)

    x = top(x, input_shape, classes, activation, weight_decay)

    model = Model(img_input, x, name='Atrous_DenseNet')
    # TODO(ahundt) add weight loading
    return model
Esempio n. 4
0
def Atrous_DenseNet(input_shape=None,
                    weight_decay=0.,
                    batch_momentum=0.9,
                    batch_shape=None,
                    classes=21):
    # TODO(ahundt) pass the parameters but for now start with the well known defaults
    return densenet.DenseNet(depth=202,
                             nb_dense_block=4,
                             growth_rate=32,
                             nb_filter=16,
                             nb_layers_per_block=-1,
                             bottleneck=True,
                             reduction=0.5,
                             dropout_rate=0.2,
                             weight_decay=1E-4,
                             include_top=True,
                             weights=None,
                             input_tensor=None,
                             input_shape=input_shape,
                             classes=classes,
                             dilation_rate=2,
                             pooling=None)