|
import os |
|
import numpy as np |
|
import tensorflow as tf |
|
from tensorflow.keras.preprocessing.image import ImageDataGenerator |
|
from tensorflow.keras.models import load_model |
|
from sklearn.metrics import classification_report, confusion_matrix |
|
import pickle |
|
|
|
|
|
model = load_model("malware_classifier_lime.h5") |
|
|
|
data_dir = 'Malign/extract' |
|
|
|
|
|
with open("cache.pkl", "rb") as f: |
|
num_classes = pickle.load(f) |
|
|
|
|
|
batch_size = 32 |
|
image_size = (200, 200) |
|
|
|
|
|
test_datagen = ImageDataGenerator(rescale=1./255) |
|
|
|
test_generator = test_datagen.flow_from_directory( |
|
data_dir, |
|
target_size=image_size, |
|
batch_size=batch_size, |
|
class_mode='categorical', |
|
shuffle=False |
|
) |
|
|
|
|
|
print("Evaluating the model...") |
|
score = model.evaluate(test_generator) |
|
print("Loss: ", score[0]) |
|
print("Accuracy: ", score[1]) |
|
|
|
|
|
print("Predicting the class labels...") |
|
y_pred = model.predict(test_generator) |
|
y_pred_classes = np.argmax(y_pred, axis=1) |
|
|
|
|
|
print("Classification report:") |
|
print(classification_report(test_generator.classes, y_pred_classes, target_names=test_generator.class_indices.keys())) |
|
|
|
|
|
print("Confusion matrix:") |
|
print(confusion_matrix(test_generator.classes, y_pred_classes)) |
|
|