-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodels.py
58 lines (44 loc) · 1.95 KB
/
models.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
from keras.models import Sequential
from keras.applications.vgg16 import VGG16
from keras.applications.vgg19 import VGG19
from keras.applications.resnet50 import ResNet50
from keras.applications.inception_v3 import InceptionV3
from keras.layers import Flatten, Dense, GlobalAveragePooling2D
class Models:
def __init__(self, input_shape, classes):
self.input_shape = input_shape
self.classes = classes
self.model = Sequential()
def vgg16(self):
base_model = VGG16(include_top=False, weights='imagenet',
input_shape=self.input_shape)
self.model.add(base_model)
self.model.add(Flatten())
self.model.add(Dense(self.classes, activation='softmax'))
def vgg19(self):
base_model = VGG19(include_top=False, weights='imagenet',
input_shape=self.input_shape)
self.model.add(base_model)
self.model.add(Flatten())
self.model.add(Dense(self.classes, activation='softmax'))
def resnet50(self):
base_model = ResNet50(include_top=False, weights='imagenet',
input_shape=self.input_shape)
self.model.add(base_model)
self.model.add(Flatten())
self.model.add(Dense(self.classes, activation='softmax'))
def inceptionV3(self):
base_model = InceptionV3(include_top=False, weights='imagenet',
input_shape=self.input_shape)
self.model.add(base_model)
self.model.add(GlobalAveragePooling2D())
self.model.add(Dense(self.classes, activation='softmax'))
def compile(self, optimizer):
print(self.model.summary())
self.model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])
def load_weights(self, path):
self.model.load_weights(path)
def save_weights(self, path):
self.model.save_weights(path)
def get_model(self):
return self.model