-
Notifications
You must be signed in to change notification settings - Fork 0
/
estimators.py
155 lines (122 loc) · 4.3 KB
/
estimators.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from tensorflow.keras import layers, models, optimizers
from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.applications.vgg19 import VGG19
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.applications.resnet_v2 import ResNet50V2
from tensorflow.keras.applications.xception import Xception
from tensorflow.keras.applications.inception_v3 import InceptionV3
from sklearn.ensemble import GradientBoostingClassifier
import tensorflow as tf
input_shape = (128, 128, 3)
tensor = tf.keras.Input(input_shape)
def create_cnn():
model = models.Sequential()
model.add(layers.Conv2D(32, (4, 4), activation="relu"))
model.add(layers.Conv2D(32, (4, 4), activation="relu"))
model.add(layers.Conv2D(32, (4, 4), activation="relu"))
model.add(layers.MaxPooling2D(pool_size=(2, 2)))
model.add(layers.Dropout(0.25))
model.add(layers.Flatten())
model.add(layers.Dense(128, activation="relu"))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(1, activation="sigmoid"))
model.compile(
loss="binary_crossentropy",
optimizer=optimizers.RMSprop(lr=1e-4),
metrics=["acc"],
)
return model
def create_vgg16():
conv_base = VGG16(weights="imagenet", include_top=False, input_shape=input_shape)
model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(256, activation="relu"))
model.add(layers.Dense(1, activation="sigmoid"))
conv_base.trainable = False
model.compile(
loss="binary_crossentropy",
optimizer=optimizers.RMSprop(lr=1e-4),
metrics=["acc"],
)
return model
def create_vgg19():
conv_base = VGG19(weights="imagenet", include_top=False, input_shape=input_shape)
model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(256, activation="relu"))
model.add(layers.Dense(1, activation="sigmoid"))
conv_base.trainable = False
model.compile(
loss="binary_crossentropy",
optimizer=optimizers.RMSprop(lr=0.0001),
metrics=["acc"],
)
return model
def create_resnet50():
conv_base = ResNet50(weights="imagenet", include_top=False, input_shape=input_shape)
model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(256, activation="relu"))
model.add(layers.Dense(1, activation="sigmoid"))
conv_base.trainable = False
model.compile(
loss="binary_crossentropy",
optimizer=optimizers.RMSprop(lr=1e-4),
metrics=["acc"],
)
return model
def create_resnet50v2():
conv_base = ResNet50V2(
weights="imagenet", include_top=False, input_shape=input_shape
)
model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(256, activation="relu"))
model.add(layers.Dense(1, activation="sigmoid"))
conv_base.trainable = False
model.compile(
loss="binary_crossentropy",
optimizer=optimizers.RMSprop(lr=1e-4),
metrics=["acc"],
)
return model
def create_xception():
conv_base = Xception(weights="imagenet", include_top=False, input_shape=input_shape)
model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(256, activation="relu"))
model.add(layers.Dense(1, activation="sigmoid"))
conv_base.trainable = False
model.compile(
loss="binary_crossentropy",
optimizer=optimizers.RMSprop(lr=1e-4),
metrics=["acc"],
)
return model
def create_inceptionv3():
conv_base = InceptionV3(
weights="imagenet", include_top=False, input_shape=input_shape
)
model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(256, activation="relu"))
model.add(layers.Dense(1, activation="sigmoid"))
conv_base.trainable = False
model.compile(
loss="binary_crossentropy",
optimizer=optimizers.RMSprop(lr=1e-4),
metrics=["acc"],
)
return model