DHEIVER commited on
Commit
e58a7b5
·
1 Parent(s): 8fded84

Create predict_glaucoma.py

Browse files
Files changed (1) hide show
  1. predict_glaucoma.py +28 -0
predict_glaucoma.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow import keras
5
+
6
+ def predict_glaucoma(image_path, model_path):
7
+ # Carrega o modelo de classificação
8
+ model = keras.models.load_model(model_path)
9
+
10
+ # Lê a imagem do arquivo temporário
11
+ input_image = cv2.imread(image_path, cv2.IMREAD_COLOR)
12
+
13
+ # Redimensiona a imagem para 256x256 pixels
14
+ resize_width = 256
15
+ resize_height = 256
16
+ input_image = cv2.resize(input_image, (resize_width, resize_height))
17
+
18
+ # Normaliza os valores de pixel da imagem
19
+ input_image = input_image.astype(np.float32) / 255.0
20
+
21
+ # Converte a imagem para escala de cinza
22
+ input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)
23
+
24
+ # Faz a previsão do modelo
25
+ input_tensor = np.expand_dims(input_image, axis=(0, -1))
26
+ prediction = model.predict(input_tensor)[0][0]
27
+
28
+ return prediction