utils.py 960 Bytes
from __future__ import print_function

import sys

from keras.models import Model
from keras.layers import Input, Dense, Dropout, Activation, BatchNormalization


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def initialize_neural_model(number_of_features):
    inputs = Input(shape=(number_of_features,))
    output_from_1st_layer = Dense(1000, activation='relu')(inputs)
    output_from_1st_layer = Dropout(0.5)(output_from_1st_layer)
    output_from_1st_layer = BatchNormalization()(output_from_1st_layer)
    output_from_2nd_layer = Dense(500, activation='relu')(output_from_1st_layer)
    output_from_2nd_layer = Dropout(0.5)(output_from_2nd_layer)
    output_from_2nd_layer = BatchNormalization()(output_from_2nd_layer)
    output = Dense(1, activation='sigmoid')(output_from_2nd_layer)

    model = Model(inputs, output)
    model.compile(optimizer='Adam', loss='binary_crossentropy', metrics=['accuracy'])
    return model