最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python - Trouble loading the celebA dataset for vgg16 model - Stack Overflow

matteradmin9PV0评论

Im trying to use the celeba dataset for a vgg16 model, however when I try to run this code

import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input
from tf_explain.core.grad_cam import GradCAM
import matplotlib.pyplot as plt
import numpy as np
import os

# Set path for validation datasets (update these paths accordingly)
val_dir = '/content/drive/MyDrive/Datasets/img_align_celeba'

# Define the image size VGG16 expects
target_size = (224, 224)

# Define ImageDataGenerator for validation data
val_datagen = ImageDataGenerator(
    rescale=1./255,  # Normalize pixel values to [0, 1]
    preprocessing_function=preprocess_input  # VGG16 preprocessing
)

# Create the validation generator
val_generator = val_datagen.flow_from_directory(
    val_dir,
    target_size=target_size,
    batch_size=32,  # You can adjust batch size
    class_mode='categorical',  # Assuming categorical labels (one-hot encoded)
    shuffle=False  # We don't shuffle in the validation set
)

# Fetch a batch of validation images
X_val, y_val = next(val_generator)

I get the error

Found 0 images belonging to 0 classes. 

there are no subdirectories the img_align_celeba folder, just images. link to dataset:


I have extracted the zip and just uploaded a folder containing the images? Need some guidance on how to work with this dataset.

Im trying to use the celeba dataset for a vgg16 model, however when I try to run this code

import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input
from tf_explain.core.grad_cam import GradCAM
import matplotlib.pyplot as plt
import numpy as np
import os

# Set path for validation datasets (update these paths accordingly)
val_dir = '/content/drive/MyDrive/Datasets/img_align_celeba'

# Define the image size VGG16 expects
target_size = (224, 224)

# Define ImageDataGenerator for validation data
val_datagen = ImageDataGenerator(
    rescale=1./255,  # Normalize pixel values to [0, 1]
    preprocessing_function=preprocess_input  # VGG16 preprocessing
)

# Create the validation generator
val_generator = val_datagen.flow_from_directory(
    val_dir,
    target_size=target_size,
    batch_size=32,  # You can adjust batch size
    class_mode='categorical',  # Assuming categorical labels (one-hot encoded)
    shuffle=False  # We don't shuffle in the validation set
)

# Fetch a batch of validation images
X_val, y_val = next(val_generator)

I get the error

Found 0 images belonging to 0 classes. 

there are no subdirectories the img_align_celeba folder, just images. link to dataset:

https://www.kaggle/datasets/jessicali9530/celeba-dataset

I have extracted the zip and just uploaded a folder containing the images? Need some guidance on how to work with this dataset.

Share Improve this question asked Nov 18, 2024 at 16:19 Jasmine Jasmine 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

actual size of those images 178x218, not 224x224. Replace this target_size = (224, 224) by target_size = (178, 218)

Post a comment

comment list (0)

  1. No comments so far