text_plain_output_1.png image_output_1.png
from sklearn.metrics import accuracy_score

from sklearn.metrics import classification_report

from tensorflow.keras.models import load_model

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import os

import os

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import random

import seaborn as sns

import tensorflow as tf

import numpy as np
import pandas as pd
import os

model = load_model('../input/efficientnetv2transfer/model-18-fine_after.h5')

def set_seed(seed=200):
    tf.random.set_seed(seed)
    np.random.seed(seed)
    random.seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
set_seed(0)

x_test = np.load('../input/pneumonia-xray-datagen-np/x_test.npy')
y_test = np.load('../input/pneumonia-xray-datagen-np/y_test.npy')

test_evalu = model.evaluate(x_test, y_test)

def check(labels, predictions):
    cmx = tf.math.confusion_matrix(labels, predictions, num_classes=None, weights=None, dtype=tf.dtypes.int32, name=None)
    target_names = ['Normal', 'Pneumonia']
    df_cmx = pd.DataFrame(np.array(cmx), index=target_names, columns=target_names)

Y_pred = model.predict(x_test)
y_pred = Y_pred.reshape(Y_pred.shape[0]).tolist()
cut = 0.5
for i in range(len(y_pred)):
    if y_pred[i] >= cut:
        y_pred[i] = 1
    else:
        y_pred[i] = 0
check(y_test, y_pred)