def multi_level_contextual(patch_size, n_channels, nb_classes):# number of convolutional filters to use at each layer nb_filters = [64, 64, 64] # level of pooling to perform at each layer (POOL x POOL) nb_pool = [2, 2, 2] # level of convolution to perform at each layer (CONV x CONV) nb_conv = [5, 5, 5] inputs = Input((patch_size, patch_size, patch_size, n_channels)) c1 = Conv3D(nb_filters[0], (nb_conv[0], nb_conv[0], nb_conv[0]), padding='same', activation='relu', kernel_regularizer=regularizers.l2(0.01))(inputs) c2 = BatchNormalization(epsilon=1e-06, momentum=0.9, weights=None)(c1) c3 = MaxPooling3D(pool_size=(nb_pool[0], nb_pool[0], nb_pool[0]))(c2) c4 = SpatialDropout3D(0.5)(c3) c5 = Conv3D(nb_filters[1],(nb_conv[1], nb_conv[1], nb_conv[1]), padding='same', activation='relu', kernel_regularizer=regularizers.l2(0.01))(c4) c6 = BatchNormalization(epsilon=1e-06, momentum=0.9, weights=None)(c5) c7 = Conv3D(nb_filters[2],(nb_conv[2], nb_conv[2], nb_conv[2]), padding='same', activation='relu', kernel_regularizer=regularizers.l2(0.01))(c6) c8 = BatchNormalization(epsilon=1e-06, momentum=0.9, weights=None)(c7) c9 = SpatialDropout3D(0.5)(c8) c10 = Flatten()(c9) c11 = Dense(256, kernel_initializer='glorot_normal', activation='relu', kernel_regularizer=regularizers.l2(0.01))(c10) c12 = Dense(nb_classes, kernel_initializer='glorot_normal', kernel_regularizer=regularizers.l2(0.01))(c11) c13 = Activation('softmax')(c12) c00 = Cropping3D(cropping=((patch_size//2-patch_size//4, patch_size//2+patch_size//4), (patch_size//2-patch_size//4, patch_size//2+patch_size//4), (patch_size//2-patch_size//4, patch_size//2+patch_size//4)))(inputs) c01 = Conv3D(nb_filters[0], (nb_conv[0], nb_conv[0], nb_conv[0]), padding='same', activation='relu', kernel_regularizer=regularizers.l2(0.01))(c00) c02 = BatchNormalization(epsilon=1e-06, momentum=0.9, weights=None)(c01) c03 = SpatialDropout3D(0.5)(c02) c04 = Conv3D(nb_filters[1],(nb_conv[1], nb_conv[1], nb_conv[1]), padding='same', activation='relu', kernel_regularizer=regularizers.l2(0.01))(c03) c05 = BatchNormalization(epsilon=1e-06, momentum=0.9, weights=None)(c04) c06 = Conv3D(nb_filters[2],(nb_conv[2], nb_conv[2], nb_conv[2]), padding='same', activation='relu', kernel_regularizer=regularizers.l2(0.01))(c05) c07 = BatchNormalization(epsilon=1e-06, momentum=0.9, weights=None)(c06) c08 = SpatialDropout3D(0.5)(c07) c09 = Flatten()(c08) c010 = Dense(128, kernel_initializer='glorot_normal', activation='relu', kernel_regularizer=regularizers.l2(0.01))(c09) c011 = Dense(nb_classes, kernel_initializer='glorot_normal', kernel_regularizer=regularizers.l2(0.01))(c010) c012 = Activation('softmax')(c011) model = Model(inputs=[inputs], outputs=[(c13+c012)/2]) return model