Created
June 22, 2020 06:06
-
-
Save maskaravivek/7173fbc93554b3de58067faa249e5020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow import keras | |
class My_Custom_Generator(keras.utils.Sequence): | |
def __init__(self, images, labels, batch_size): | |
self.images = images | |
self.labels = labels | |
self.batch_size = batch_size | |
def __len__(self) : | |
return (np.ceil(len(self.images) / float(self.batch_size))).astype(np.int) | |
def __getitem__(self, idx) : | |
batch_x = self.images[idx * self.batch_size : (idx+1) * self.batch_size] | |
batch_y = self.labels[idx * self.batch_size : (idx+1) * self.batch_size] | |
train_image = [] | |
train_label = [] | |
for i in range(0, len(batch_x)): | |
img_path = batch_x[i] | |
label = batch_y[i] | |
# read method takes image path and label and returns corresponding matrices | |
image, label_matrix = read(img_path, label) | |
train_image.append(image) | |
train_label.append(label_matrix) | |
return np.array(train_image), np.array(train_label) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment