GestaltMatcher

Overcoming the limits of rare disease matching using facial phenotypic descriptors

GestaltMatcher Architecture

Gestaltmatcher architecture
import os
from keras.layers import Dropout, Dense, Flatten, Activation
from keras.layers.convolutional import MaxPooling2D, Conv2D, AveragePooling2D
from keras.layers.normalization import BatchNormalization
from keras.models import Sequential
from keras.initializers import VarianceScaling
from keras.optimizers import SGD, Nadam, Adam
from keras import regularizers
from keras.utils.vis_utils import plot_model
from keras.metrics import top_k_categorical_accuracy

def top_5(y_true, y_pred):
    return top_k_categorical_accuracy(y_true, y_pred,5)

def casia_model(nb_classes, model_weights_path='None'):

    initializer='he_normal'
    kernel_regularizer=None

    model = Sequential()
    model.add(Conv2D(32, kernel_size=3, strides=1, padding='same',input_shape=(100, 100, 1), kernel_initializer=initializer,
                     kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(Conv2D(64, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2), padding='valid'))

    model.add(Conv2D(64, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(Conv2D(128, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2), padding='valid'))

    model.add(Conv2D(96, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(Conv2D(192, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2), padding='same'))

    model.add(Conv2D(128, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(Conv2D(256, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2), padding='same'))

    model.add(Conv2D(160, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(BatchNormalization())
    model.add(Activation('relu'))

    model.add(Conv2D(320, kernel_size=3, strides=1, padding='same',kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(AveragePooling2D(pool_size=(7, 7), strides=(1, 1), padding='valid'))

    model.add(Dropout(0.5))
    model.add(Flatten())

    model.add(Dense(nb_classes ,kernel_initializer=initializer, kernel_regularizer=kernel_regularizer))
    model.add(Activation('softmax'))

    adam = Adam()

    if os.path.exists(model_weights_path):
        model.load_weights(model_weights_path)

    model.compile(loss='categorical_crossentropy', optimizer=adam, metrics=['accuracy', top_5])

    model.summary()
    return model

if __name__ == "__main__":


    casia = casia_model(296)

    #print(casia.summary())
    plot_model(casia, to_file="casia.png", show_shapes=True)