keras-team / tf-keras

The TensorFlow-specific implementation of the Keras API, which was the default Keras from 2019 to 2023.
Apache License 2.0
59 stars 28 forks source link

keras.preprocessing.image_dataset_from_directory() No images found in directory #790

Closed Kyogre67 closed 3 days ago

Kyogre67 commented 1 month ago
import matplotlib.pyplot as plt
import numpy as np
import random
from PIL import Image
import tensorflow
from tensorflow import keras
from keras import layers, preprocessing, Sequential
from sklearn.neighbors import KernelDensity
import glob

class CustomImageDataset:
    def __init__(self, directory, image_size, batch_size, label_mode):
        self.dataset = tensorflow.keras.preprocessing.image_dataset_from_directory(
            directory,
            image_size=image_size,
            batch_size=batch_size,
            label_mode=label_mode
        )
        self.label_mode = label_mode

    def __iter__(self):
        return iter(self.dataset)

    def __len__(self):
        return len(self.dataset)

    def map(self, *args, **kwargs):
        return self.dataset.map(*args, **kwargs)

    def batch(self, *args, **kwargs):
        return self.dataset.batch(*args, **kwargs)

    def prefetch(self, *args, **kwargs):
        return self.dataset.prefetch(*args, **kwargs)

SIZE = 8

batch_size = 64

train_generator = preprocessing.image_dataset_from_directory(
    r'C:\Users\{}\Downloads\archive (1)\noncloud_train',    
    image_size=(SIZE, SIZE),
    batch_size=batch_size,
    labels=None
)

validation_generator = preprocessing.image_dataset_from_directory(
    r'C:\Users\{}\Downloads\archive (1)\noncloud_test',
    image_size=(SIZE, SIZE),
    batch_size=batch_size,
    labels=None
)

anomaly_generator = CustomImageDataset(
    r'C:\Users\{}\Downloads\archive (1)\cloud',
    image_size=(SIZE, SIZE),
    batch_size=batch_size,
    labels=None

No images found within the directory unless labels=None. My folder organization is correct, it looks like this:

archive (1) -- cloud ---- files.jpeg -- noncloud_train ---- files.jpeg -- noncloud_test ---- files.jpeg

tilakrayal commented 1 month ago

@Kyogre67, I tried to execute the mentioned code and faced the different error. Kindly find the gist of it here and provide the complete dependencies. Also please let us know the tensorflow and the Keras version you are trying to use. Thank you!

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 3 days ago

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.