Created
June 12, 2017 16:04
-
-
Save Yvictor/926aff38d70432aff4050e04b2e9ed10 to your computer and use it in GitHub Desktop.
keras model example
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
from keras.layers import Convolution2D, MaxPooling2D, Dense, Dropout, Activation, Flatten, Input | |
from keras.models import Model | |
from keras.optimizers import RMSprop | |
batchsize = 64 | |
conv_num_filters_1 = 16 | |
conv_num_filters_2 = 32 | |
conv_num_filters_3 = 32 | |
filter_size = 4 | |
pool_size_1 = 4 | |
pool_size_2 = 4 | |
pool_size_3 = 4 | |
dp_rate = 0.5 | |
fc_unit1 = 128 | |
fc_unit2 = 64 | |
out_class = 3 | |
padd = 'valid' | |
activation_func = 'relu' | |
input_data = Input(shape=(1, obs_size, len(features_name)), name='the_input', dtype='float32') | |
inner = Convolution2D(conv_num_filters_1, kernel_size=(1, filter_size), | |
padding=padd, activation=activation_func, name='conv1')(input_data) | |
inner = Convolution2D(conv_num_filters_1, kernel_size=(1, filter_size), | |
padding=padd, activation=activation_func, name='conv1_2')(inner) | |
inner = MaxPooling2D(pool_size=(1, pool_size_1), name='max1')(inner) | |
inner = Dropout(dp_rate, name='dropout1')(inner) | |
inner = Convolution2D(conv_num_filters_2, kernel_size=(1, filter_size), | |
padding=padd, activation=activation_func, name='conv2')(inner) | |
inner = Convolution2D(conv_num_filters_2, kernel_size=(1, filter_size), | |
padding=padd, activation=activation_func, name='conv2_2')(inner) | |
inner = MaxPooling2D(pool_size=(1, pool_size_2), name='max2')(inner) | |
inner = Dropout(dp_rate, name='dropout2')(inner) | |
inner = Convolution2D(conv_num_filters_3, kernel_size=(1, filter_size), | |
padding=padd, activation=activation_func, name='conv3')(inner) | |
inner = Convolution2D(conv_num_filters_3, kernel_size=(1, filter_size), | |
padding=padd, activation=activation_func, name='conv3_2')(inner) | |
inner = MaxPooling2D(pool_size=(1, pool_size_3), name='max3')(inner) | |
inner = Dropout(dp_rate, name='dropout3')(inner) | |
inner = Flatten(name='flatten')(inner) | |
inner = Dense(fc_unit1, activation='relu', name='FC1')(inner) | |
inner = Dropout(dp_rate, name='dropoutfc')(inner) | |
y_pred = Dense(out_class, activation='softmax', name='FC2')(inner) | |
model = Model(inputs=[input_data], outputs=[y_pred]) | |
model.summary() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment