-
Notifications
You must be signed in to change notification settings - Fork 7
/
main_train_your_own.py
60 lines (42 loc) · 1.57 KB
/
main_train_your_own.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
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 23 18:08:34 2020
@author: craig
"""
from keras_segmentation.models.unet import vgg_unet
from keras_segmentation.predict import model_from_checkpoint_path
model = vgg_unet(n_classes=51 , input_height=416, input_width=608 )
model=model_from_checkpoint_path("weights/vgg_unet_1")
model.train(
train_images = "dataset1/images_prepped_train/",
train_annotations = "dataset1/annotations_prepped_train/",
val_images="dataset1/images_prepped_test/" ,
val_annotations="dataset1/annotations_prepped_test/",
verify_dataset=True,
# load_weights="weights/vgg_unet_1.4" ,
optimizer_name='adadelta' , do_augment=True , augmentation_name="aug_all",
checkpoints_path = "weights/vgg_unet_1" , epochs=10
)
# Display the model's architecture
model.summary()
# Save the entire model to a HDF5 file.
# The '.h5' extension indicates that the model should be saved to HDF5.
model.save('vgg_unet_1.h5')
#predict an image from the training data
out = model.predict_segmentation(
checkpoints_path="weights/vgg_unet_1" ,
inp="dataset1/images_prepped_test/43.jpg",
out_fname="newout.png"
)
from keras_segmentation.predict import predict_multiple
predict_multiple(
checkpoints_path="weights/vgg_unet_1" ,
inp_dir="dataset1/images_prepped_test/" ,
out_dir="weights/out/"
)
#import matplotlib.pyplot as plt
#plt.imshow(out)
#
## evaluating the model
#print(model.evaluate_segmentation( inp_images_dir="dataset1/images_prepped_test/" , annotations_dir="dataset1/annotations_prepped_test/" ) )