|
|
import tensorflow as tf
|
|
|
from PIL import Image
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model("modelo_skin_cancer final.h5")
|
|
|
|
|
|
|
|
|
def preprocess(image):
|
|
|
image = image.convert("RGB")
|
|
|
image = image.resize((300, 300))
|
|
|
image_array = np.array(image) / 255.0
|
|
|
image_array = np.expand_dims(image_array, axis=0)
|
|
|
return image_array
|
|
|
|
|
|
|
|
|
def predict(image):
|
|
|
image = preprocess(image)
|
|
|
prediction = model.predict(image)[0][0]
|
|
|
label = "Maligno" if prediction > 0.5 else "Benigno"
|
|
|
return { "label": label, "confidence": float(prediction) }
|
|
|
|