-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (31 loc) · 1.29 KB
/
main.py
File metadata and controls
50 lines (31 loc) · 1.29 KB
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 dog_expert
from dog_expert import DataLoader, Preprocessor
import tensorflow as tf
from dog_expert import models
from tensorflow.keras.optimizers import Adam
import os
import pickle
os.environ["CUDA_VISIBLE_DEVICES"] = "2"
IMAGE_SIZE = (256, 256)
BATCH_SIZE = 8
def main():
with open(r'artifacts/class_mapping.pkl', 'rb') as handle:
class_mapping = pickle.load(handle)
NO_CLASSES = len(class_mapping.keys())
preprocessor = Preprocessor()
preprocessor.cast(dtype=tf.float32).normalize()
data_loader = DataLoader(train_dataset_dir=r'datasets\bing',
val_dataset_dir=r'datasets\stanford', batch_size=BATCH_SIZE,
class_mapping=class_mapping, preprocessor=preprocessor)
train = data_loader.train_dataset
val = data_loader.val_dataset
model = models.Xception(num_classes=NO_CLASSES, image_size=IMAGE_SIZE)
model.compile(loss='categorical_crossentropy', optimizer=Adam(
learning_rate=0.003), metrics=['accuracy'])
history = model.fit(train, validation_data=val,
epochs=50)
model.save('test_model1.h5')
with open('history.pickle', 'wb') as handle:
pickle.dump(history, handle, protocol=pickle.HIGHEST_PROTOCOL)
if __name__ == '__main__':
main()