Skip to content

Instantly share code, notes, and snippets.

@naoppy

naoppy/5-04-1.ipynb

Created Mar 8, 2019
Embed
What would you like to do?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.examples.tutorials.mnist import input_data"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Extracting data/train-images-idx3-ubyte.gz\n",
"Extracting data/train-labels-idx1-ubyte.gz\n",
"Extracting data/t10k-images-idx3-ubyte.gz\n",
"Extracting data/t10k-labels-idx1-ubyte.gz\n"
]
}
],
"source": [
"mnist = input_data.read_data_sets(\"data/\", one_hot=True)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"test images: (10000, 784)\n",
"test labels: (10000, 10)\n"
]
}
],
"source": [
"test_images = mnist.test.images\n",
"test_labels = mnist.test.labels\n",
"\n",
"print(\"test images:\", test_images.shape)\n",
"print(\"test labels:\", test_labels.shape)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"learning_rate = 0.5\n",
"training_epochs = 1500\n",
"batch_size = 50"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# 入力層 ニューロン数28*28=784, 行数可変\n",
"x = tf.placeholder(tf.float32, [None, 784], name=\"input_x\")\n",
"# 画像データを28*28にしてログに出力\n",
"img = tf.reshape(x, [-1, 28, 28, 1])\n",
"tf.summary.image(\"input_image\", img, 20)\n",
"\n",
"# 隠れ層 ニューロン数64\n",
"with tf.name_scope(\"hidden1\"):\n",
" # 重み (input 784, output 64)\n",
" w1 = tf.Variable(tf.truncated_normal([784, 64], stddev=0.1), name=\"w1\")\n",
" # バイアス\n",
" b1 = tf.Variable(tf.zeros([64]), name=\"b1\")\n",
" # 活性化関数 ReLU\n",
" h1 = tf.nn.relu(tf.matmul(x, w1) + b1)\n",
"\n",
"# 出力層 ニューロン数10\n",
"with tf.name_scope(\"output\"):\n",
" # 重み input 64, output 10\n",
" w2 = tf.Variable(tf.truncated_normal([64, 10], stddev=0.1), name=\"w2\")\n",
" # バイアス\n",
" b2 = tf.Variable(tf.zeros([10]), name=\"b2\")\n",
" # 活性化関数 softmax\n",
" out = tf.nn.softmax(tf.matmul(h1, w2) + b2)\n",
" \n",
"# 誤差関数\n",
"with tf.name_scope(\"loss\"):\n",
" # 正解ラベルを保持するプレースホルダ―\n",
" t = tf.placeholder(tf.float32, [None, 10], name=\"correct_labels\")\n",
" # 二乗和誤差の平均を損失関数に使う\n",
" loss = tf.reduce_mean(tf.square(t - out))\n",
" # 誤差をログとして出力\n",
" tf.summary.scalar(\"loss\", loss)\n",
" \n",
"# 訓練 ミニマイザー\n",
"with tf.name_scope(\"train\"):\n",
" train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)\n",
" \n",
"# 評価\n",
"with tf.name_scope(\"accuracy\"):\n",
" correct = tf.equal(tf.argmax(out, 1), tf.argmax(t, 1))\n",
" accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))\n",
" tf.summary.scalar(\"accuracy\", accuracy)\n",
"\n",
"init_op = tf.global_variables_initializer()\n",
"# ログのマージ\n",
"summary_op = tf.summary.merge_all()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"epoch:50 accuracy: 0.28\n"
]
},
{
"ename": "InvalidArgumentError",
"evalue": "You must feed a value for placeholder tensor 'input_x' with dtype float and shape [?,784]\n\t [[node input_x (defined at <ipython-input-5-efa1eab084ed>:2) = Placeholder[dtype=DT_FLOAT, shape=[?,784], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"]()]]\n\nCaused by op 'input_x', defined at:\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\runpy.py\", line 193, in _run_module_as_main\n \"__main__\", mod_spec)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel_launcher.py\", line 16, in <module>\n app.launch_new_instance()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\traitlets\\config\\application.py\", line 658, in launch_instance\n app.start()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 505, in start\n self.io_loop.start()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 132, in start\n self.asyncio_loop.run_forever()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\asyncio\\base_events.py\", line 438, in run_forever\n self._run_once()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\asyncio\\base_events.py\", line 1451, in _run_once\n handle._run()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\asyncio\\events.py\", line 145, in _run\n self._callback(*self._args)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\ioloop.py\", line 758, in _run_callback\n ret = callback()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\stack_context.py\", line 300, in null_wrapper\n return fn(*args, **kwargs)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1233, in inner\n self.run()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1147, in run\n yielded = self.gen.send(value)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 370, in dispatch_queue\n yield self.process_one()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 346, in wrapper\n runner = Runner(result, future, yielded)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1080, in __init__\n self.run()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1147, in run\n yielded = self.gen.send(value)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 357, in process_one\n yield gen.maybe_future(dispatch(*args))\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 326, in wrapper\n yielded = next(result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 267, in dispatch_shell\n yield gen.maybe_future(handler(stream, idents, msg))\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 326, in wrapper\n yielded = next(result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 534, in execute_request\n user_expressions, allow_stdin,\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 326, in wrapper\n yielded = next(result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 294, in do_execute\n res = shell.run_cell(code, store_history=store_history, silent=silent)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 536, in run_cell\n return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2843, in run_cell\n raw_cell, store_history, silent, shell_futures)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2869, in _run_cell\n return runner(coro)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\async_helpers.py\", line 67, in _pseudo_sync_runner\n coro.send(None)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3044, in run_cell_async\n interactivity=interactivity, compiler=compiler, result=result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3209, in run_ast_nodes\n if (yield from self.run_code(code, result)):\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3291, in run_code\n exec(code_obj, self.user_global_ns, self.user_ns)\n File \"<ipython-input-5-efa1eab084ed>\", line 2, in <module>\n x = tf.placeholder(tf.float32, [None, 784], name=\"input_x\")\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\ops\\array_ops.py\", line 1747, in placeholder\n return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\ops\\gen_array_ops.py\", line 5205, in placeholder\n \"Placeholder\", dtype=dtype, shape=shape, name=name)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py\", line 787, in _apply_op_helper\n op_def=op_def)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\util\\deprecation.py\", line 488, in new_func\n return func(*args, **kwargs)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 3274, in create_op\n op_def=op_def)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 1770, in __init__\n self._traceback = tf_stack.extract_stack()\n\nInvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input_x' with dtype float and shape [?,784]\n\t [[node input_x (defined at <ipython-input-5-efa1eab084ed>:2) = Placeholder[dtype=DT_FLOAT, shape=[?,784], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"]()]]\n",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mInvalidArgumentError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_call\u001b[1;34m(self, fn, *args)\u001b[0m\n\u001b[0;32m 1333\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1334\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1335\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mOpError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run_fn\u001b[1;34m(feed_dict, fetch_list, target_list, options, run_metadata)\u001b[0m\n\u001b[0;32m 1318\u001b[0m return self._call_tf_sessionrun(\n\u001b[1;32m-> 1319\u001b[1;33m options, feed_dict, fetch_list, target_list, run_metadata)\n\u001b[0m\u001b[0;32m 1320\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_call_tf_sessionrun\u001b[1;34m(self, options, feed_dict, fetch_list, target_list, run_metadata)\u001b[0m\n\u001b[0;32m 1406\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_session\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtarget_list\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1407\u001b[1;33m run_metadata)\n\u001b[0m\u001b[0;32m 1408\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mInvalidArgumentError\u001b[0m: You must feed a value for placeholder tensor 'input_x' with dtype float and shape [?,784]\n\t [[{{node input_x}} = Placeholder[dtype=DT_FLOAT, shape=[?,784], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"]()]]",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[1;31mInvalidArgumentError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-12-3678a541ba4b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"epoch:%d accuracy: %.2f\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mepoch\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0macc_val\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[1;31m# イベントログをsummary_strに代入\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 14\u001b[1;33m \u001b[0msummary_str\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msummary_op\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mtest_images\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mtest_labels\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 15\u001b[0m \u001b[1;31m# イベントファイルにログを追加\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 16\u001b[0m \u001b[0msummary_writer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_summary\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msummary_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mepoch\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(self, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m 927\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 928\u001b[0m result = self._run(None, fetches, feed_dict, options_ptr,\n\u001b[1;32m--> 929\u001b[1;33m run_metadata_ptr)\n\u001b[0m\u001b[0;32m 930\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 931\u001b[0m \u001b[0mproto_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run\u001b[1;34m(self, handle, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m 1150\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mfinal_fetches\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mfinal_targets\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfeed_dict_tensor\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1151\u001b[0m results = self._do_run(handle, final_targets, final_fetches,\n\u001b[1;32m-> 1152\u001b[1;33m feed_dict_tensor, options, run_metadata)\n\u001b[0m\u001b[0;32m 1153\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1154\u001b[0m \u001b[0mresults\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_run\u001b[1;34m(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m 1326\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mhandle\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1327\u001b[0m return self._do_call(_run_fn, feeds, fetches, targets, options,\n\u001b[1;32m-> 1328\u001b[1;33m run_metadata)\n\u001b[0m\u001b[0;32m 1329\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1330\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_prun_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeeds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetches\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_call\u001b[1;34m(self, fn, *args)\u001b[0m\n\u001b[0;32m 1346\u001b[0m \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1347\u001b[0m \u001b[0mmessage\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0merror_interpolation\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minterpolate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_graph\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1348\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnode_def\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1349\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1350\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_extend_graph\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mInvalidArgumentError\u001b[0m: You must feed a value for placeholder tensor 'input_x' with dtype float and shape [?,784]\n\t [[node input_x (defined at <ipython-input-5-efa1eab084ed>:2) = Placeholder[dtype=DT_FLOAT, shape=[?,784], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"]()]]\n\nCaused by op 'input_x', defined at:\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\runpy.py\", line 193, in _run_module_as_main\n \"__main__\", mod_spec)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel_launcher.py\", line 16, in <module>\n app.launch_new_instance()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\traitlets\\config\\application.py\", line 658, in launch_instance\n app.start()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 505, in start\n self.io_loop.start()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 132, in start\n self.asyncio_loop.run_forever()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\asyncio\\base_events.py\", line 438, in run_forever\n self._run_once()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\asyncio\\base_events.py\", line 1451, in _run_once\n handle._run()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\asyncio\\events.py\", line 145, in _run\n self._callback(*self._args)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\ioloop.py\", line 758, in _run_callback\n ret = callback()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\stack_context.py\", line 300, in null_wrapper\n return fn(*args, **kwargs)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1233, in inner\n self.run()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1147, in run\n yielded = self.gen.send(value)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 370, in dispatch_queue\n yield self.process_one()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 346, in wrapper\n runner = Runner(result, future, yielded)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1080, in __init__\n self.run()\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 1147, in run\n yielded = self.gen.send(value)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 357, in process_one\n yield gen.maybe_future(dispatch(*args))\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 326, in wrapper\n yielded = next(result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 267, in dispatch_shell\n yield gen.maybe_future(handler(stream, idents, msg))\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 326, in wrapper\n yielded = next(result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 534, in execute_request\n user_expressions, allow_stdin,\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tornado\\gen.py\", line 326, in wrapper\n yielded = next(result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 294, in do_execute\n res = shell.run_cell(code, store_history=store_history, silent=silent)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 536, in run_cell\n return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2843, in run_cell\n raw_cell, store_history, silent, shell_futures)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2869, in _run_cell\n return runner(coro)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\async_helpers.py\", line 67, in _pseudo_sync_runner\n coro.send(None)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3044, in run_cell_async\n interactivity=interactivity, compiler=compiler, result=result)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3209, in run_ast_nodes\n if (yield from self.run_code(code, result)):\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3291, in run_code\n exec(code_obj, self.user_global_ns, self.user_ns)\n File \"<ipython-input-5-efa1eab084ed>\", line 2, in <module>\n x = tf.placeholder(tf.float32, [None, 784], name=\"input_x\")\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\ops\\array_ops.py\", line 1747, in placeholder\n return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\ops\\gen_array_ops.py\", line 5205, in placeholder\n \"Placeholder\", dtype=dtype, shape=shape, name=name)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py\", line 787, in _apply_op_helper\n op_def=op_def)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\util\\deprecation.py\", line 488, in new_func\n return func(*args, **kwargs)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 3274, in create_op\n op_def=op_def)\n File \"C:\\Users\\naoki\\Anaconda3\\envs\\book1\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 1770, in __init__\n self._traceback = tf_stack.extract_stack()\n\nInvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input_x' with dtype float and shape [?,784]\n\t [[node input_x (defined at <ipython-input-5-efa1eab084ed>:2) = Placeholder[dtype=DT_FLOAT, shape=[?,784], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"]()]]\n"
]
}
],
"source": [
"with tf.Session() as sess:\n",
" summary_writer = tf.summary.FileWriter(\"logs\", sess.graph)\n",
" sess.run(init_op)\n",
" for epoch in range(training_epochs):\n",
" # ミニバッチ抽出\n",
" train_images, train_labels = mnist.train.next_batch(batch_size)\n",
" sess.run(train_step, feed_dict={x:train_images, t:train_labels})\n",
" \n",
" epoch += 1\n",
" if epoch % 50 == 0:\n",
" acc_val = sess.run(accuracy, feed_dict={x:test_images, t:test_labels})\n",
" print(\"epoch:%d accuracy: %.2f\" % (epoch, acc_val))\n",
" # イベントログをsummary_strに代入\n",
" summary_str = sess.run(summary_op, feed_dict={x:test_images, t:test_labels})\n",
" # イベントファイルにログを追加\n",
" summary_writer.add_summary(summary_str, epoch)\n",
" summary_writer.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.