Created
April 11, 2019 03:57
-
-
Save crawftv/b11186383af17c79f12dc137155b7e88 to your computer and use it in GitHub Desktop.
Skopt Tutorial - Model Creator
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.optimizers import Adam | |
def create_model(learning_rate, num_dense_layers,num_input_nodes, | |
num_dense_nodes, activation, adam_decay): | |
#start the model making process and create our first layer | |
model = Sequential() | |
model.add(Dense(num_input_nodes, input_shape= input_shape, activation=activation | |
)) | |
#create a loop making a new dense layer for the amount passed to this model. | |
#naming the layers helps avoid tensorflow error deep in the stack trace. | |
for i in range(num_dense_layers): | |
name = 'layer_dense_{0}'.format(i+1) | |
model.add(Dense(num_dense_nodes, | |
activation=activation, | |
name=name | |
)) | |
#add our classification layer. | |
model.add(Dense(10,activation='softmax')) | |
#setup our optimizer and compile | |
adam = Adam(lr=learning_rate, decay= adam_decay) | |
model.compile(optimizer=adam, loss='categorical_crossentropy', | |
metrics=['accuracy']) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment