简体   繁体   English

如何在使用 CNN 提取特征的同时使用 SVM 进行分类?

[英]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.

相关问题 如何存储 CNN 提取的特征以训练 SVM 分类器 - How to store CNN extracted features to train a SVM classifier 在CNN提取的功能之上使用SVM-如何进行多类分类? - Using SVM on top of CNN extracted features - How to do Multi-Class classification? 如何使用SVM分类器进行分类? - How to classify using SVM classifier? 如何使用SVM分类每个样本的特征形状是否为矩阵? 是否只是将矩阵重塑为长向量? - how to use SVM to classify if the shape of features for each sample is matrix? Is it simply to reshape the matrix to long vector? 对象检测 - 如何使用CNN检测和提取特征并使用分类器对其进行分类? - Object detection - How to detect and extract features using CNN and classify them using a classifier? 如何使用 SVM 对不平衡数据集进行分类 - How to Classify the imbalanced Dataset using SVM 如何组合从两个 cnn 模型中提取的特征? - How to combine features extracted from two cnn models? 如何将从 ccn1 提取的特征传递给另一个 cnn2? - How to pass features extracted from ccn1 to another cnn2? 在SVM中使用特征之前如何在特征上使用L2规范化 - How to use L2 normalization on features before using them in SVM 我在使用 cnn 对超过 10000 个 class 进行分类时遇到问题。 我该如何解决? - i have a problem while using cnn to classify more then 10000 class. how can i solve it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM