Using SVM as final layer in Convolutional Neural Network

I am working on the implementation of a hybrid CNN-SVM, where I define the use of SVM in the last layer of CNN as shown in this code:

# Flattening
cnn.add(tf.keras.layers.Flatten())
# Full Connection
cnn.add(tf.keras.layers.Dense(units=128, activation='relu'))
cnn.add(Dense(4, kernel_regularizer=tf.keras.regularizers.l2(0.01),activation
             ='softmax'))
cnn.compile(optimizer = 'adam', loss = 'squared_hinge', metrics = ['accuracy'])

In the case of CNN (without adding SVM), we can define the last part of CNN as below:

def calculate_softmax(data):
    result = np.exp(data)
    return result
softmax = calculate_softmax(temp)
prediction = softmax.argmax()

where temp is the input data for softmax

I wanted to do the same thing when using SVM with the last layer but I could not find any hint?

Topic softmax cnn svm

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.