Kami melatih dengan 15 model Deep Learning yang berbeda untuk
membandingkan yang terbaik terlebih dahulu.
Rincian modelnya (menggunakan weight):
models = { 'Xception': Xception, 'VGG16': VGG16, 'VGG19': VGG19,
'ResNet50V2': ResNet50V2, 'ResNet101': ResNet101, 'ResNet152V2':
ResNet152V2, 'InceptionV3': InceptionV3, 'InceptionResNetV2':
InceptionResNetV2, 'MobileNetV2': MobileNetV2, 'DenseNet201':
DenseNet201, 'NASNetLarge': NASNetLarge, 'EfficientNetB7':
EfficientNetB7, 'EfficientNetV2B3': EfficientNetV2B3,
'ConvNeXtBase': ConvNeXtBase, 'EfficientNetV2M': EfficientNetV2M
}
Dengan parameter:
def create_model(base_model): base_model =
base_model(weights='imagenet', include_top=False,
input_shape=(224, 224, 3)) x = base_model.output x =
GlobalAveragePooling2D()(x) x = Dropout(0.5)(x) x = Dense(1024,
activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(0.01))(x) x =
Dropout(0.5)(x) predictions = Dense(train_generator.num_classes,
activation='softmax')(x) model = Model(inputs=base_model.input,
outputs=predictions) return model
Dan juga dilakukan hyperparameter tuning:
# Hyperparameter tuning and training results = {} for
model_name, model_class in models.items(): print(f"Training
model: {model_name}") model = create_model(model_class)
model.compile(optimizer=Adam(), loss='categorical_crossentropy',
metrics=['accuracy']) # Callbacks early_stopping =
EarlyStopping(monitor='val_loss', patience=10,
restore_best_weights=True) checkpoint =
ModelCheckpoint(os.path.join(model_save_path,
f'{model_name}.h5'), monitor='val_loss', save_best_only=True) #
Training history = model.fit( train_generator, epochs=50,
validation_data=val_generator, callbacks=[early_stopping,
checkpoint] ) # Save the results results[model_name] = history
Hasil evaluasi tiap model dapat dilihat di sini:
| No |
Model |
Test Accuracy |
Test Loss |
Time per Step |
Precision |
Recall |
F1-Score |
| 1 |
Xception |
0.9495 |
0.3311 |
65s |
0.96 |
0.95 |
0.95 |
| 2 |
VGG16 |
0.2744 |
1.3785 |
175s |
0.27 |
0.27 |
0.27 |
| 3 |
VGG19 |
0.2744 |
1.3803 |
224s |
0.27 |
0.27 |
0.27 |
| 4 |
ResNet50V2 |
0.8881 |
0.5388 |
51s |
0.89 |
0.89 |
0.89 |
| 5 |
ResNet101 |
0.2383 |
1.7311 |
104s |
0.24 |
0.24 |
0.24 |
| 6 |
ResNet152V2 |
0.9025 |
0.3728 |
141s |
0.9 |
0.9 |
0.9 |
| 7 |
InceptionV3 |
0.8953 |
0.3549 |
36s |
0.89 |
0.89 |
0.89 |
| 8 |
InceptionResNetV2 |
0.9061 |
0.4424 |
84s |
0.91 |
0.91 |
0.91 |
| 9 |
MobileNetV2 |
0.4332 |
6.3952 |
14s |
0.43 |
0.43 |
0.43 |
| 10 |
DenseNet201 |
0.8845 |
0.4953 |
79s |
0.88 |
0.88 |
0.88 |
| 11 |
NASNetLarge |
0.2888 |
130.9035 |
168s |
0.29 |
0.29 |
0.29 |
| 12 |
EfficientNetB7 |
0.6498 |
1.2851 |
167s |
0.65 |
0.65 |
0.65 |
| 13 |
EfficientNetV2B3 |
0.5343 |
1.4725 |
34s |
0.53 |
0.53 |
0.53 |
| 14 |
EfficientNetV2M |
0.721 |
0.8624 |
81s |
0.72 |
0.72 |
0.72 |
| 15 |
ConvNeXtBase |
0.8225 |
1.3083 |
78s |
0.82 |
0.82 |
0.82 |
Hyperparameter tuning dilakukan untuk setiap model untuk menemukan
kombinasi optimal yang memberikan performa terbaik. Setelah
pelatihan dan evaluasi, dua model dengan performa terbaik (di atas
90% akurasi) ditemukan: Xception dan InceptionResNetV2.