Spaces:
Build error
Build error
File size: 925 Bytes
1f47b1e e58a7b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import cv2
import numpy as np
import tensorflow as tf
from tensorflow import keras
def predict_glaucoma(image_path, model_path):
# Carrega o modelo de classificação
model = keras.models.load_model(model_path)
# Lê a imagem do arquivo temporário
input_image = cv2.imread(image_path, cv2.IMREAD_COLOR)
# Redimensiona a imagem para 256x256 pixels
resize_width = 256
resize_height = 256
input_image = cv2.resize(input_image, (resize_width, resize_height))
# Normaliza os valores de pixel da imagem
input_image = input_image.astype(np.float32) / 255.0
# Converte a imagem para escala de cinza
input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)
# Faz a previsão do modelo
input_tensor = np.expand_dims(input_image, axis=(0, -1))
prediction = model.predict(input_tensor)[0][0]
return prediction
|