[英]How to use SVM to classify while the features are extracted using CNN?
conv12 = Conv2D(32, (3, 3), activation='relu', padding='same')(up12)
conv12 = Dropout(0.3)(conv12)
conv12 = Conv2D(32, (3, 3), activation='relu', padding='same')(conv12)
conv13 = Conv2D(1, (1, 1), activation='sigmoid')(conv12)
model = Model(inputs=[inputs], outputs=[conv13])
model.compile(optimizer=Adam(lr=.00045), loss=dice_coef_loss, metrics=[dice_coef])
return model
After the conv13 layer i want to use SVM, how can i do that?在 conv13 层之后我想使用 SVM,我该怎么做? I am new to this and can't figure this out.
我对此很陌生,无法弄清楚。
Your neural network produces an output given an input (an image I assume).给定输入(我假设的图像),您的神经网络会生成 output。 This output, as you set it to be the parameters from the
conv13
layer, will be a vector of a certain size.这个output,当你把它设置为
conv13
层的参数时,将是一个一定大小的向量。 You can now consider this output as input for your SVM classifier.您现在可以将此 output 视为 SVM 分类器的输入。 However, you do not need to stick to
Keras
for this step, as libraries like scikit-learn
have implemented an easier way to do that.但是,您不需要在此步骤中坚持使用
Keras
,因为像scikit-learn
这样的库已经实现了一种更简单的方法来做到这一点。
Let's say your CNN produces a set of vectors like X =[95, 25, ..., 45, 24]
as output.假设您的 CNN 生成一组向量,例如
X =[95, 25, ..., 45, 24]
作为 output。 If you then have a set of labels y = {0, 1}
then you can do:如果你有一组标签
y = {0, 1}
那么你可以这样做:
from sklearn.svm import SVC
clf = SVC() # Play with hyperparameters.
clf.predict([[95, 25, ..., 45, 24]]) # Output: array([1])
See: https://scikit-learn.org/stable/modules/svm.html请参阅: https://scikit-learn.org/stable/modules/svm.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.