here’s my model
JavaScript
x
10
10
1
model=Sequential()
2
model.add(Xception(weights='imagenet',input_shape=(224,224,3),include_top=False))
3
model.add(GlobalAveragePooling2D())
4
model.add(Dense(4096,activation='relu',name='fc1'))
5
model.add(Dense(4096,activation='relu',name='fc2'))
6
model.add(Dense(1000,activation='relu',name='fc3'))
7
model.add(Dropout(0.5))
8
model.add(Dense(1,activation='sigmoid',name='fc4'))
9
model.layers[0].trainable=False
10
i want to make svm classifier as my final classifier in this model so how can i do that? also another question i want to know the predicted class of a certain input so when i use
JavaScript
1
2
1
model.predict(x_test)
2
it only gives me probabilities so how can i solve that too
Advertisement
Answer
You can use neural network as feature extractor and take outputs from last layer into your SVM. Try following:
JavaScript
1
24
24
1
model=Sequential()
2
model.add(Xception(weights='imagenet',input_shape=(224,224,3),include_top=False))
3
model.add(GlobalAveragePooling2D())
4
model.add(Dense(4096,activation='relu',name='fc1'))
5
model.add(Dense(4096,activation='relu',name='fc2'))
6
model.add(Dense(1000,activation='relu',name='fc3'))
7
model.add(Dropout(0.5))
8
model.add(Dense(1,activation='sigmoid',name='fc4'))
9
10
model.compile(loss="categorical_crossentropy", optimizer="adam")
11
model.summary()
12
13
model.fit(X,y, epochs=10)
14
15
model.pop() # this will remove the last layer
16
model.summary() # check the network
17
18
feature_mapping = model(X)
19
20
from sklearn import svm
21
22
clf = svm.SVC()
23
clf.fit(feature_mapings, y)
24