▷ 오늘 학습 계획: 딥러닝 강의(4~6)
출력값과 학습 데이터의 오차로 델타 함수를 만들어서 가중치 변경
Backpropagation
from tensorflow.keras import Sequential, layers, models
from sklearn.metrics import classification_report, confusion_matrix
model = models.Sequential([
# Convolutional은 보통 strides(1,1)
# kernel_size (5,5), (3,3) 많이 사용함
layers.Conv2D(32, kernel_size=(5,5), strides=(1,1), padding='same',
activation='relu', input_shape=(150,150,1)),
layers.MaxPooling2D(pool_size=(2,2), strides=(2,2)),
# 보통 pool size랑 동일하게 strides
layers.Conv2D(64, (2,2), activation='relu', padding='same'),
# 채널을 늘려서 더 많은 특성 관찰
layers.MaxPooling2D(pool_size=(2,2)),
layers.Dropout(0.25),
layers.Flatten(),
layers.Dense(1000, activation='relu'),
layers.Dense(1, activation='sigmoid'), # 마지막 출력값에 대한 설정
])
model.compile(
optimizer='adam', loss=tf.keras.losses.BinaryCrossentropy(),
metrics=['accuracy']
)
X_train = X_train.reshape(len(X_train), X_train.shape[1], X_train.shape[2], 1)
# X_train = X_train.reshape(-1, 150, 150, 1)
X_val = X_val.reshape(len(X_val), X_val.shape[1], X_val.shape[2], 1)
# X_val = X_val.reshape(-1, 150, 150, 1)
history = model.fit(X_train, y_train, epochs=4, batch_size=32)
model.evaluate(X_val, y_val)
model.predict(X_val)
prediction = (model.predict(X_val) > 0.5).astype('int32')
print(classification_report(y_val, prediction))
print(confusion_matrix(y_val, prediction))
▷ 내일 학습 계획: 딥러닝 강의(7~10)
[이 글은 제로베이스 데이터 취업 스쿨의 강의 자료 일부를 발췌하여 작성되었습니다.]