I tried to run a cnn model on my data and it gives me high accuracy. Then i tried to extract the features from the first dense layer and feed it into svm classifier, but unfortunately the validation accuracy is very high and the testing is 50% although the validation data and testing data are the same in my case. can you help me please
And here is part of my code:
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)