| --- |
| license: apache-2.0 |
| tags: |
| - trained with 8 images 4 of dog 4 of cat |
| language: |
| - es |
| --- |
| # Model Card for Model ID |
|
|
| <!-- Provide a quick summary of what the model is/does. --> |
|
|
| This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1). |
|
|
| ## Model Details |
|
|
| ### Model Description |
|
|
| <!-- Provide a longer summary of what this model is. --> |
|
|
| trained with 8 images 4 of dog 4 of cat |
|
|
| High effectiveness rate, |
|
|
| fast, effective and light model 💯💯 |
|
|
| ‵‵‵import tensorflow as tf |
| import numpy as np |
| from google.colab import files |
| from PIL import Image |
| import os |
|
|
| # --- PASO 1: CARGAR EL MODELO ENTRENADO --- |
| MODEL_PATH = '/content/modelo_perro_gato.h5' |
| |
| if not os.path.exists(MODEL_PATH): |
| print(f"❌ ERROR: No se encontró el modelo en la ruta: {MODEL_PATH}") |
| print("Por favor, ejecuta primero el script de entrenamiento para generar el archivo del modelo.") |
| else: |
| try: |
| model = tf.keras.models.load_model(MODEL_PATH) |
| print(f"✅ Modelo '{os.path.basename(MODEL_PATH)}' cargado exitosamente.") |
| |
| # --- 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}")‵‵‵ |