forked from tfriedel/neural-image-assessment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_generators.py
29 lines (21 loc) · 1.3 KB
/
data_generators.py
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
from image_preprocessing import ImageDataGenerator, randomCropFlips, \
centerCrop
generator = ImageDataGenerator(preprocessing_function=randomCropFlips())
batch_size = 64
def get_batches(x, y, gen=generator, shuffle=True, batch_size=batch_size,):
return gen.flow_from_filelist(x, y,
shuffle=shuffle, batch_size=batch_size, image_size=image_size,
cropped_image_size=cropped_image_size)
# save_to_dir=r's:/temp/genimg', save_format='jpg')
generator_valid = ImageDataGenerator(preprocessing_function=centerCrop())
def get_batches_valid(x, y, gen=generator_valid, shuffle=False,
batch_size=batch_size,
image_size=PRE_CROP_IMAGE_SIZE, cropped_image_size=IMAGE_SIZE):
return gen.flow_from_filelist(x, y,
shuffle=shuffle, batch_size=batch_size, image_size=image_size,
cropped_image_size=cropped_image_size)
# save_to_dir=r's:/temp/genimg', save_format='jpg')
train_generator = get_batches(dataset.train_image_paths, dataset.train_scores,
batch_size=batch_size)
validation_generator = get_batches_valid(dataset.test_image_paths, dataset.test_scores,
batch_size=batch_size)