tengo este modelo hecho paara reconocer digitos del 0 al 99 import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import numpy as np
import os
import pandas as pd
from PIL import Image
import csv

#def cargar_datos(folder, target_size=(28, 28)):
#    images = []
#    labels = []
#
#    images_folder = os.path.join(folder, 'images')
#    labels_folder = os.path.join(folder, 'labels')
#
#   for filename in os.listdir(images_folder):
#        # Cargar imagen y ajustar tamaño
#        img_path = os.path.join(images_folder, filename)
#        with Image.open(img_path) as img:
#            img_resized = img.resize(target_size)
#            images.append(np.array(img_resized))

        # Cargar etiqueta desde el archivo CSV
#        label_filename = f"{filename.split('.')[0]}.txt"
#        label_path = os.path.join(labels_folder, label_filename)

#        with open(label_path, newline='') as label_file:
#            reader = csv.DictReader(label_file)
#            # Aquí, asumimos que la columna 'label' contiene la información que necesitas
#            label_data = int(next(reader)['label'])
#            labels.append(label_data)

#    return np.array(images), np.array(labels)

def create_cnn_model(input_shape=(28, 56, 1)):
    model = Sequential()

    model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(Conv2D(64, kernel_size=(3, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))

    model.add(Flatten())
    model.add(Dense(512, activation="relu"))
    model.add(Dropout(0.5))
    model.add(Dense(100, activation="softmax"))

    return model


def main():
    # Cargar los datos
    script_dir = os.path.dirname(__file__)

    #data = np.load('mnist_object.npz')

    #X_train, y_train, y_train_bboxes, X_test, y_test, y_test_bboxes =  data['train_images'], data['train_labels'], data['train_bboxes'], data['test_images'], data['test_labels'], data['test_bboxes']

    #X_train.astype("float32") / 255

    data = np.load('mnist_compressed.npz')

    X_test, y_test, X_train, y_train =  data['test_images'], data['test_labels'], data['train_images'], data['train_labels']

    X_train.astype("float32") / 255
    # Muestra las dimensiones de los conjuntos de entrenamiento y prueba
    print("Dimensiones del conjunto de entrenamiento:", X_train.shape, y_train.shape)
    print("Dimensiones del conjunto de prueba:", X_test.shape, y_test.shape)

   # Rutas a las carpetas de train y test
    train_folder = os.path.join(script_dir, 'mnist_detection', 'train')
    test_folder = os.path.join(script_dir, 'mnist_detection', 'test')

    # Resto del código...

    # Cargar los datos
    #train_images, train_labels = cargar_datos(train_folder)
    #train_images = train_images.astype("float32") / 255
   # test_images, test_labels = cargar_datos(test_folder)
    #test_images = test_images.astype("float32") / 255

    #datagen = ImageDataGenerator(rotation_range=10, zoom_range=0.1, width_shift_range=0.1, height_shift_range=0.1)
    #datagen.fit(x_train.reshape(-1, 28, 28, 1))

    # Crear el modelo
    model = create_cnn_model()

    # Compilar el modelo
    model.compile(loss="sparse_categorical_crossentropy", optimizer=tf.keras.optimizers.Adam(learning_rate=0.0005), metrics=["accuracy"])

    # Entrenar el modelo
    model.fit(X_train, y_train, epochs=5)

    # Guardar el modelo en un archivo
    model.save('models/mlpMNIST.h5')

    # Evaluar el modelo
    score = model.evaluate(X_test, y_test, verbose=0)
    print("Pérdida:", score[0])
    print("Precisión:", score[1])

if __name__ == "__main__":
    main()