-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_edited_vgg16_model.py
45 lines (27 loc) · 1.13 KB
/
create_edited_vgg16_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
import keras
from keras.models import Sequential
from keras.layers import Activation
from keras.layers.core import Dense, Flatten
from keras.optimizers import Adam
from keras.metrics import categorical_crossentropy
from keras.layers.normalization import BatchNormalization
from keras.layers.convolutional import *
import matplotlib.pyplot as plt
from keras.utils import plot_model
#vgg16_model = keras.applications.vgg16.VGG16()
vgg16_model = keras.applications.vgg16.VGG16(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
#vgg16_model.summary()
model = Sequential()
for layer in vgg16_model.layers:
model.add(layer)
model.layers.pop()
for layer in model.layers:
layer.trainable = True
model.add(Dense(6, activation='linear')) #or linear
#compile model before saving
#model.compile(Adam(lr=.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
#model.compile(Adam(lr=.0001), loss='mean_squared_error', metrics=['accuracy'])
model.save('vgg16_edit.h5')
model.summary()
plot_model(model, to_file='model.png')
print('\n\n**********************\nModel saved')