Classifier Activation function issue
abacus-A opened this issue · 4 comments
I am getting the following error when I use sigmoid in CNN training since real and fake detection is binary problem but I am unable to use sigmoid can you please guide why only softmax is working.
ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (2,)
Input: (70, 128, 128, 3) (30, 128, 128, 3) (70, 2) (30, 2)
error
predictions = Dense(
1,
activation="sigmoid",
kernel_initializer="he_uniform")(
headModel
)
correct
predictions = Dense(
2,
activation="softmax",
kernel_initializer="he_uniform")(
headModel
)
Your input should be 1d of targets if you are using sigmoid. For softmax, it's 70,2. for sigmoid it should be (70,1) [ 1 1 0 1] . this the error
Thank you for the clarification. Last thing I want to ask in feature_extractor.py You are extracting spatial features for recurrence networks training using Transfer Learning (of Xception Model) in which you have used weights of which were trained on train_CNN.py(fine tuned). Can the feature_extractor.py extract features without these weights by using imagenet weights or do we get a shape error. If you explain this scenario it will save a lot of training time for me. In short I think feature_extractor.py file depends on train_CNN.py file ? Thank you.
You can directly extract the features but intuitively as you mentioned Xception Net is trained on imagenet weights. Images in that dataset are not similar to face images. That's where finetuning and train_CNN role comes into play. Shift the weights to learn more about image faces. I didn't try that but you can try directly. It's an interesting approach. But it should not work. Domain learning matters very much. Spatial content learnt by imagenet weights is different and what content it's seeing that's different.
Hi, I have checked but still got confused in the following issue in feature_extractor_lstm file. I am using xception model overall I hope you can guide,
model = Model(inputs=baseModel.input, outputs=predictions)
model.load_weights("trained_wts/" + weights + ".hdf5")
print("Weights loaded...")
model_lstm = Model(
inputs=baseModel.input,
outputs=model.get_layer("fc1").output
)
for layer in baseModel.layers:
layer.trainable = True
Since we have loaded the weights from train_cnn.py which are finetuned then is it necessary to run layer.trainable = True in 05.feature_extractor.py what if we put layer.trainable = False. Please guide. Thank you currently I am using the code for cnn+lstm for extraction and classification after