# Custom label with image\_dataset\_from\_directory

**URL:** <https://discuss.ai.google.dev/t/custom-label-with-image-dataset-from-directory/28108>\
**Category:** General Discussion\
**Tags:** tfimage, datasets\
**Created:** [April 24, 2024, 3:37am UTC](https://discuss.ai.google.dev/t/custom-label-with-image-dataset-from-directory/28108 "2024-04-24T03:37:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pupu](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/pupu/32/6797_2.png) [@pupu](https://discuss.ai.google.dev/u/pupu)\
**Post date:** [April 24, 2024, 3:37am UTC](https://discuss.ai.google.dev/t/custom-label-with-image-dataset-from-directory/28108/1 "2024-04-24T03:37:10Z")

</div>

I wanted to change label from multi class to binary class (0,1) eg. class 1 or the rest. Is there any way to change the label with tf.keras.utils.image\_dataset\_from\_directory  
My image are in structure like this  
class 1  
image1  
image2  
…  
class 2  
image1  
image2  
…  
…  
class 100  
image1  
image2  
…

my code:

train\_dataset = tf.keras.utils.image\_dataset\_from\_directory(train\_dir,  
shuffle=False,  
batch\_size=batch\_size,  
image\_size=imgage\_size,  
labels = ‘inferred’,  
seed = 1  
)

---

<div class="post-metadata">

**Author:** ![Kiran\_Sai\_Ramineni](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kiran_sai_ramineni/32/8859_2.png) [@Kiran\_Sai\_Ramineni](https://discuss.ai.google.dev/u/Kiran_Sai_Ramineni)\
**Post date:** [April 29, 2024, 7:41am UTC](https://discuss.ai.google.dev/t/custom-label-with-image-dataset-from-directory/28108/3 "2024-04-29T07:41:26Z")

</div>

Hi @pupu, Generally image\_dataset\_from\_directory loads the data based on the directory structure. while loading the multi class data I don’t think it is possible to convert that to a binary class. One way is to rearrange the directory structure having 2 classes. Thank You.
