admin管理员组

文章数量:1024592

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)

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)

本文标签: pythonTrouble loading the celebA dataset for vgg16 modelStack Overflow