import

from keras.utils    import np_utils
from keras.datasets import mnist
from keras.models   import Sequential
from keras.layers   import Dense

 

mnist 데이터 변형하기

tri = tri.reshape(tri.shape[0],784).astype("float32")/255.0
tei = tei.reshape(tei.shape[0],784).astype("float32")/255.0
trl = np_utils.to_categorical(trl, num_classes=10, dtype='float32')
tel = np_utils.to_categorical(tel, num_classes=10, dtype='float32')
print(tri.shape,trl.shape,tei.shape,tel.shape)

model

model = Sequential()
model.add(Dense(256, activation="relu"))
model.add(Dense(512, activation="relu"))
model.add(Dense(10, activation="softmax"))
model.compile(loss="categorical_crossentropy", optimizer="sgd", metrics=['accuracy'])
model.fit(tri, trl, epochs=5, batch_size=128, verbose=1)

c, a = model.evaluate(tei, tel)
print("acc : " , a, " , c : " , c)

'도서관 I > AI' 카테고리의 다른 글

Fashion-MNIST 예제  (0) 2020.06.01
기본 keras 사용법  (0) 2020.06.01
top_K  (0) 2020.06.01
MNIST 데이터 불러오기  (0) 2020.05.29
python 정리  (0) 2020.05.28

+ Recent posts