Skip to content
Snippets Groups Projects
Commit cacae355 authored by halteproblem's avatar halteproblem
Browse files

updated keras model

parent 0bb91237
Branches
Tags
No related merge requests found
%% Cell type:code id:ab5b8f55 tags: %% Cell type:code id:ab5b8f55 tags:
``` python ``` python
from tensorflow.keras.datasets import mnist from tensorflow.keras.datasets import mnist
from tensorflow.keras import layers from tensorflow.keras import layers
from tensorflow import keras from tensorflow import keras
``` ```
%% Output %% Output
2022-11-07 01:27:36.412359: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA 2022-11-21 13:55:12.803035: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-11-07 01:27:36.541397: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory 2022-11-21 13:55:13.455822: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-11-07 01:27:36.541430: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2022-11-21 13:55:13.455839: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2022-11-07 01:27:36.570561: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered 2022-11-21 13:55:13.531867: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2022-11-07 01:27:37.237114: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory 2022-11-21 13:55:15.035232: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-11-07 01:27:37.237230: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory 2022-11-21 13:55:15.035379: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-11-07 01:27:37.237238: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly. 2022-11-21 13:55:15.035388: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
%% Cell type:code id:840ed4ea tags: %% Cell type:code id:840ed4ea tags:
``` python ``` python
def CNN(): def CNN():
model = keras.Sequential() model = keras.Sequential()
model.add(layers.Conv2D( model.add(layers.Conv2D(
filters=6, filters=6,
kernel_size=(3, 3), kernel_size=(5, 5),
activation='relu', activation='relu',
padding='valid' padding='valid'
)) ))
model.add(layers.AveragePooling2D()) model.add(layers.MaxPooling2D())
model.add(layers.Conv2D(
filters=16,
kernel_size=(5, 5),
activation='relu',
padding='valid'
))
model.add(layers.MaxPooling2D())
model.add(layers.Flatten()) model.add(layers.Flatten())
model.add(layers.Dense( model.add(layers.Dense(
units=120, units=120,
activation='relu' activation='relu'
)) ))
model.add(layers.Dense( model.add(layers.Dense(
units=84, units=84,
activation='relu' activation='relu'
)) ))
model.add(layers.Dense( model.add(layers.Dense(
units=10, units=10,
activation='softmax' activation='softmax'
)) ))
model.compile( model.compile(
optimizer='adam', optimizer='adam',
loss='categorical_crossentropy', loss='categorical_crossentropy',
metrics=['accuracy'] metrics=['accuracy']
) )
model.fit( model.fit(
train_images, train_labels, train_images, train_labels,
epochs=10, epochs=10,
batch_size=128 batch_size=128
) )
results = model.evaluate(test_images, test_labels) results = model.evaluate(test_images, test_labels)
model.save('model') model.save('model')
model.save_weights('weights.h5') model.save_weights('weights.h5')
``` ```
%% Cell type:code id:b25a29c6 tags: %% Cell type:code id:b25a29c6 tags:
``` python ``` python
(train_images, train_labels), (test_images, test_labels) = mnist.load_data() (train_images, train_labels), (test_images, test_labels) = mnist.load_data()
train_images = train_images.reshape((60_000, 28, 28, 1)).astype("float32") / 255 train_images = train_images.reshape((60_000, 28, 28, 1)).astype("float32") / 255
test_images = test_images.reshape((10_000, 28, 28, 1)).astype("float32") / 255 test_images = test_images.reshape((10_000, 28, 28, 1)).astype("float32") / 255
train_labels = keras.utils.to_categorical(train_labels) train_labels = keras.utils.to_categorical(train_labels)
test_labels = keras.utils.to_categorical(test_labels) test_labels = keras.utils.to_categorical(test_labels)
CNN() CNN()
``` ```
%% Output %% Output
2022-11-21 13:55:22.825403: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2022-11-21 13:55:22.825842: W tensorflow/stream_executor/cuda/cuda_driver.cc:263] failed call to cuInit: UNKNOWN ERROR (303)
2022-11-21 13:55:22.825876: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (pop-os): /proc/driver/nvidia/version does not exist
2022-11-21 13:55:22.826864: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Epoch 1/10 Epoch 1/10
469/469 [==============================] - 4s 8ms/step - loss: 0.3470 - accuracy: 0.9018 469/469 [==============================] - 7s 14ms/step - loss: 0.3167 - accuracy: 0.9061
Epoch 2/10 Epoch 2/10
469/469 [==============================] - 4s 8ms/step - loss: 0.1211 - accuracy: 0.9649 469/469 [==============================] - 6s 13ms/step - loss: 0.0950 - accuracy: 0.9712
Epoch 3/10 Epoch 3/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0778 - accuracy: 0.9770 469/469 [==============================] - 6s 14ms/step - loss: 0.0697 - accuracy: 0.9786
Epoch 4/10 Epoch 4/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0569 - accuracy: 0.9829 469/469 [==============================] - 6s 14ms/step - loss: 0.0558 - accuracy: 0.9829
Epoch 5/10 Epoch 5/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0456 - accuracy: 0.9858 469/469 [==============================] - 6s 14ms/step - loss: 0.0464 - accuracy: 0.9858
Epoch 6/10 Epoch 6/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0373 - accuracy: 0.9888 469/469 [==============================] - 7s 14ms/step - loss: 0.0395 - accuracy: 0.9876
Epoch 7/10 Epoch 7/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0309 - accuracy: 0.9904 469/469 [==============================] - 7s 14ms/step - loss: 0.0343 - accuracy: 0.9889
Epoch 8/10 Epoch 8/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0268 - accuracy: 0.9912 469/469 [==============================] - 7s 14ms/step - loss: 0.0297 - accuracy: 0.9908
Epoch 9/10 Epoch 9/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0214 - accuracy: 0.9932 469/469 [==============================] - 7s 15ms/step - loss: 0.0257 - accuracy: 0.9918
Epoch 10/10 Epoch 10/10
469/469 [==============================] - 4s 8ms/step - loss: 0.0197 - accuracy: 0.9938 469/469 [==============================] - 6s 13ms/step - loss: 0.0233 - accuracy: 0.9923
313/313 [==============================] - 1s 2ms/step - loss: 0.0699 - accuracy: 0.9782 313/313 [==============================] - 1s 2ms/step - loss: 0.0331 - accuracy: 0.9897
WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op while saving (showing 1 of 1). These functions will not be directly callable after loading. WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 2 of 2). These functions will not be directly callable after loading.
INFO:tensorflow:Assets written to: model/assets INFO:tensorflow:Assets written to: model/assets
INFO:tensorflow:Assets written to: model/assets INFO:tensorflow:Assets written to: model/assets
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment