-
Notifications
You must be signed in to change notification settings - Fork 18
/
prepare_data.py
50 lines (43 loc) · 2.37 KB
/
prepare_data.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import tensorflow as tf
import config
def get_datasets():
# Preprocess the dataset
train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rescale=1.0 / 255.0
)
train_generator = train_datagen.flow_from_directory(config.train_dir,
target_size=(config.image_height, config.image_width),
color_mode="rgb",
batch_size=config.BATCH_SIZE,
seed=1,
shuffle=True,
class_mode="categorical")
valid_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rescale=1.0 /255.0
)
valid_generator = valid_datagen.flow_from_directory(config.valid_dir,
target_size=(config.image_height, config.image_width),
color_mode="rgb",
batch_size=config.BATCH_SIZE,
seed=7,
shuffle=True,
class_mode="categorical"
)
test_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rescale=1.0 /255.0
)
test_generator = test_datagen.flow_from_directory(config.test_dir,
target_size=(config.image_height, config.image_width),
color_mode="rgb",
batch_size=config.BATCH_SIZE,
seed=7,
shuffle=True,
class_mode="categorical"
)
train_num = train_generator.samples
valid_num = valid_generator.samples
test_num = test_generator.samples
return train_generator, \
valid_generator, \
test_generator, \
train_num, valid_num, test_num