diff --git a/04_modern_net.ipynb b/04_modern_net.ipynb index bcabb07..c1cff59 100644 --- a/04_modern_net.ipynb +++ b/04_modern_net.ipynb @@ -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" @@ -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", @@ -66,9 +68,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Launch the graph in a session\n", @@ -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 }