-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path29-1 MNIST comparison in major NN frameworks
1 lines (1 loc) · 2.21 KB
/
29-1 MNIST comparison in major NN frameworks
1
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"29-1 MNIST comparison in major NN frameworks ","provenance":[],"collapsed_sections":[],"authorship_tag":"ABX9TyM/li/1lR6P5c7XKlm0o7u8"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"code","metadata":{"id":"Fd8G0gq8fcw-"},"source":["# MNIST comparison in major NN frameworks\n","# author: Gressling, T\n","# license: MIT License # code: github.com/gressling/examples\n","# activity: single example # index: 29-1 "],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"8gCp3vwtfikf"},"source":["# Keras\n","model = Sequential()\n"," model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_\n"," shape=input_shape))\n"," model.add(Conv2D(64, (3, 3), activation='relu'))\n"," model.add(MaxPooling2D(pool_size=(2, 2)))\n"," model.add(Dropout(0.25))\n"," model.add(Flatten())\n"," model.add(Dense(128, activation='relu'))\n"," model.add(Dropout(0.5))\n"," model.add(Dense(num_classes, activation='softmax'))"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"vFNkQRQ0fmPe"},"source":["# pytorch\n","super(Net, self).__init__()\n"," self.conv1 = nn.Conv2d(1, 32, 3, 1)\n"," self.conv2 = nn.Conv2d(32, 64, 3, 1)\n"," self.dropout1 = nn.Dropout2d(0.25)\n"," self.dropout2 = nn.Dropout2d(0.5)\n"," self.fc1 = nn.Linear(9216, 128)\n"," self.fc2 = nn.Linear(128, 10)"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"WRj0QKbhfoPW"},"source":["# Theano\n","def net(batch_size, width, height, channels):\n"," l_input = L.InputLayer(shape=(batch_size, width, height, channels), name='input')\n"," l_conv_1 = L.Conv2DLayer(l_input, num_filters=20, filter_size=(5,5), name='conv1')\n"," l_pool_1 = L.MaxPool2DLayer(l_conv_1, pool_size=(2,2), name='pool1')\n"," l_conv_2 = L.Conv2DLayer(l_pool_1, num_filters=50, filter_size=(5,5), name='conv2')\n"," l_pool_2 = L.MaxPool2DLayer(l_conv_2, pool_size=(2,2), name='pool2')\n"," l_flatten = L.FlattenLayer(l_pool_2, name='flatten')\n"," l_dense_1 = L.DenseLayer(l_flatten, num_units=500, name='dense1')\n"," l_dense_2 = L.DenseLayer(l_dense_1, num_units=10, name='dense2', nonlinearity=softmax)\n"," return l_dense_2"],"execution_count":null,"outputs":[]}]}