{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2017-12-29T13:29:18.441562Z", "start_time": "2017-12-29T13:29:16.950744Z" }, "collapsed": true }, "outputs": [], "source": [ "import tensorflow as tf" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:37:39.581799Z", "start_time": "2017-12-24T02:37:39.578525Z" }, "collapsed": true }, "outputs": [], "source": [ "hello = tf.constant(\"Hi\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:37:41.820876Z", "start_time": "2017-12-24T02:37:41.816679Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tensor(\"Const:0\", shape=(), dtype=string)\n" ] } ], "source": [ "print(hello)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:38:11.259967Z", "start_time": "2017-12-24T02:38:11.257750Z" }, "collapsed": true }, "outputs": [], "source": [ "# Tensor : 자료형" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:38:30.780135Z", "start_time": "2017-12-24T02:38:30.744754Z" }, "collapsed": true }, "outputs": [], "source": [ "a = tf.constant(10)\n", "b = tf.constant(2)\n", "c = a + b" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:38:32.288780Z", "start_time": "2017-12-24T02:38:32.285798Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tensor(\"add:0\", shape=(), dtype=int32)\n" ] } ], "source": [ "print(c)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:39:00.510883Z", "start_time": "2017-12-24T02:39:00.507996Z" }, "collapsed": true }, "outputs": [], "source": [ "# 텐서플로우는 그래프 생성 후, 그래프 실행하는 과정을 거쳐야 함. 지연 실행 방법을 사용" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:39:28.062189Z", "start_time": "2017-12-24T02:39:28.044938Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12\n" ] } ], "source": [ "sess = tf.Session()\n", "print(sess.run(c))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:39:51.367977Z", "start_time": "2017-12-24T02:39:51.364098Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "b'Hi'\n" ] } ], "source": [ "print(sess.run(hello))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:40:00.117899Z", "start_time": "2017-12-24T02:40:00.114885Z" }, "collapsed": true }, "outputs": [], "source": [ "sess.close()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:40:20.044739Z", "start_time": "2017-12-24T02:40:20.042220Z" }, "collapsed": true }, "outputs": [], "source": [ "# 플레이스홀더는 매개변수" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:40:34.345655Z", "start_time": "2017-12-24T02:40:34.340413Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tensor(\"Placeholder_1:0\", shape=(?, 3), dtype=float32)\n" ] } ], "source": [ "X = tf.placeholder(tf.float32, [None, 3])\n", "print(X)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:40:52.230352Z", "start_time": "2017-12-24T02:40:52.227617Z" }, "collapsed": true }, "outputs": [], "source": [ "x_data = [[1,2,3], [4,5,6]]\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:41:15.656000Z", "start_time": "2017-12-24T02:41:15.628670Z" }, "collapsed": true }, "outputs": [], "source": [ "W = tf.Variable(tf.random_normal([3,2]))\n", "b = tf.Variable(tf.random_normal([2,1]))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:41:34.455607Z", "start_time": "2017-12-24T02:41:34.449990Z" }, "collapsed": true }, "outputs": [], "source": [ "expr = tf.matmul(X,W) + b" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T02:46:54.518403Z", "start_time": "2017-12-24T02:46:54.489821Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[1, 2, 3], [4, 5, 6]]\n", "[[-0.72649789 -0.31295726]\n", " [ 1.18099403 -0.71925688]\n", " [-1.98263812 -2.10048032]]\n", "[[-1.28041577]\n", " [-1.60697615]]\n", "[[ -5.59283924 -9.33332729]\n", " [-10.50382614 -19.05797195]]\n" ] } ], "source": [ "sess = tf.Session()\n", "sess.run(tf.global_variables_initializer())\n", "print(x_data)\n", "print(sess.run(W))\n", "print(sess.run(b))\n", "print(sess.run(expr, feed_dict={X: x_data}))\n", "# feed_dict : 그래프 실행할 때 사용할 입력값을 지정\n", "sess.close()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:16:46.957693Z", "start_time": "2017-12-24T07:16:46.946043Z" } }, "outputs": [ { "data": { "text/plain": [ "[[1, 2, 3], [4, 5, 6]]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x_data" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:18:04.340933Z", "start_time": "2017-12-24T07:18:04.338050Z" }, "collapsed": true }, "outputs": [], "source": [ "x_data = [1, 2, 3]\n", "y_data = [1, 2, 3]" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:18:25.429205Z", "start_time": "2017-12-24T07:18:25.408288Z" }, "collapsed": true }, "outputs": [], "source": [ "W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:18:31.448685Z", "start_time": "2017-12-24T07:18:31.406441Z" }, "collapsed": true }, "outputs": [], "source": [ "# tf.random_uniform(shape, minval=0, maxval=None, dtype=tf.float32, seed=None, name=None)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:19:00.813435Z", "start_time": "2017-12-24T07:19:00.800318Z" }, "collapsed": true }, "outputs": [], "source": [ "b = tf.Variable(tf.random_uniform([1], -1.0, 1.0))" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:19:18.242910Z", "start_time": "2017-12-24T07:19:18.238541Z" }, "collapsed": true }, "outputs": [], "source": [ "X = tf.placeholder(tf.float32, name=\"X\")" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:19:32.541627Z", "start_time": "2017-12-24T07:19:32.537866Z" }, "collapsed": true }, "outputs": [], "source": [ "Y = tf.placeholder(tf.float32, name=\"Y\")" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:19:50.893692Z", "start_time": "2017-12-24T07:19:50.888670Z" }, "collapsed": true }, "outputs": [], "source": [ "hypothesis = W*X +b" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:21:29.689819Z", "start_time": "2017-12-24T07:21:29.673323Z" }, "collapsed": true }, "outputs": [], "source": [ "cost = tf.reduce_mean(tf.square(hypothesis-Y))" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:21:45.954127Z", "start_time": "2017-12-24T07:21:45.951823Z" }, "collapsed": true }, "outputs": [], "source": [ "optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.1)" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:21:52.809645Z", "start_time": "2017-12-24T07:21:52.720765Z" }, "collapsed": true }, "outputs": [], "source": [ "train_op = optimizer.minimize(cost)" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:24:51.987019Z", "start_time": "2017-12-24T07:24:51.908823Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 23.2728 [ 1.17120934] [ 0.16678452]\n", "1 0.27883 [ 0.94470012] [ 0.06494389]\n", "2 0.00412319 [ 0.97033584] [ 0.07407507]\n", "3 0.00080411 [ 0.96839243] [ 0.07112574]\n", "4 0.0007286 [ 0.96944255] [ 0.06954362]\n", "5 0.000693551 [ 0.9701454] [ 0.06785788]\n", "6 0.000660599 [ 0.97086656] [ 0.06622814]\n", "7 0.000629222 [ 0.97156656] [ 0.06463589]\n", "8 0.000599332 [ 0.97225004] [ 0.06308208]\n", "9 0.000570862 [ 0.9729172] [ 0.06156565]\n", "X: 5, Y: [ 4.92615175]\n", "X: 5, Y: [ 2.49385858]\n" ] } ], "source": [ "with tf.Session() as sess:\n", " sess.run(tf.global_variables_initializer())\n", " \n", " for step in range(10):\n", " _, cost_val = sess.run([train_op, cost], feed_dict={X:x_data, Y: y_data})\n", " \n", " print(step, cost_val, sess.run(W), sess.run(b))\n", " \n", " print(\"X: 5, Y:\", sess.run(hypothesis, feed_dict={X:5}))\n", " print(\"X: 5, Y:\", sess.run(hypothesis, feed_dict={X:2.5}))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 4. 기본 신경망 구현" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:56:41.624966Z", "start_time": "2017-12-24T07:56:41.622011Z" }, "collapsed": true }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:57:15.483669Z", "start_time": "2017-12-24T07:57:15.480451Z" }, "collapsed": true }, "outputs": [], "source": [ "x_data = np.array([[0,0], [1,0], [1,1], [0,0], [0,0], [0,1]])" ] }, { "cell_type": "code", "execution_count": 45, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:57:54.665816Z", "start_time": "2017-12-24T07:57:54.661667Z" }, "collapsed": true }, "outputs": [], "source": [ "y_data = np.array([\n", " [1, 0, 0],\n", " [0, 1, 0],\n", " [0, 0, 1],\n", " [1, 0, 0],\n", " [1, 0, 0],\n", " [0, 0, 1]\n", "])" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:58:04.455825Z", "start_time": "2017-12-24T07:58:04.452180Z" }, "collapsed": true }, "outputs": [], "source": [ "X = tf.placeholder(tf.float32)" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T07:58:11.937530Z", "start_time": "2017-12-24T07:58:11.933891Z" }, "collapsed": true }, "outputs": [], "source": [ "Y = tf.placeholder(tf.float32)" ] }, { "cell_type": "code", "execution_count": 69, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:17:11.915085Z", "start_time": "2017-12-24T08:17:11.890232Z" }, "collapsed": true }, "outputs": [], "source": [ "W1 = tf.Variable(tf.random_uniform([2, 10], -1., 1.))\n", "W2 = tf.Variable(tf.random_uniform([10, 3], -1., 1.))" ] }, { "cell_type": "code", "execution_count": 70, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:17:38.682262Z", "start_time": "2017-12-24T08:17:38.669939Z" }, "collapsed": true }, "outputs": [], "source": [ "b1 = tf.Variable(tf.zeros([10]))\n", "b2 = tf.Variable(tf.zeros([3]))" ] }, { "cell_type": "code", "execution_count": 73, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:18:08.877724Z", "start_time": "2017-12-24T08:18:08.869938Z" }, "collapsed": true }, "outputs": [], "source": [ "L1 = tf.add(tf.matmul(X, W1), b1)" ] }, { "cell_type": "code", "execution_count": 74, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:18:09.064500Z", "start_time": "2017-12-24T08:18:09.059366Z" }, "collapsed": true }, "outputs": [], "source": [ "L1 = tf.nn.relu(L1)" ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:18:29.268605Z", "start_time": "2017-12-24T08:18:29.263493Z" }, "collapsed": true }, "outputs": [], "source": [ "model = tf.add(tf.matmul(L1, W2), b2)" ] }, { "cell_type": "code", "execution_count": 77, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:18:55.909709Z", "start_time": "2017-12-24T08:18:55.874844Z" }, "collapsed": true }, "outputs": [], "source": [ "cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=Y, logits=model))" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:29:47.269789Z", "start_time": "2017-12-24T08:29:47.137430Z" }, "collapsed": true }, "outputs": [], "source": [ "# optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)\n", "optimizer = tf.train.AdamOptimizer(learning_rate=0.01)\n", "train_op = optimizer.minimize(cost)" ] }, { "cell_type": "code", "execution_count": 83, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T08:29:47.681279Z", "start_time": "2017-12-24T08:29:47.361726Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10 0.820693\n", "20 0.639553\n", "30 0.514824\n", "40 0.417581\n", "50 0.332758\n", "60 0.256476\n", "70 0.190775\n", "80 0.138239\n", "90 0.0994742\n", "100 0.0724157\n", "예측값: [0 1 2 0 0 2]\n", "실제값: [0 1 2 0 0 2]\n", "정확도: 100.00\n" ] } ], "source": [ "init = tf.global_variables_initializer()\n", "sess = tf.Session()\n", "sess.run(init)\n", "\n", "for step in range(100):\n", " sess.run(train_op, feed_dict={X:x_data, Y:y_data})\n", " \n", " if (step+1)%10 == 0:\n", " print(step+1, sess.run(cost, feed_dict={X:x_data, Y:y_data}))\n", " \n", "prediction = tf.argmax(model, axis=1)\n", "target = tf.argmax(Y, axis=1)\n", "print(\"예측값: \", sess.run(prediction, feed_dict={X:x_data}))\n", "print(\"실제값: \", sess.run(target, feed_dict={Y:y_data}))\n", "\n", "is_correct = tf.equal(prediction, target)\n", "accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32))\n", "print(\"정확도: {:.2f}\".format(sess.run(accuracy*100, feed_dict={X: x_data, Y:y_data})))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 5. 텐서보드와 모델 재사용" ] }, { "cell_type": "code", "execution_count": 116, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T09:47:03.837671Z", "start_time": "2017-12-24T09:47:03.832662Z" }, "collapsed": true }, "outputs": [], "source": [ "data = np.loadtxt(\"./sample_data.csv\", delimiter=',', unpack=True, dtype='float32')\n", "\n", "x_data = np.transpose(data[0:2])\n", "y_data = np.transpose(data[2:])" ] }, { "cell_type": "code", "execution_count": 117, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T09:47:04.428352Z", "start_time": "2017-12-24T09:47:04.423558Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[ 0., 1., 1., 0., 0., 0.],\n", " [ 0., 0., 1., 0., 0., 1.],\n", " [ 1., 0., 0., 1., 1., 0.],\n", " [ 0., 1., 0., 0., 0., 0.],\n", " [ 0., 0., 1., 0., 0., 1.]], dtype=float32)" ] }, "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "code", "execution_count": 119, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T10:02:35.214951Z", "start_time": "2017-12-24T10:02:30.860765Z" }, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Step: 1 Cost: 1.152\n", "Step: 2 Cost: 1.045\n", "예측값: [0 1 1 0 0 2]\n", "실제값: [0 1 2 0 0 2]\n", "정확도: 83.33\n" ] } ], "source": [ "# tf.reset_default_graph()\n", "global_step = tf.Variable(0, trainable=False, name='global_step')\n", "\n", "X = tf.placeholder(tf.float32)\n", "Y = tf.placeholder(tf.float32)\n", "\n", "with tf.name_scope('layer1'):\n", " W1 = tf.Variable(tf.random_uniform([2, 10], -1., 1.), name='W1')\n", " L1 = tf.nn.relu(tf.matmul(X, W1))\n", "\n", "with tf.name_scope('layer2'):\n", " W2 = tf.Variable(tf.random_uniform([10, 20], -1., 1.), name='W2')\n", " L2 = tf.nn.relu(tf.matmul(L1, W2))\n", "\n", "with tf.name_scope('output'):\n", " W3 = tf.Variable(tf.random_uniform([20, 3], -1., 1.), name='W3')\n", " model = tf.matmul(L2, W3)\n", "\n", "with tf.name_scope('optimizer'):\n", " cost = tf.reduce_mean(\n", " tf.nn.softmax_cross_entropy_with_logits(labels=Y, logits=model))\n", "\n", " optimizer = tf.train.AdamOptimizer(learning_rate=0.01)\n", " # global_step로 넘겨준 변수를, 학습용 변수들을 최적화 할 때 마다 학습 횟수를 하나씩 증가시킵니다.\n", " train_op = optimizer.minimize(cost, global_step=global_step)\n", " \n", " # 손실값을 추적하기 위해 수집할 값을 지정\n", " tf.summary.scalar('cost', cost)\n", "\n", "sess = tf.Session()\n", "# 모델을 저장하고 불러오는 API를 초기화합니다.\n", "# global_variables 함수를 통해 앞서 정의하였던 변수들을 저장하거나 불러올 변수들로 설정합니다.\n", "saver = tf.train.Saver(tf.global_variables())\n", "\n", "ckpt = tf.train.get_checkpoint_state('./model')\n", "if ckpt and tf.train.checkpoint_exists(ckpt.model_checkpoint_path):\n", " saver.restore(sess, ckpt.model_checkpoint_path)\n", "else:\n", " sess.run(tf.global_variables_initializer())\n", "\n", "merged = tf.summary.merge_all()\n", "# 앞서 지정한 텐서들을 수집\n", "writer = tf.summary.FileWriter('./logs', sess.graph)\n", "# 그래프와 텐서들의 값을 저장할 디렉터리 설정\n", "# 최적화 진행\n", "for step in range(2):\n", " sess.run(train_op, feed_dict={X: x_data, Y: y_data})\n", " \n", " print(\"Step: {}\".format(sess.run(global_step)),\n", " \"Cost: {:.3f}\".format(sess.run(cost, feed_dict={X: x_data, Y: y_data})))\n", " \n", " summary = sess.run(merged, feed_dict={X: x_data, Y: y_data})\n", " writer.add_summary(summary, global_step=sess.run(global_step))\n", " \n", "saver.save(sess, './model/dnn.ckpt', global_step=global_step)\n", "# 결과 확인\n", "# 0: 기타 1: 포유류, 2: 조류\n", "######\n", "prediction = tf.argmax(model, 1)\n", "target = tf.argmax(Y, 1)\n", "print('예측값:', sess.run(prediction, feed_dict={X: x_data}))\n", "print('실제값:', sess.run(target, feed_dict={Y: y_data}))\n", "\n", "is_correct = tf.equal(prediction, target)\n", "accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32))\n", "print('정확도: {:.2f}'.format(sess.run(accuracy * 100, feed_dict={X: x_data, Y: y_data})))" ] }, { "cell_type": "code", "execution_count": 95, "metadata": { "ExecuteTime": { "end_time": "2017-12-24T09:01:01.312004Z", "start_time": "2017-12-24T09:01:01.309492Z" }, "collapsed": true }, "outputs": [], "source": [ "# tf.Variable(initial_value=None, trainable=True, collections=None, validate_shape=True, \n", "# caching_device=None, name=None, variable_def=None, dtype=None, expected_shape=None, import_scope=None)" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2017-12-24T09:19:27.666510Z", "start_time": "2017-12-24T09:19:27.548931Z" } }, "source": [ "[텐서플로 서빙 홈페이지](https://tensorflow.github.io/serving/)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2017-12-29T13:29:48.862743Z", "start_time": "2017-12-29T13:29:39.247823Z" }, "collapsed": true }, "outputs": [], "source": [ "from tensorflow.examples.tutorials.mnist import input_data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2017-12-29T13:30:04.407882Z", "start_time": "2017-12-29T13:29:59.047791Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.\n", "Extracting ./mnist/data/train-images-idx3-ubyte.gz\n", "Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.\n", "Extracting ./mnist/data/train-labels-idx1-ubyte.gz\n", "Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.\n", "Extracting ./mnist/data/t10k-images-idx3-ubyte.gz\n", "Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.\n", "Extracting ./mnist/data/t10k-labels-idx1-ubyte.gz\n" ] } ], "source": [ "mnist = input_data.read_data_sets(\"./mnist/data/\", one_hot=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2017-12-29T13:30:35.398442Z", "start_time": "2017-12-29T13:30:35.386656Z" }, "collapsed": true }, "outputs": [], "source": [ "X = tf.placeholder(tf.float32, [None, 784])\n", "Y = tf.placeholder(tf.float32, [None, 10])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "W1 = tf.Variable(tf.random_normal([784]))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }