-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
84 lines (74 loc) · 3.7 KB
/
model.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from keras import layers
from keras import Sequential
def create_model1(img_height, img_width, num_classes, filters=16, pool_size=2, dense_units=128):
model = Sequential([
layers.Rescaling(1. / 255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(2 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(4 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Flatten(),
layers.Dense(dense_units, activation='relu'),
layers.Dense(num_classes)
])
return model
def create_model2(img_height, img_width, num_classes, filters=32, pool_size=2, dense_units=64):
model = Sequential([
layers.Rescaling(1. / 255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(2 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(4 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Flatten(),
layers.Dense(dense_units, activation='relu'),
layers.Dense(num_classes)
])
return model
def create_model3(img_height, img_width, num_classes, filters=32, pool_size=2, dense_units=256):
model = Sequential([
layers.Rescaling(1. / 255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(2 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(4 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Flatten(),
layers.Dense(dense_units, activation='relu'),
layers.Dense(num_classes)
])
return model
def create_model4(img_height, img_width, num_classes, filters=16, pool_size=2, dense_units=128):
model = Sequential([
layers.Rescaling(1. / 255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(2 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Flatten(),
layers.Dense(dense_units, activation='relu'),
layers.Dense(num_classes)
])
return model
def create_model5(img_height, img_width, num_classes, filters=16, pool_size=2, dense_units=128):
model = Sequential([
layers.Rescaling(1. / 255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(2 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(4 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(8 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Conv2D(16 * filters, 3, padding='same', activation='relu'),
layers.MaxPooling2D(pool_size=pool_size),
layers.Flatten(),
layers.Dense(dense_units, activation='relu'),
layers.Dense(num_classes)
])
return model