728x90
반응형
# CNN
# https://hmkim312.github.io/posts/MNIST_%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%A1%9C_%ED%95%B4%EB%B3%B4%EB%8A%94_CNN(Convolution_Neral_Network)/
import tensorflow as tf
mnist = tf.keras.datasets.fashion_mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
x_train, x_test = x_train.reshape((60000, 28,28,1)), x_test.reshape((10000, 28,28,1))
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(64, kernel_size=(5,5), strides=(1,1), padding='same',
activation='relu', input_shape=(28,28,1)),
tf.keras.layers.MaxPooling2D(pool_size=(2,2), strides=(2,2)),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)
"""
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
32768/29515 [=================================] - 0s 0us/step
40960/29515 [=========================================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
26427392/26421880 [==============================] - 0s 0us/step
26435584/26421880 [==============================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz
16384/5148 [===============================================================================================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz
4423680/4422102 [==============================] - 0s 0us/step
4431872/4422102 [==============================] - 0s 0us/step
Epoch 1/5
1875/1875 [==============================] - 82s 43ms/step - loss: 0.3812 - accuracy: 0.8639
Epoch 2/5
1875/1875 [==============================] - 79s 42ms/step - loss: 0.2568 - accuracy: 0.9064
Epoch 3/5
1875/1875 [==============================] - 78s 42ms/step - loss: 0.2123 - accuracy: 0.9216
Epoch 4/5
1875/1875 [==============================] - 78s 42ms/step - loss: 0.1781 - accuracy: 0.9330
Epoch 5/5
1875/1875 [==============================] - 79s 42ms/step - loss: 0.1487 - accuracy: 0.9440
313/313 [==============================] - 4s 11ms/step - loss: 0.2705 - accuracy: 0.9106
[0.2704820930957794, 0.9106000065803528]
"""
728x90
반응형
'Deep Learning' 카테고리의 다른 글
Count Objects in Image using Python (0) | 2022.09.06 |
---|---|
Creating Number Recognition Artificial Intelligence (0) | 2022.09.05 |
Basic Tensorflow (0) | 2022.09.02 |
7 Segment Display binary connetion table (0) | 2022.09.01 |
Activation Function(sigmoid, relu, softmax) (0) | 2022.09.01 |