728x90
반응형
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.utils import to_categorical
import pandas as pd
import numpy as np
import math
INPUT_SHAPE = 784
NUM_CATEGORIES = 10
LABEL_DICT = {
0: "T-shirt/top",
1: "Trouser",
2: "Pullover",
3: "Dress",
4: "Coat",
5: "Sandal",
6: "Shirt",
7: "Sneaker",
8: "Bag",
9: "Ankle boot"
}
# LOAD THE RAW DATA
train_raw = pd.read_csv('C:/Users/user/Desktop/sehyun/archive/fashion-mnist_train.csv').values
test_raw = pd.read_csv('C:/Users/user/Desktop/sehyun/archive/fashion-mnist_test.csv').values
# split into X and Y, after one-hot encoding
train_x, train_y = (train_raw[:,1:], to_categorical(train_raw[:,0], num_classes = NUM_CATEGORIES))
test_x, test_y = (test_raw[:,1:], to_categorical(test_raw[:,0], num_classes = NUM_CATEGORIES))
# normalize the x data
train_x = train_x / 255
test_x = test_x / 255
# BUILD THE MODEL
model = Sequential()
model.add(Dense(512, input_dim = INPUT_SHAPE))
model.add(Activation('relu'))
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dense(NUM_CATEGORIES))
model.add(Activation('softmax'))
# compile it - categorical crossentropy is for multiple choice classification
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
# train the model!
model.fit(train_x,
train_y,
epochs = 10,
batch_size = 32,
validation_data = (test_x, test_y))
score = model.evaluate(test_x, test_y, steps=math.ceil(10000/32))
# checking the test loss and test accuracy
print('Test loss:', score[0])
print('Test accuracy:', score[1])
728x90
반응형
'코드' 카테고리의 다른 글
[matlab] 이미지 리사이즈 코드 (0) | 2023.03.20 |
---|---|
[python] 이미지 증강 코드 data augmentaion (0) | 2023.03.20 |
[python] 말과 사람 구분하기 horse or human (0) | 2023.02.24 |
[python] Fashion mnist cnn (0) | 2023.02.24 |
[python] keras NeRF (0) | 2023.02.24 |