'SVM as a last layer of a CNN

I am new to the community and I am trying to learn as much as possible but I came to a point where I need help because I don't manage to find the right solution.

I have a CNN with a softmax layer at the end but I would like to have an SVM and I really don't know how to do it. I found something online saying that basically, I have to change from softmax to linear but I don't understand why and since I don't understand I can not do it.

If anyone knows how to do it please can you let me know how to do it with the code below? Thank you and sorry if this question was asked before or if you find it not that smart. I am new to this.

Code below:

    model = keras.models.Sequential([    
    keras.layers.Conv2D(filters=16, kernel_size=(3,3), activation='relu', input_shape=(IMG_HEIGHT,IMG_WIDTH,channels)),
    keras.layers.Conv2D(filters=32, kernel_size=(3,3), activation='relu'),
    keras.layers.MaxPool2D(pool_size=(2, 2)),
    keras.layers.BatchNormalization(axis=-1),
    
    keras.layers.Conv2D(filters=64, kernel_size=(3,3), activation='relu'),
    keras.layers.Conv2D(filters=128, kernel_size=(3,3), activation='relu'),
    keras.layers.MaxPool2D(pool_size=(2, 2)),
    keras.layers.BatchNormalization(axis=-1),
    
    keras.layers.Flatten(),
    keras.layers.Dense(512, activation='relu'),
    keras.layers.BatchNormalization(),
    keras.layers.Dropout(rate=0.5),
    
    keras.layers.Dense(43, activation='softmax')
])


Solution 1:[1]

You don't need any layers after a flatten layer.Now use this model to extract a feature vector for xtrain and xtest for svm . Refer: YouTube channel digitalsreeni

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shilash M