-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrain.py
43 lines (33 loc) · 1.12 KB
/
train.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
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from model import ResNetV2
def main():
model = ResNetV2()
model.build(input_shape=(None, 52, 52, 1))
print(model.summary())
train_datagen = ImageDataGenerator(
samplewise_center=True,
samplewise_std_normalization=True,
rotation_range=30,
width_shift_range=0.1,
height_shift_range=0.1)
test_datagen = ImageDataGenerator(
samplewise_center=True,
samplewise_std_normalization=True)
train_generator = train_datagen.flow_from_directory(
'train',
color_mode ='grayscale',
target_size=(52, 52),
batch_size = 32)
test_generator = test_datagen.flow_from_directory(
'test',
color_mode ='grayscale',
target_size=(52, 52),
batch_size = 32)
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit_generator(
train_generator,
epochs=15,
validation_data=test_generator)
model.save_weights('resnet_model2.h5')
if __name__ == "__main__":
main()