-
Notifications
You must be signed in to change notification settings - Fork 0
/
deep_learning_with_python_appendix_a.ipynb
175 lines (175 loc) · 13.8 KB
/
deep_learning_with_python_appendix_a.ipynb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "deep_learning_with_python_appendix_a.ipynb",
"version": "0.3.2",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/jeffblackadar/image_work/blob/master/deep_learning_with_python_appendix_a.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Rhct4ZAeUoiQ",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "349b3737-88df-42f8-d7aa-e270294c5013"
},
"source": [
"# Deep Learning with Python \n",
"# François Chollet\n",
"# from page 340\n",
"# python 3\n",
"# I uncomment and run each line and then recomment it\n",
"\n",
"#! sudo apt-get update\n",
"#!sudo apt --fix-broken install\n",
"#! sudo apt-get upgrade\n",
"#! sudo apt-get install python3-pip python3-dev\n",
"#! sudo apt-get install build-essential cmake git unzip pkg-config libopenblas-dev liblapack-dev\n",
"#! sudo apt-get install python-numpy python-scipy python-matplotlib python-yaml\n",
"#! sudo apt-get install libhdf5-serial-dev python-h5py\n",
"#! sudo apt-get install graphviz\n",
"#! sudo pip3 install pydot-ng\n",
"#! sudo apt-get install python-opencv\n",
"#! wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.0.176-1_amd64.deb\n",
"# changed to\n",
"#! wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.1.168-1_amd64.deb\n",
"\n",
"#! sudo dpkg -i cuda-repo-ubuntu1604_9.0.176-1_amd64.deb\n",
"#changed to\n",
"#! sudo dpkg -i cuda-repo-ubuntu1604_10.1.168-1_amd64.deb\n",
"\n",
"#! sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub\n",
"#! sudo apt-get update\n",
"#! sudo apt-get install cuda-10-0\n",
"# Uploaded libcudnn7-dev_7.6.0.64-1+cuda10.0_amd64.deb\n",
"#! sudo dpkg -i /content/libcudnn7*.deb\n",
"#! sudo pip3 install tensorflow\n",
"#!sudo pip3 install tensorflow-gpu\n",
"#! sudo pip3 install keras\n",
"#!git clone https://github.com/fchollet/keras\n",
"\n",
"#!sudo python3 /content/keras/setup.py install\n",
"!python3 /content/keras/examples/mnist_cnn.py"
],
"execution_count": 20,
"outputs": [
{
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n",
"Downloading data from https://s3.amazonaws.com/img-datasets/mnist.npz\n",
"11493376/11490434 [==============================] - 2s 0us/step\n",
"x_train shape: (60000, 28, 28, 1)\n",
"60000 train samples\n",
"10000 test samples\n",
"WARNING: Logging before flag parsing goes to stderr.\n",
"W0714 19:13:17.944064 140457858963328 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n",
"\n",
"W0714 19:13:17.956455 140457858963328 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n",
"\n",
"W0714 19:13:17.958007 140457858963328 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.\n",
"\n",
"W0714 19:13:17.987353 140457858963328 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3976: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
"\n",
"W0714 19:13:17.988847 140457858963328 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:133: The name tf.placeholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead.\n",
"\n",
"W0714 19:13:17.996473 140457858963328 deprecation.py:506] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.\n",
"W0714 19:13:18.081905 140457858963328 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:790: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n",
"\n",
"W0714 19:13:18.089526 140457858963328 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3295: The name tf.log is deprecated. Please use tf.math.log instead.\n",
"\n",
"W0714 19:13:18.199475 140457858963328 deprecation.py:323] From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_grad.py:1250: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use tf.where in 2.0, which has the same broadcast rule as np.where\n",
"Train on 60000 samples, validate on 10000 samples\n",
"Epoch 1/12\n",
"2019-07-14 19:13:18.606276: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA\n",
"2019-07-14 19:13:18.611527: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1\n",
"2019-07-14 19:13:18.758703: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
"2019-07-14 19:13:18.759329: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x16cf100 executing computations on platform CUDA. Devices:\n",
"2019-07-14 19:13:18.759365: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Tesla K80, Compute Capability 3.7\n",
"2019-07-14 19:13:18.761875: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2300000000 Hz\n",
"2019-07-14 19:13:18.762197: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x16cf9c0 executing computations on platform Host. Devices:\n",
"2019-07-14 19:13:18.762268: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): <undefined>, <undefined>\n",
"2019-07-14 19:13:18.762530: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
"2019-07-14 19:13:18.762977: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: \n",
"name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235\n",
"pciBusID: 0000:00:04.0\n",
"2019-07-14 19:13:18.766944: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0\n",
"2019-07-14 19:13:18.949494: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0\n",
"2019-07-14 19:13:19.032754: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10.0\n",
"2019-07-14 19:13:19.052451: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10.0\n",
"2019-07-14 19:13:19.263876: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10.0\n",
"2019-07-14 19:13:19.377656: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10.0\n",
"2019-07-14 19:13:19.715335: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7\n",
"2019-07-14 19:13:19.715616: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
"2019-07-14 19:13:19.716098: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
"2019-07-14 19:13:19.716519: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0\n",
"2019-07-14 19:13:19.716613: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0\n",
"2019-07-14 19:13:19.718816: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:\n",
"2019-07-14 19:13:19.718852: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0 \n",
"2019-07-14 19:13:19.718869: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N \n",
"2019-07-14 19:13:19.719321: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
"2019-07-14 19:13:19.719829: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
"2019-07-14 19:13:19.720260: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:40] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n",
"2019-07-14 19:13:19.720320: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10802 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7)\n",
"2019-07-14 19:13:20.510397: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0\n",
"2019-07-14 19:13:21.159826: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7\n",
"60000/60000 [==============================] - 13s 221us/step - loss: 0.2661 - acc: 0.9186 - val_loss: 0.0675 - val_acc: 0.9763\n",
"Epoch 2/12\n",
"60000/60000 [==============================] - 8s 141us/step - loss: 0.0901 - acc: 0.9729 - val_loss: 0.0411 - val_acc: 0.9863\n",
"Epoch 3/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0684 - acc: 0.9793 - val_loss: 0.0343 - val_acc: 0.9890\n",
"Epoch 4/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0554 - acc: 0.9836 - val_loss: 0.0286 - val_acc: 0.9901\n",
"Epoch 5/12\n",
"60000/60000 [==============================] - 8s 141us/step - loss: 0.0469 - acc: 0.9859 - val_loss: 0.0306 - val_acc: 0.9892\n",
"Epoch 6/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0415 - acc: 0.9876 - val_loss: 0.0271 - val_acc: 0.9910\n",
"Epoch 7/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0393 - acc: 0.9882 - val_loss: 0.0263 - val_acc: 0.9921\n",
"Epoch 8/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0359 - acc: 0.9889 - val_loss: 0.0296 - val_acc: 0.9903\n",
"Epoch 9/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0311 - acc: 0.9904 - val_loss: 0.0281 - val_acc: 0.9903\n",
"Epoch 10/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0291 - acc: 0.9908 - val_loss: 0.0241 - val_acc: 0.9923\n",
"Epoch 11/12\n",
"60000/60000 [==============================] - 8s 141us/step - loss: 0.0275 - acc: 0.9912 - val_loss: 0.0297 - val_acc: 0.9909\n",
"Epoch 12/12\n",
"60000/60000 [==============================] - 8s 140us/step - loss: 0.0272 - acc: 0.9914 - val_loss: 0.0286 - val_acc: 0.9914\n",
"Test loss: 0.028639289979931436\n",
"Test accuracy: 0.9914\n"
],
"name": "stdout"
}
]
}
]
}