|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "** 너무 오래걸려서 패스.... **\n", |
| 8 | + "\n", |
| 9 | + "gpu는 그냥 6~7초안에 끝나는데 얘는 무슨 몇분씩걸린다." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": 2, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [ |
| 17 | + { |
| 18 | + "name": "stdout", |
| 19 | + "output_type": "stream", |
| 20 | + "text": [ |
| 21 | + "x_train shape: (60000, 28, 28, 1)\n", |
| 22 | + "60000 train samples\n", |
| 23 | + "10000 test samples\n", |
| 24 | + "Train on 60000 samples, validate on 10000 samples\n", |
| 25 | + "Epoch 1/12\n", |
| 26 | + " 384/60000 [..............................] - ETA: 27:43 - loss: 2.2585 - acc: 0.1380" |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "ename": "KeyboardInterrupt", |
| 31 | + "evalue": "", |
| 32 | + "output_type": "error", |
| 33 | + "traceback": [ |
| 34 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 35 | + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", |
| 36 | + "\u001b[1;32m<ipython-input-2-b9f0df44fa12>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 68\u001b[0m \u001b[0mepochs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mepochs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 69\u001b[0m \u001b[0mverbose\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 70\u001b[1;33m validation_data=(x_test, y_test))\n\u001b[0m\u001b[0;32m 71\u001b[0m \u001b[0mscore\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mevaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx_test\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_test\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 72\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Test loss:'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscore\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
| 37 | + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)\u001b[0m\n\u001b[0;32m 1040\u001b[0m \u001b[0minitial_epoch\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0minitial_epoch\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1041\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msteps_per_epoch\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1042\u001b[1;33m validation_steps=validation_steps)\n\u001b[0m\u001b[0;32m 1043\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1044\u001b[0m def evaluate(self, x=None, y=None,\n", |
| 38 | + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\engine\\training_arrays.py\u001b[0m in \u001b[0;36mfit_loop\u001b[1;34m(model, f, ins, out_labels, batch_size, epochs, verbose, callbacks, val_f, val_ins, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps)\u001b[0m\n\u001b[0;32m 197\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtoarray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 198\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 199\u001b[1;33m \u001b[0mouts\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mins_batch\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 200\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mouts\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 201\u001b[0m \u001b[0mouts\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mouts\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
| 39 | + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, inputs)\u001b[0m\n\u001b[0;32m 2659\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_legacy_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2660\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2661\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2662\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2663\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mpy_any\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mis_tensor\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0minputs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
| 40 | + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py\u001b[0m in \u001b[0;36m_call\u001b[1;34m(self, inputs)\u001b[0m\n\u001b[0;32m 2629\u001b[0m \u001b[0msymbol_vals\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2630\u001b[0m session)\n\u001b[1;32m-> 2631\u001b[1;33m \u001b[0mfetched\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_callable_fn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0marray_vals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2632\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mfetched\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moutputs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2633\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", |
| 41 | + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, *args)\u001b[0m\n\u001b[0;32m 1449\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_session\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_created_with_new_api\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1450\u001b[0m return tf_session.TF_SessionRunCallable(\n\u001b[1;32m-> 1451\u001b[1;33m self._session._session, self._handle, args, status, None)\n\u001b[0m\u001b[0;32m 1452\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1453\u001b[0m return tf_session.TF_DeprecatedSessionRunCallable(\n", |
| 42 | + "\u001b[1;31mKeyboardInterrupt\u001b[0m: " |
| 43 | + ] |
| 44 | + } |
| 45 | + ], |
| 46 | + "source": [ |
| 47 | + "import keras\n", |
| 48 | + "from keras.datasets import mnist\n", |
| 49 | + "from keras.models import Sequential\n", |
| 50 | + "from keras.layers import Dense, Dropout, Flatten\n", |
| 51 | + "from keras.layers import Conv2D, MaxPooling2D\n", |
| 52 | + "import keras.backend.tensorflow_backend as kk\n", |
| 53 | + "from keras import backend as K\n", |
| 54 | + "'''\n", |
| 55 | + "cpu테스트\n", |
| 56 | + "정말 오래걸린다.\n", |
| 57 | + "'''\n", |
| 58 | + "batch_size = 128\n", |
| 59 | + "num_classes = 10\n", |
| 60 | + "epochs = 12\n", |
| 61 | + "\n", |
| 62 | + "# input image dimensions\n", |
| 63 | + "img_rows, img_cols = 28, 28\n", |
| 64 | + "\n", |
| 65 | + "# the data, split between train and test sets\n", |
| 66 | + "(x_train, y_train), (x_test, y_test) = mnist.load_data()\n", |
| 67 | + "\n", |
| 68 | + "if K.image_data_format() == 'channels_first':\n", |
| 69 | + " x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)\n", |
| 70 | + " x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)\n", |
| 71 | + " input_shape = (1, img_rows, img_cols)\n", |
| 72 | + "else:\n", |
| 73 | + " x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)\n", |
| 74 | + " x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)\n", |
| 75 | + " input_shape = (img_rows, img_cols, 1)\n", |
| 76 | + "\n", |
| 77 | + "x_train = x_train.astype('float32')\n", |
| 78 | + "x_test = x_test.astype('float32')\n", |
| 79 | + "x_train /= 255\n", |
| 80 | + "x_test /= 255\n", |
| 81 | + "print('x_train shape:', x_train.shape)\n", |
| 82 | + "print(x_train.shape[0], 'train samples')\n", |
| 83 | + "print(x_test.shape[0], 'test samples')\n", |
| 84 | + "\n", |
| 85 | + "# convert class vectors to binary class matrices\n", |
| 86 | + "y_train = keras.utils.to_categorical(y_train, num_classes)\n", |
| 87 | + "y_test = keras.utils.to_categorical(y_test, num_classes)\n", |
| 88 | + "\n", |
| 89 | + "import tensorflow as tf\n", |
| 90 | + "config = tf.ConfigProto()\n", |
| 91 | + "config.gpu_options.allow_growth = True\n", |
| 92 | + "session = tf.Session(config=config)\n", |
| 93 | + "\n", |
| 94 | + "\n", |
| 95 | + "with kk.tf_ops.device('/device:CPU:0'):\n", |
| 96 | + " model = Sequential()\n", |
| 97 | + " model.add(Conv2D(32, kernel_size=(3, 3),\n", |
| 98 | + " activation='relu',\n", |
| 99 | + " input_shape=input_shape))\n", |
| 100 | + " model.add(Conv2D(64, (3, 3), activation='relu'))\n", |
| 101 | + " model.add(MaxPooling2D(pool_size=(2, 2)))\n", |
| 102 | + " model.add(Dropout(0.25))\n", |
| 103 | + " model.add(Flatten())\n", |
| 104 | + " model.add(Dense(128, activation='relu'))\n", |
| 105 | + " model.add(Dropout(0.5))\n", |
| 106 | + " model.add(Dense(num_classes, activation='softmax'))\n", |
| 107 | + "\n", |
| 108 | + " model.compile(loss=keras.losses.categorical_crossentropy,\n", |
| 109 | + " optimizer=keras.optimizers.Adadelta(),\n", |
| 110 | + " metrics=['accuracy'])\n", |
| 111 | + "\n", |
| 112 | + " model.fit(x_train, y_train,\n", |
| 113 | + " batch_size=batch_size,\n", |
| 114 | + " epochs=epochs,\n", |
| 115 | + " verbose=1,\n", |
| 116 | + " validation_data=(x_test, y_test))\n", |
| 117 | + "score = model.evaluate(x_test, y_test, verbose=0)\n", |
| 118 | + "print('Test loss:', score[0])\n", |
| 119 | + "print('Test accuracy:', score[1])" |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + "cell_type": "code", |
| 124 | + "execution_count": null, |
| 125 | + "metadata": {}, |
| 126 | + "outputs": [], |
| 127 | + "source": [] |
| 128 | + } |
| 129 | + ], |
| 130 | + "metadata": { |
| 131 | + "kernelspec": { |
| 132 | + "display_name": "Python 3", |
| 133 | + "language": "python", |
| 134 | + "name": "python3" |
| 135 | + }, |
| 136 | + "language_info": { |
| 137 | + "codemirror_mode": { |
| 138 | + "name": "ipython", |
| 139 | + "version": 3 |
| 140 | + }, |
| 141 | + "file_extension": ".py", |
| 142 | + "mimetype": "text/x-python", |
| 143 | + "name": "python", |
| 144 | + "nbconvert_exporter": "python", |
| 145 | + "pygments_lexer": "ipython3", |
| 146 | + "version": "3.6.5" |
| 147 | + } |
| 148 | + }, |
| 149 | + "nbformat": 4, |
| 150 | + "nbformat_minor": 2 |
| 151 | +} |
0 commit comments