|
16 | 16 | }, |
17 | 17 | { |
18 | 18 | "cell_type": "code", |
19 | | - "execution_count": 1, |
| 19 | + "execution_count": 2, |
20 | 20 | "metadata": {}, |
21 | | - "outputs": [ |
22 | | - { |
23 | | - "name": "stderr", |
24 | | - "output_type": "stream", |
25 | | - "text": [ |
26 | | - "Using TensorFlow backend.\n" |
27 | | - ] |
28 | | - } |
29 | | - ], |
| 21 | + "outputs": [], |
30 | 22 | "source": [ |
31 | 23 | "from collections import Counter\n", |
32 | | - "import keras\n", |
| 24 | + "from tensorflow import keras\n", |
33 | 25 | "from keras.datasets import mnist\n", |
34 | 26 | "from keras.layers import Dense, Dropout\n", |
35 | 27 | "from keras.models import load_model, Sequential\n", |
36 | 28 | "from keras.optimizers import SGD\n", |
37 | | - "from keras.utils import np_utils\n", |
| 29 | + "from keras.utils import to_categorical\n", |
38 | 30 | "import matplotlib.pyplot as plt\n", |
39 | 31 | "%matplotlib inline\n", |
40 | 32 | "import numpy as np\n", |
|
57 | 49 | }, |
58 | 50 | { |
59 | 51 | "cell_type": "code", |
60 | | - "execution_count": 2, |
| 52 | + "execution_count": 3, |
61 | 53 | "metadata": {}, |
62 | 54 | "outputs": [], |
63 | 55 | "source": [ |
|
67 | 59 | " x_test = x_test.reshape(10000, 784)\n", |
68 | 60 | " x_train = x_train.astype(np.float32)/255.0\n", |
69 | 61 | " x_test = x_test.astype(np.float32)/255.0\n", |
70 | | - " y_train = np_utils.to_categorical(y_train)\n", |
71 | | - " y_test = np_utils.to_categorical(y_test)\n", |
| 62 | + " y_train = to_categorical(y_train)\n", |
| 63 | + " y_test = to_categorical(y_test)\n", |
72 | 64 | " return x_train, y_train, x_test, y_test" |
73 | 65 | ] |
74 | 66 | }, |
75 | 67 | { |
76 | 68 | "cell_type": "code", |
77 | | - "execution_count": 3, |
| 69 | + "execution_count": 4, |
78 | 70 | "metadata": {}, |
79 | 71 | "outputs": [], |
80 | 72 | "source": [ |
|
97 | 89 | }, |
98 | 90 | { |
99 | 91 | "cell_type": "code", |
100 | | - "execution_count": 4, |
| 92 | + "execution_count": 5, |
101 | 93 | "metadata": {}, |
102 | 94 | "outputs": [], |
103 | 95 | "source": [ |
|
129 | 121 | }, |
130 | 122 | { |
131 | 123 | "cell_type": "code", |
132 | | - "execution_count": 5, |
| 124 | + "execution_count": 6, |
133 | 125 | "metadata": {}, |
134 | 126 | "outputs": [], |
135 | 127 | "source": [ |
|
145 | 137 | }, |
146 | 138 | { |
147 | 139 | "cell_type": "code", |
148 | | - "execution_count": 6, |
| 140 | + "execution_count": 7, |
149 | 141 | "metadata": { |
150 | 142 | "scrolled": true |
151 | 143 | }, |
|
154 | 146 | "name": "stdout", |
155 | 147 | "output_type": "stream", |
156 | 148 | "text": [ |
157 | | - "model 1\n", |
| 149 | + "model 1\n" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "name": "stderr", |
| 154 | + "output_type": "stream", |
| 155 | + "text": [ |
| 156 | + "2024-03-20 09:54:27.891996: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 157 | + "Your kernel may have been built without NUMA support.\n", |
| 158 | + "2024-03-20 09:54:28.321918: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 159 | + "Your kernel may have been built without NUMA support.\n", |
| 160 | + "2024-03-20 09:54:28.321969: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 161 | + "Your kernel may have been built without NUMA support.\n", |
| 162 | + "2024-03-20 09:54:28.326420: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 163 | + "Your kernel may have been built without NUMA support.\n", |
| 164 | + "2024-03-20 09:54:28.326464: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 165 | + "Your kernel may have been built without NUMA support.\n", |
| 166 | + "2024-03-20 09:54:28.326487: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 167 | + "Your kernel may have been built without NUMA support.\n", |
| 168 | + "2024-03-20 09:54:35.782651: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 169 | + "Your kernel may have been built without NUMA support.\n", |
| 170 | + "2024-03-20 09:54:35.783569: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 171 | + "Your kernel may have been built without NUMA support.\n", |
| 172 | + "2024-03-20 09:54:35.783589: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2022] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n", |
| 173 | + "2024-03-20 09:54:35.783689: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:887] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node\n", |
| 174 | + "Your kernel may have been built without NUMA support.\n", |
| 175 | + "2024-03-20 09:54:35.784579: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1929] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 3421 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n", |
| 176 | + "2024-03-20 09:55:35.800249: I external/local_xla/xla/service/service.cc:168] XLA service 0x7f56bc0020b0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:\n", |
| 177 | + "2024-03-20 09:55:35.800419: I external/local_xla/xla/service/service.cc:176] StreamExecutor device (0): NVIDIA GeForce RTX 3060 Laptop GPU, Compute Capability 8.6\n", |
| 178 | + "2024-03-20 09:55:37.662907: I external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:454] Loaded cuDNN version 8907\n", |
| 179 | + "WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n", |
| 180 | + "I0000 00:00:1710924937.828903 11615 device_compiler.h:186] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process.\n" |
| 181 | + ] |
| 182 | + }, |
| 183 | + { |
| 184 | + "name": "stdout", |
| 185 | + "output_type": "stream", |
| 186 | + "text": [ |
158 | 187 | "model 2\n", |
159 | 188 | "model 3\n" |
160 | 189 | ] |
|
188 | 217 | }, |
189 | 218 | { |
190 | 219 | "cell_type": "code", |
191 | | - "execution_count": 7, |
| 220 | + "execution_count": 8, |
192 | 221 | "metadata": {}, |
193 | 222 | "outputs": [ |
194 | 223 | { |
195 | 224 | "data": { |
196 | 225 | "text/plain": [ |
197 | | - "[0.9514, 0.9506, 0.9488]" |
| 226 | + "[0.9503999948501587, 0.9484999775886536, 0.9495999813079834]" |
198 | 227 | ] |
199 | 228 | }, |
200 | | - "execution_count": 7, |
| 229 | + "execution_count": 8, |
201 | 230 | "metadata": {}, |
202 | 231 | "output_type": "execute_result" |
203 | 232 | } |
|
219 | 248 | }, |
220 | 249 | { |
221 | 250 | "cell_type": "code", |
222 | | - "execution_count": 8, |
| 251 | + "execution_count": 10, |
223 | 252 | "metadata": {}, |
224 | | - "outputs": [], |
| 253 | + "outputs": [ |
| 254 | + { |
| 255 | + "name": "stdout", |
| 256 | + "output_type": "stream", |
| 257 | + "text": [ |
| 258 | + "313/313 [==============================] - 1s 2ms/step\n", |
| 259 | + "313/313 [==============================] - 1s 2ms/step\n", |
| 260 | + "313/313 [==============================] - 0s 1ms/step\n" |
| 261 | + ] |
| 262 | + } |
| 263 | + ], |
225 | 264 | "source": [ |
226 | 265 | "y_infer = np.empty((len(models), len(y_test)), dtype=np.int64)\n", |
227 | 266 | "for i, model in enumerate(models):\n", |
228 | | - " y_infer[i, :] = model.predict_classes(x_test)" |
| 267 | + " prediction = model.predict(x_test)\n", |
| 268 | + " y_infer[i, :] = np.argmax(prediction, axis=1)" |
229 | 269 | ] |
230 | 270 | }, |
231 | 271 | { |
|
237 | 277 | }, |
238 | 278 | { |
239 | 279 | "cell_type": "code", |
240 | | - "execution_count": 9, |
| 280 | + "execution_count": 11, |
241 | 281 | "metadata": { |
242 | 282 | "scrolled": true |
243 | 283 | }, |
|
246 | 286 | "name": "stdout", |
247 | 287 | "output_type": "stream", |
248 | 288 | "text": [ |
249 | | - "0.9519\n" |
| 289 | + "0.951\n" |
250 | 290 | ] |
251 | 291 | } |
252 | 292 | ], |
|
285 | 325 | }, |
286 | 326 | { |
287 | 327 | "cell_type": "code", |
288 | | - "execution_count": 15, |
| 328 | + "execution_count": 12, |
289 | 329 | "metadata": {}, |
290 | 330 | "outputs": [], |
291 | 331 | "source": [ |
|
294 | 334 | }, |
295 | 335 | { |
296 | 336 | "cell_type": "code", |
297 | | - "execution_count": 16, |
| 337 | + "execution_count": 13, |
298 | 338 | "metadata": {}, |
299 | 339 | "outputs": [], |
300 | 340 | "source": [ |
|
306 | 346 | }, |
307 | 347 | { |
308 | 348 | "cell_type": "code", |
309 | | - "execution_count": 17, |
| 349 | + "execution_count": 14, |
310 | 350 | "metadata": {}, |
311 | 351 | "outputs": [ |
312 | 352 | { |
313 | 353 | "data": { |
314 | 354 | "text/plain": [ |
315 | | - "[0.09286915022358298, 0.9707]" |
| 355 | + "[0.09376676380634308, 0.9704999923706055]" |
316 | 356 | ] |
317 | 357 | }, |
318 | | - "execution_count": 17, |
| 358 | + "execution_count": 14, |
319 | 359 | "metadata": {}, |
320 | 360 | "output_type": "execute_result" |
321 | 361 | } |
|
334 | 374 | ], |
335 | 375 | "metadata": { |
336 | 376 | "kernelspec": { |
337 | | - "display_name": "Python 3", |
| 377 | + "display_name": "Python 3 (ipykernel)", |
338 | 378 | "language": "python", |
339 | 379 | "name": "python3" |
340 | 380 | }, |
|
348 | 388 | "name": "python", |
349 | 389 | "nbconvert_exporter": "python", |
350 | 390 | "pygments_lexer": "ipython3", |
351 | | - "version": "3.6.6" |
| 391 | + "version": "3.11.8" |
352 | 392 | } |
353 | 393 | }, |
354 | 394 | "nbformat": 4, |
355 | | - "nbformat_minor": 2 |
| 395 | + "nbformat_minor": 4 |
356 | 396 | } |
0 commit comments