I'm applying a CNN to classify a given dataset.
My function:
def batch_generator(dataset, input_shape = (256, 256), batch_size = 32):
dataset_images = []
dataset_labels = []
for i in range(0, len(dataset)):
dataset_images.append(cv2.resize(cv2.imread(dataset[i], cv2.IMREAD_COLOR),
input_shape, interpolation = cv2.INTER_AREA))
dataset_labels.append(labels[dataset[i].split('/')[-2]])
return dataset_images, dataset_labels
This function is supposed to be called for every epoch and it should return a unique batch of size 'batch_size' containing dataset_images (each image is 256x256) and corresponding dataset_label from the labels dictionary.
input 'dataset' contains path to all the images, so I'm opening them and resizing them to 256x256. Can someone help me in adding to this code so that is returns the desired batches?
torch.utils.data.DataLoader
rather than writing your own generator.