tf-keras icon indicating copy to clipboard operation
tf-keras copied to clipboard

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

Open Kyogre67 opened this issue 1 year ago • 1 comments
trafficstars

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

Kyogre67 avatar Aug 03 '24 17:08 Kyogre67

@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!

tilakrayal avatar Aug 12 '24 07:08 tilakrayal

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] avatar Aug 27 '24 01:08 github-actions[bot]

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

github-actions[bot] avatar Sep 10 '24 01:09 github-actions[bot]