one hot 인코딩 적용
This commit is contained in:
jung-geun
2023-07-11 02:10:14 +09:00
parent 0dd6cc4cab
commit 026223bd19
4 changed files with 16 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
import gc
import tensorflow as tf
from tensorflow import keras
from keras.datasets import mnist
from keras.layers import Conv2D, Dense, Dropout, Flatten, MaxPooling2D
@@ -22,6 +23,8 @@ def get_data():
x_train = x_train.reshape((60000, 28, 28, 1))
x_test = x_test.reshape((10000, 28, 28, 1))
y_train, y_test = tf.one_hot(y_train, 10), tf.one_hot(y_test, 10)
print(f"x_train : {x_train[0].shape} | y_train : {y_train[0].shape}")
print(f"x_test : {x_test[0].shape} | y_test : {y_test[0].shape}")
@@ -33,6 +36,8 @@ def get_data_test():
x_test = x_test / 255.0
x_test = x_test.reshape((10000, 28, 28, 1))
y_test = tf.one_hot(y_test, 10)
print(f"x_test : {x_test[0].shape} | y_test : {y_test[0].shape}")
return x_test, y_test
@@ -60,6 +65,7 @@ x_train, y_train = get_data_test()
loss = [
"mse",
"categorical_crossentropy",
"sparse_categorical_crossentropy",
"binary_crossentropy",
"kullback_leibler_divergence",
@@ -84,7 +90,7 @@ if __name__ == "__main__":
c1=0.4,
w_min=0.3,
w_max=0.7,
negative_swarm=0.2,
negative_swarm=0.1,
mutation_swarm=0.2,
)

View File

@@ -59,8 +59,11 @@ def make_model():
model = make_model()
x_train, y_train, x_test, y_test = get_data()
y_train = tf.one_hot(y_train, 10)
y_test = tf.one_hot(y_test, 10)
model.compile(
optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]
optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"]
)
# model.compile(optimizer="adam", loss="mse", metrics=["accuracy"])

File diff suppressed because one or more lines are too long

Binary file not shown.