[Python] tf.keras.utils.image_dataset_from_directory Found 0 files belonging to 0 classes

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently attempting to develop an image classification model and have organized my data using the following

    DATASET/

    ejercicio1/
    train/
    frames/
    ejercicio1_train_0001.jpg
    ejercicio1_train_0002.jpg
    ...
    test/
    frames/
    ejercicio1_test_0001.jpg
    ejercicio1_test_0002.jpg
    ...
    val/
    frames/
    ejercicio1_val_0001.jpg
    ejercicio1_val_0002.jpg
    ...
    ejercicio2/`'.


    Upon executing my code, the path is correctly identified; however, I receive the message Found 0 files belonging to 0 classes. How could I resolve this issue?

    Here is part of the code (this code uses TensorFlow):

    def create_image_dataset(directory, img_size, batch_size, subset=None, validation_split=None, seed=None):
    directory = os.path.abspath(directory)
    directory = os.path.normpath(directory) # Normalizar la ruta
    print(f"Intentando crear dataset desde: {directory}") # Depuración detallada
    try:
    dataset = tf.keras.utils.image_dataset_from_directory(
    directory,
    labels='inferred',
    label_mode='categorical',
    image_size=img_size,
    batch_size=batch_size,
    shuffle=True if subset == 'training' or validation_split is None else False,
    validation_split=validation_split,
    subset=subset,
    seed=seed
    )
    print(f"Dataset creado con éxito desde: {directory}")
    return dataset
    except ValueError as e:
    print(f"Error al crear dataset desde: {directory}. Error: {e}")
    return None # Importante: devolver None en caso de error

    train_datasets = []
    test_datasets = []
    val_datasets = []
    # Obtiene la lista de nombres de las carpetas de ejercicio
    exercise_names = [d for d in os.listdir(DATASET_DIR) if os.path.isdir(os.path.join(DATASET_DIR, d))]

    # Crea un dataset para cada conjunto (train, test, val) de cada ejercicio
    for exercise in exercise_names:
    train_dir = os.path.join(DATASET_DIR, exercise, TRAIN_DIR_NAME, FRAME_DIR_NAME)
    train_dir = os.path.normpath(train_dir) # Normalizar la ruta
    test_dir = os.path.join(DATASET_DIR, exercise, TEST_DIR_NAME, FRAME_DIR_NAME)
    test_dir = os.path.normpath(test_dir) # Normalizar la ruta
    val_dir = os.path.join(DATASET_DIR, exercise, VAL_DIR_NAME, FRAME_DIR_NAME)
    val_dir = os.path.normpath(val_dir) # Normalizar la ruta

    print(f"Ruta de entrenamiento: {train_dir}")
    print(f"Ruta de prueba: {test_dir}")
    print(f"Ruta de validación: {val_dir}")

    if os.path.exists(train_dir):
    train_dataset = create_image_dataset(train_dir, IMG_SIZE, BATCH_SIZE, seed=SEED)
    if train_dataset:
    train_datasets.append(train_dataset)
    if os.path.exists(test_dir):
    test_dataset = create_image_dataset(test_dir, IMG_SIZE, BATCH_SIZE, seed=SEED)
    if test_dataset:
    test_datasets.append(test_dataset)
    if os.path.exists(val_dir):
    val_dataset = create_image_dataset(val_dir, IMG_SIZE, BATCH_SIZE, seed=SEED)
    if val_dataset:
    val_datasets.append(val_dataset)

    Continue reading...

Compartilhe esta Página