File size: 729 Bytes
d60e533
e0801ac
d60e533
e0801ac
62eca9a
962d630
05aedf9
d60e533
 
d5cf581
c4011fa
 
6059147
d22fd20
672a9ff
837f07f
a0f5a83
4766918
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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')  # Use grayscale images
    image = image.resize((150, 150))  # Resize to 150 x 150 px.
    img_array = np.array(image) / 255.0  # Normalize pixel values
    img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension
    prediction = model.predict(img_array)
    labels = ['Glioma', 'Meningioma', 'No tumor', 'Pituitary']
    probabilities = {label: probability for label, probability in zip(labels, prediction[0])}
    return probabilities