|
|
from PIL import Image |
|
|
import keras |
|
|
import numpy as np |
|
|
import os |
|
|
import tensorflow as tf |
|
|
|
|
|
model = keras.saving.load_model("hf://sensei-ml/Brain_Tumors_Classificator_CNN_Keras_Model") |
|
|
|
|
|
def predict(image_path): |
|
|
image = Image.fromarray(image_path) |
|
|
image = image.convert('L') |
|
|
image = image.resize((150, 150)) |
|
|
img_array = np.array(image) / 255.0 |
|
|
img_array = np.expand_dims(img_array, axis=0) |
|
|
prediction = model.predict(img_array) |
|
|
labels = ['Glioma', 'Meningioma', 'No tumor', 'Pituitary'] |
|
|
probabilities = {label: probability for label, probability in zip(labels, prediction[0])} |
|
|
return probabilities |