import numpy as np import matplotlib.pyplot as plt from PIL import Image from tensorflow.keras.models import load_model model = load_model('my_model.keras') model.summary() def predict(img_path): class_dict = {'glioma': 0, 'meningioma': 1, 'notumor': 2, 'pituitary': 3} label = list(class_dict.keys()) plt.figure(figsize=(12, 12)) img = Image.open(img_path) resized_img = img.resize((299, 299)) img = np.asarray(resized_img) img = np.expand_dims(img, axis=0) img = img / 255 predictions = model.predict(img) probs = list(predictions[0]) labels = label plt.subplot(2, 1, 1) plt.imshow(resized_img) plt.subplot(2, 1, 2) bars = plt.barh(labels, probs) plt.xlabel('Olasılık', fontsize=15) ax = plt.gca() ax.bar_label(bars, fmt = '%.2f') plt.show() predict("Testing/notumor/Te-no_0010.jpg")