Skip to content

Instantly share code, notes, and snippets.

@MattChanTK
Last active November 8, 2016 17:45
Show Gist options
  • Select an option

  • Save MattChanTK/fc7f9e3fffece3ec4a23b9c74ad39848 to your computer and use it in GitHub Desktop.

Select an option

Save MattChanTK/fc7f9e3fffece3ec4a23b9c74ad39848 to your computer and use it in GitHub Desktop.
'''
---------------------------------------------
Constructing the Convolutional Neural Network
---------------------------------------------
'''
def create_convolutional_neural_network(input_vars, out_dims, dropout_prob=0.0):
convolutional_layer_1 = Convolution((5, 5), 32, strides=1, activation=cntk.ops.relu, pad=True)(input_vars)
pooling_layer_1 = MaxPooling((2, 2), strides=(2, 2), pad=True)(convolutional_layer_1)
convolutional_layer_2 = Convolution((5, 5), 64, strides=1, activation=cntk.ops.relu, pad=True)(pooling_layer_1)
pooling_layer_2 = MaxPooling((2, 2), strides=(2, 2), pad=True)(convolutional_layer_2)
fully_connected_layer = Dense(1024, activation=cntk.ops.relu)(pooling_layer_2)
dropout_layer = Dropout(dropout_prob)(fully_connected_layer)
output_layer = Dense(out_dims, activation=None)(dropout_layer)
return output_layer
# Define the input to the neural network
input_vars = cntk.ops.input_variable(image_shape, np.float32)
# Create the convolutional neural network
output = create_convolutional_neural_network(input_vars, output_dim, dropout_prob=0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment