조기 수렴 시 파티클 리셋 적용
모델의 초기화 수정 => 랜덤값은 문제가 많음
미니배치 초기화 시 자동 shuffle 적용
negative 파티클 특정 수치마다 초기화
This commit is contained in:
jung-geun
2023-10-20 05:47:25 +09:00
parent 6c6aa221f8
commit 6e838ddfd5
7 changed files with 167 additions and 73 deletions

View File

@@ -33,34 +33,18 @@ def get_data():
return x_train, y_train, x_test, y_test
def get_data_test():
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_test = x_test / 255.0
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)
x_train, x_test = tf.convert_to_tensor(
x_train), tf.convert_to_tensor(x_test)
y_train, y_test = tf.convert_to_tensor(
y_train), tf.convert_to_tensor(y_test)
print(f"x_test : {x_test[0].shape} | y_test : {y_test[0].shape}")
return x_test, y_test
def make_model():
model = Sequential()
model.add(
Conv2D(32, kernel_size=(5, 5), activation="sigmoid",
input_shape=(28, 28, 1))
)
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, kernel_size=(3, 3), activation="sigmoid"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dropout(0.25))
model.add(Dense(256, activation="sigmoid"))
model.add(Dense(128, activation="sigmoid"))
model.add(Dense(10, activation="softmax"))
@@ -107,15 +91,19 @@ loss = [
pso_mnist = optimizer(
model,
loss="mean_squared_error",
n_particles=600,
n_particles=900,
c0=0.2,
c1=0.4,
w_min=0.3,
w_max=0.5,
negative_swarm=0.05,
mutation_swarm=0.3,
particle_min=-4,
particle_max=4,
particle_min=-0.3,
particle_max=0.3,
early_stopping=True,
early_stopping_patience=10,
early_stopping_monitor="loss",
early_stopping_min_delta=0.0005,
)
best_score = pso_mnist.fit(
@@ -130,7 +118,7 @@ best_score = pso_mnist.fit(
check_point=25,
empirical_balance=False,
dispersion=False,
batch_size=32,
batch_size=1024,
)
print("Done!")