이제 모델을 컴파일하고 훈련시킵니다.
코드 8-21 모델 컴파일
model.compile(loss='binary_crossentropy',
optimizer=tf.keras.optimizers.Adam(1e-4), metrics=['accuracy'])
history = model.fit(train_batches, epochs=5, validation_data=test_batches,
validation_steps=30)
다음은 모델의 훈련을 출력한 결과입니다.
Epoch 1/5
2500/2500 [==============================] - 1665s 666ms/step - loss: 0.5494 - accuracy: 0.7013 - val_loss: 0.3577 - val_accuracy: 0.8600
Epoch 2/5
2500/2500 [==============================] - 1898s 759ms/step - loss: 0.3166 - accuracy: 0.8791 - val_loss: 0.4395 - val_accuracy: 0.8433
Epoch 3/5
2500/2500 [==============================] - 1889s 756ms/step - loss: 0.2472 - accuracy: 0.9105 - val_loss: 0.4011 - val_accuracy: 0.8267
Epoch 4/5
2500/2500 [==============================] - 1730s 692ms/step - loss: 0.2044 - accuracy: 0.9292 - val_loss: 0.3639 - val_accuracy: 0.8700
Epoch 5/5
2500/2500 [==============================] - 1802s 721ms/step - loss: 0.1698 - accuracy: 0.9428 - val_loss: 0.3939 - val_accuracy: 0.8600