Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Windows 10
- 턱걸이
- TensorFlow
- 회귀
- 학습
- 프로그래밍
- shell
- c
- error
- 코딩
- 딥러닝
- 시스템프로그래밍
- C언어
- Computer Vision
- 프로세스
- 백준
- python
- 공부
- 리눅스
- linux
- 운영체제
- 텐서플로우
- 알고리즘
- 쉘
- 영상처리
- 백준알고리즘
- C++
- OpenCV
- Windows10
- CV
Archives
- Today
- Total
줘이리의 인생적기
[tensorflow 24] Fashion MNIST04 본문
728x90
더 높은 정확도를 나오게 하려면 어떻게 해야할까요?
딥러닝의 발전은 컨볼루션 레이어가 중첩된 더 깊은 구조에서 나타났습니다.
정확도가 개선되었다는 말이죠
이번에는 VGG의 스타일로 모델을 생성해보도록 하겠습니다.
import tensorflow as tf
import matplotlib.pyplot as plt
fashion_mnist = tf.keras.datasets.fashion_mnist
(train_X, train_Y), (test_X, test_Y) = fashion_mnist.load_data()
train_X = train_X / 255.0
test_X = test_X / 255.0
# print("reshape 이전 => ", train_X.shape, test_X.shape)
train_X = train_X.reshape(-1, 28, 28, 1)
test_X = test_X.reshape(-1, 28, 28, 1)
# print("reshape 이후 => ", train_X.shape, test_X.shape)
#모델 생성
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(input_shape=(28,28,1), kernel_size=(3,3), filters=32, padding='same', activation='relu'),
tf.keras.layers.Conv2D(kernel_size=(3,3), filters=64, padding='same', activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=(2,2)),
tf.keras.layers.Conv2D(kernel_size=(3,3), filters=128, padding='same', activation='relu'),
tf.keras.layers.Conv2D(kernel_size=(3,3), filters=256, padding='valid', activation='relu'),
tf.keras.layers.MaxPool2D(pool_size=(2,2)),
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(units=512, activation='relu'),
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Dense(units=256, activation='relu'),
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Dense(units=10, activation='softmax')
])
model.compile(optimizer=tf.keras.optimizers.Adam(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
history = model.fit(train_X, train_Y, epochs=25, validation_split=0.25)
#loss 시각화
plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(history.history['loss'], 'b-', label='loss')
plt.plot(history.history['val_loss'], 'r--', label='val_loss')
plt.xlabel('Epoch')
plt.legend()
plt.subplot(1, 2, 2)
plt.plot(history.history['accuracy'], 'g-', label='accuracy')
plt.plot(history.history['val_accuracy'], 'k--', label='val_accuracy')
plt.xlabel('Epoch')
plt.ylim(0.7, 1)
plt.legend()
plt.show()
result = model.evaluate(test_X, test_Y, verbose=0)
print(result)
layer 부분을 유심하게 봐주세요
컨볼루션 레이어 Dense 레이어 총합 7개 정도 쌓았습니다
결과가 어떻게 나왔을까요
와우 92.7퍼센트로 정확도가 올랐네요.
epoch를 더 올리면 더 높은 정확도를 얻을 수 있을 것 같습니다.
깊게 쌓을수록 좋은 정확도를 얻을 수 있다는 것을 확인했네요
다른 방법도 있을까요?
'공부 > tensorflow' 카테고리의 다른 글
[tensorflow 25] Fashion MNIST05 (0) | 2021.08.09 |
---|---|
[tensorflow 23] Fashion MNIST03 (0) | 2021.05.26 |
[tensorflow 22] Fashion MNIST02 (0) | 2021.05.25 |
[tensorflow 21] 레이어 (0) | 2021.05.24 |
[tensorflow 20] CNN - 특징 추출 (0) | 2021.05.21 |