PNG warning
Hey @markub3327,

It seems like the issue arose because you used `color_mode="grayscale"` with `tf.keras.utils.image_dataset_from_directory`, but your dataset has RGBA images. Try switching it to `color_mode="rgba"`

Check out the documentation [here](https://www.tensorflow.org/api_docs/python/tf/keras/utils/image_dataset_from_directory) for more info.

Hope this clears things up! Hello, @aditya02shah 

  loaded images are combination of RGBA and Grayscale images. I need to unified it to grayscale during loading by `tf.keras.utils.image_dataset_from_directory`. 

| Args      |  |
| ----------- | ----------- |
| color_mode | One of "grayscale", "rgb", "rgba". Defaults to "rgb". Whether the images will be converted to have 1, 3, or 4 channels. |

The `color_mode` set as `grayscale` should be convert all types of images to 1 channel (grayscale) !!!

Thanks for understanding.
 @markub3327 I would recommend converting all the images to the same format, preferably Grayscale, to ensure uniformity. This can be achieved by implementing a preprocessing function to convert the images during loading. 
Once all images are in the same format, you can use them as needed for your requirements. @aditya02shah 
The preprocessing function is applied after creating the dataset by `tf.keras.utils.image_dataset_from_directory`. After that I can use `.map` API call. @markub3327,
I was facing a different issue while executing the above provided code. Could you please provide the complete code and the dependencies which helps e=debug the issue in an effective way. Kindly find the [gist](https://colab.research.google.com/gist/tilakrayal/d9e4362fd2620f3c99535d0aeb1f6c0d/untitled1726.ipynb). Thank you The provided code is a part of huge project. I cannot send more, but the error what you mention is:

> /usr/local/lib/python3.10/dist-packages/tensorflow/python/lib/io/file_io.py in list_directory_v2(path)
>     766   """
>     767   if not is_directory(path):
> --> 768     raise errors.NotFoundError(
>     769         node_def=None,
>     770         op=None,
> 
> NotFoundError: Could not find directory /code/dataset/train_dataset

This error is about path to folder with images contained in dataset. The images are combinations of RGBA and Grayscale (mode = L and mode = RGBA by Pillow). I cannot provide the whole dataset of images here. Please try to model this situation.

Thanks. Certainly! The code you've provided appears to be related to setting up a **TensorFlow image dataset** for training and validation. Let's break it down:

1. **`tf.keras.utils.image_dataset_from_directory`**:
   - This function creates a dataset from image files in a directory.
   - It takes the following parameters:
     - `"/code/dataset/train_dataset"`: The path to the directory containing your training images.
     - `validation_split=0.1`: Specifies that 10% of the data will be used for validation.
     - `subset="both"`: Includes both training and validation subsets.
     - `image_size=(128, 128)`: Resizes the images to 128x128 pixels.
     - `interpolation="bicubic"`: Interpolation method for resizing.
     - `batch_size=None`: The batch size (you can set this to a specific value).
     - `color_mode="grayscale"`: Converts images to grayscale.
     - `shuffle=True`: Shuffles the dataset.
     - `seed=123`: Sets a random seed for reproducibility.

2. **`preprocessing` function**:
   - This function normalizes the pixel values of the images.
   - It clips the values between 0 and 1.
   - The function is applied to each image in the dataset using `map`.

3. **Data Processing Steps**:
   - The dataset is shuffled (`train_ds.shuffle(1024)`).
   - Batches are created (`train_ds.batch(config.batch_size, drop_remainder=True)`).
   - Data is prefetched for efficient loading (`train_ds.prefetch(tf.data.AUTOTUNE)`).

4. **Model Training**:
   - The `model.fit` function trains the model using the training dataset (`train_ds`).
   - It specifies the number of epochs (`config.epochs`) and uses the validation dataset (`val_ds`) for validation during training.

Remember to replace `config.batch_size` and `config.epochs` with actual values from your configuration. If you have any further questions or need additional assistance, feel free to ask! 😊 import tensorflow as tf

# Assume you have a dataset of image files in "/path/to/images"
image_dir = "/path/to/images"

# Create a dataset from image files
train_ds = tf.keras.utils.image_dataset_from_directory(
    image_dir,
    validation_split=0.1,  # 10% for validation
    subset="training",
    image_size=(128, 128),
    batch_size=32,
    color_mode="grayscale",
    shuffle=True,
    seed=123,
)

# Define a preprocessing function
def preprocessing(image, label):
    # Normalize pixel values to [0, 1]
    image = tf.clip_by_value(tf.cast(image, dtype=tf.float32) / 255.0, 0.0, 1.0)
    return image, label

# Apply the preprocessing function to each image in the dataset
train_ds = train_ds.map(preprocessing, num_parallel_calls=tf.data.AUTOTUNE)

# Shuffle the dataset
train_ds = train_ds.shuffle(1024)

# Create batches
batch_size = 64
train_ds = train_ds.batch(batch_size, drop_remainder=True)

# Prefetch for efficient loading
train_ds = train_ds.prefetch(tf.data.AUTOTUNE)

# Now you can use this preprocessed dataset for training your model!
In this example:

We load image files from a directory using image_dataset_from_directory.
The preprocessing function normalizes pixel values.
We shuffle the dataset, create batches, and prefetch data for training.
Feel free to adapt this code to your specific use case! 😊





 @ChrisnaMishra 

Yes, you explain it correctly. The only one issues is a warning: `W tensorflow/core/lib/png/png_io.cc:88] PNG warning: iCCP: profile 'ICC Profile': 'GRAY': Gray color space not permitted on RGB PNG` @markub3327,
Apologies for the delay. looks like this issue is more related to Keras. Could you please raise the issue in [keras-team/Keras](https://github.com/keras-team/keras/issues) repo for the keras3.0 or [keras-team/tf-keras](https://github.com/keras-team/tf-keras/issues) for the tf-keras. Thank you!
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

binary

### TensorFlow version

2.15

### Custom code

Yes

### OS platform and distribution

Ubuntu 22.04

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I created dataset using `tf.keras.utils.image_dataset_from_directory`. When I fitting the model with this dataset I gets a warning about color space. My images have Pillow mode: **L** and **RGBA** and the resulted dataset is grayscale.

Where is the issue?

### Standalone code to reproduce the issue

```shell
train_ds, val_ds = tf.keras.utils.image_dataset_from_directory(
    "/code/dataset/train_dataset",
    validation_split=0.1,  # 90% training, 10% validation
    subset="both",
    image_size=(128, 128),
    interpolation="bicubic",
    batch_size=None,
    color_mode="grayscale",
    shuffle=True,
    seed=123,
)

def preprocessing(image, label):
    # normalize
    image = tf.clip_by_value(tf.cast(image, dtype=tf.float32) / 255.0, 0.0, 1.0)
    return image, label

train_ds = train_ds.map(
    preprocessing, num_parallel_calls=tf.data.AUTOTUNE
)
train_ds = train_ds.shuffle(1024)
train_ds = train_ds.batch(config.batch_size, drop_remainder=True)
train_ds = train_ds.prefetch(tf.data.AUTOTUNE)

model.fit(
    train_ds,
    epochs=config.epochs,
    validation_data=val_ds,      
)
```


### Relevant log output

```shell
W tensorflow/core/lib/png/png_io.cc:88] PNG warning: iCCP: profile 'ICC Profile': 'GRAY': Gray color space not permitted on RGB PNG
```
