我试图对数据运行一个cnn模型,它给了我很高的准确性。然后,我尝试从第一个密集层中提取特征并将其输入到svm分类器中,但是不幸的是,尽管我的情况下验证数据和测试数据相同,但验证准确性非常高,并且测试率为50%。 你能帮我吗
这是我的代码的一部分:
TrainingData = Read_Images("D:/[0] PHD/[0]X-Rays/[7] Datasets/MURA-v1.1/MURA-HAND/HAND-TRAIN.csv")
TrainingData = np.array(TrainingData)
TestingData = Read_Images("D:/[0] PHD/[0]X-Rays/[7] Datasets/MURA-v1.1/MURA-HAND/HAND-TEST.csv")
TestingData = np.array(TestingData)
#to get the output from specific layer
from keras.models import Model
model = model # include here your original model
layer_name = 'dense_1'
intermediate_layer_model = Model(inputs=model.input,outputs=model.get_layer(layer_name).output)
intermediate_output_training = intermediate_layer_model.predict(TrainingData)
intermediate_output_testing = intermediate_layer_model.predict(TestingData)
#Import svm model
from sklearn import svm
#Create a svm Classifier
clf = svm.SVC(kernel='linear') # Linear Kernel
#Train the model using the training sets
clf.fit(intermediate_output_training, trainLabels)
#Predict the response for test dataset
y_pred = clf.predict(intermediate_output_testing)