Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions 04_modern_net.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"def init_weights(shape):\n",
" return tf.Variable(tf.random_normal(shape, stddev=0.01))\n",
"\n",
"def model(X, w_h, w_h2, w_o, p_keep_input, p_keep_hidden): # this network is the same as the previous one except with an extra hidden layer + dropout\n",
" X = tf.nn.dropout(X, p_keep_input)\n",
" h = tf.nn.relu(tf.matmul(X, w_h))\n",
"def init_biases(shape):\n",
" return tf.Variable(tf.zeros(shape))\n",
"\n",
"def model(X, w_h, b_h, w_h2, b_h2, w_o, b_o, p_keep_input, p_keep_hidden): # this network is the same as the previous one except with an extra hidden layer + dropout\n",
" X = tf.nn.dropout(X, p_keep_input)\n",
" h = tf.nn.relu(tf.matmul(X, w_h)) + b_h\n",
" \n",
" h = tf.nn.dropout(h, p_keep_hidden)\n",
" h2 = tf.nn.relu(tf.matmul(h, w_h2))\n",
" h2 = tf.nn.relu(tf.matmul(h, w_h2)) + b_h2\n",
"\n",
" h2 = tf.nn.dropout(h2, p_keep_hidden)\n",
"\n",
" return tf.matmul(h2, w_o)\n",
" return tf.matmul(h2, w_o) + b_o\n",
"\n",
"mnist = input_data.read_data_sets(\"MNIST_data/\", one_hot=True)\n",
"trX, trY, teX, teY = mnist.train.images, mnist.train.labels, mnist.test.images, mnist.test.labels"
Expand All @@ -42,21 +43,22 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"X = tf.placeholder(\"float\", [None, 784])\n",
"Y = tf.placeholder(\"float\", [None, 10])\n",
"\n",
"w_h = init_weights([784, 625])\n",
"b_h = init_biases([625])\n",
"w_h2 = init_weights([625, 625])\n",
"b_h2 = init_biases([625])\n",
"w_o = init_weights([625, 10])\n",
"b_o = init_biases([10])\n",
"\n",
"p_keep_input = tf.placeholder(\"float\")\n",
"p_keep_hidden = tf.placeholder(\"float\")\n",
"py_x = model(X, w_h, w_h2, w_o, p_keep_input, p_keep_hidden)\n",
"py_x = model(X, w_h, b_h, w_h2, b_h2, w_o, b_o, p_keep_input, p_keep_hidden)\n",
"\n",
"cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=py_x, labels=Y))\n",
"train_op = tf.train.RMSPropOptimizer(0.001, 0.9).minimize(cost)\n",
Expand All @@ -66,9 +68,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# Launch the graph in a session\n",
Expand Down Expand Up @@ -105,16 +105,16 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}