티스토리 뷰
MNIST 예제 main 처리
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
if __name__ == '__main__':
mnist = keras.datasets.mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
mnist_idx = 100
for row in train_images[mnist_idx]:
for col in row:
print('%10f' % col, end='')
print('\n')
print('\n')
plt.figure(figsize=(5,5))
image = train_images[mnist_idx]
plt.imshow(image)
plt.show()
|
cs |
MNIST 예제 객체지향 처리
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import tensorflow as tf
class TFFuntion:
def execute(self):
mnist = tf.keras.datasets.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_train[..., tf.newaxis]
x_test = x_test[..., tf.newaxis]
train_ds = tf.data.Dataset.from_tensor_slices(
(x_train, y_train)
).shuffle(10000).batch(32)
test_ds = tf.data.Dataset.from_tensor_slices((x_test, y_train)).batch(32)
|
cs |
MNIST 예제 오리지널
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
|
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
mnist = keras.datasets.mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
print("훈련 이미지: ", train_images.shape)
print("훈련 라벨: ", train_labels.shape)
print("테스트 이미지: ", test_images.shape)
print("테스트 라벨: ", test_labels.shape)
mnist_idx = 100
print('[label]')
print('number label = ', train_labels[mnist_idx])
for row in train_images[mnist_idx]:
for col in row:
print('%10f' % col, end='')
print('\n')
print('\n')
plt.figure(figsize=(5,5))
image = train_images[mnist_idx]
plt.imshow(image)
plt.show()
|
cs |
'5. 파이썬' 카테고리의 다른 글
[텐서플로] 경사하강법 그래프 보기 (0) | 2020.05.16 |
---|---|
[텐서플로] 인공지능 계산기 (0) | 2020.05.16 |
[텐서플로2] 회귀분석 예제 regression.py (0) | 2020.05.14 |
[텐서플로] 모델의 저장과 로드 save_load.py (0) | 2020.05.14 |
[텐서플로] 패션 MNIST 예제 fashion_mnist.py (0) | 2020.05.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- springMVC
- Mongo
- Python
- JUnit
- COLAB
- Oracle
- Django
- AWS
- React
- Git
- FLASK
- ERD
- KAFKA
- jQuery
- maven
- docker
- Java
- SpringBoot
- JPA
- nodejs
- tensorflow
- Eclipse
- Algorithm
- vscode
- Mlearn
- SQLAlchemy
- intellij
- mariadb
- database
- terms
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함