Here is the simplest form of the ImageDataGenerator class you can use to read in your images. # Main directory that includes training and validation directories main_dir = 'dataset' training_path = os.path.join(main_dir,'training') validation_path = os.path.join(main_dir,'validation') CHANNEL = 3 # Keep it 3 for colored images, make it 1 for grayscale batch_size = 8 # Change it depending on your dataset size # Image sizes depend on your preference and the model's requirements IMG_HEIGHT = 64 IMG_WIDTH = 64 You can keep my defaults that I provided below or change them depending on your needs. Then, declare these configuration variables. The image filenames are not important in the above example, but directory names have to be consistent.Ĭreate a file named training.py at the same level with the ‘dataset’ directory, as shown above, and import these: import tensorflow as tf from import ImageDataGenerator import os Organize your dataset in the following way: dataset/ |-training/ |-cats/ |-cat1.jpg |-cat2.jpg |. You can obviously arrange the proportions depending on how large your dataset is. Assuming you have 10,000 images, my suggestion would be to set aside 8,000 for training and 2,000 for validation. Let’s say you are doing binary classification, meaning you have two classes, and following the mainstream example of cats and dogs. You have to organize your images into folders with a certain structure. TensorFlow’s ImageDataGenerator class is a great way to read your dataset and perform data augmentation, but it is not really straightforward.
0 Comments
Leave a Reply. |