0

I am working on an image dataset that has 12 classes. Therefore, I have split the dataset manually (by hand) into three subfolders i.e. train, valid, and test in 70%, 15%, and 15% respectively. However, I want to split them by code for train, valid, and test 70%, 15%, and 15% and transfer them to the subfolder in a train, valid, and test folder

#--------------------------------------------------Train--------------------------------
train = ImageDataGenerator()

train_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale= 1./255, rotation_range=90, width_shift_range=0.1,height_shift_range=0.1, shear_range=0.2, zoom_range=0.2,
                        horizontal_flip=True, fill_mode="nearest")

train_data = train_generator.flow_from_directory(directory="/content/dataset/train",target_size=IMAGE_SHAPE , color_mode="rgb" , class_mode='categorical', batch_size=BATCH_SIZE , shuffle = True )

#--------------------------------------------------valid-------------------------------
valid = ImageDataGenerator()
validation_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
valid_data = validation_generator.flow_from_directory(directory="/content/dataset/validation", target_size=IMAGE_SHAPE , color_mode="rgb" , class_mode='categorical' , batch_size=BATCH_SIZE , shuffle = True )

#--------------------------------------------------Test---------------------------------------------
test = ImageDataGenerator()
test_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
test_data = test_generator.flow_from_directory(directory="/content/dataset/test",target_size=IMAGE_SHAPE , color_mode="rgb" , class_mode='categorical' , batch_size=1 , shuffle = False )
test_data.reset()

It is possible to write the code for spiting them send it to the 3 several folders?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • 4
    I think this question has answers your are looking for. From there you can save the variables to a file if you wish. https://stackoverflow.com/questions/38250710/how-to-split-data-into-3-sets-train-validation-and-test – KillerToilet Mar 25 '21 at 16:22
  • 1
    In Tensorflow, use `tfds.Split` to split the dataset into train, test and validation dataset.For more information on the library find [here](https://www.tensorflow.org/datasets/api_docs/python/tfds/Split). Thanks! –  Mar 31 '21 at 03:30

0 Answers0