Код: Выделить всё
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)
Код: Выделить всё
Found 0 images belonging to 0 classes.
Код: Выделить всё
https://www.kaggle.com/datasets/jessicali9530/celeba-dataset
Подробнее здесь: https://stackoverflow.com/questions/792 ... gg16-model
Мобильная версия