Views
No views yet
# --- PASO 2: SUBIR IMAGEN Y REALIZAR PREDICCIÓN ---
print("\nPor favor, sube una imagen de un perro o un gato:")
uploaded = files.upload()
# Procesar la imagen subida
for filename in uploaded.keys():
print(f"\nProcesando imagen: '{filename}'...")
# Cargar y preprocesar la imagen
img = tf.keras.utils.load_img(filename, target_size=(224, 224))
img_array = tf.keras.utils.img_to_array(img)
img_array_expanded = np.expand_dims(img_array, axis=0)
# Es importante aplicar el mismo preprocesamiento que durante el entrenamiento
preprocessed_img = tf.keras.applications.efficientnet.preprocess_input(img_array_expanded)
# Realizar la predicción
prediction = model.predict(preprocessed_img)
score = prediction[0][0]
# Decodificar y mostrar el resultado final
if score < 0.5:
clase_predicha = "GATO"
confianza = 100 * (1 - score)
else:
clase_predicha = "PERRO"
confianza = 100 * score
print("\n" + "="*30)
print(f" RESULTADO: ¡ES UN {clase_predicha}!")
print(f" Confianza: {confianza:.2f}%")
print("="*30)
except Exception as e:
print(f"❌ Ocurrió un error inesperado: {e}")‵‵‵