-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
36 lines (22 loc) · 841 Bytes
/
generator.py
File metadata and controls
36 lines (22 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import imageio
import math
import tensorflow as tf
import numpy as np
class DataGenerator(tf.keras.utils.Sequence):
def __init__ (self, x_set, y_set, batch_size):
self.x_set = x_set
self.y_set = y_set
self.batch_size = batch_size
def __len__(self):
return math.ceil(len(self.x_set) / self.batch_size)
def __getitem__(self, idx):
batch_x = self.x_set[idx * self.batch_size : (idx + 1) * self.batch_size]
batch_y = self.y_set[idx * self.batch_size : (idx + 1) * self.batch_size]
x_images = np.asarray([imageio.imread(path) for path in batch_x], dtype='float32') / 255.
y_images = np.asarray([imageio.imread(path) for path in batch_y], dtype='float32') / 255.
return (x_images, y_images)
def on_epoch_end(self, ):
pass # insert shuffling
if __name__ == '__main__':
pass