Regarding resnet binary predictions

image

I trained my resnet50 model on cat dog dataset which is a binary classification problem. But when I am using it model_resnet.predict(test_it) [‘attached in the photo’].
Labels are binary but predictions are continuous values, due to which I am unable to create a confusion matrix or classification report. What should I do now?

Hi

you may use np.argmax(prediction) to make a classification is binary or discrete values …I hope it help you …or in the last layer of NN use sigmoid activation function to predict binary classification

Please feel free to ask any questions,
Thanks,
Abdelrahman

1 Like

Hey @AbdElRhaman_Fakhry
You Mentioned I should use sigmoid in last layer which is what I have used. I have attached a snap of code where I marked the last sigmoid layer
Please have a look at it at tell me if I have to used sigmoid somewhere else also to get binary output

That should be correct. The point of the previous reply is that the prediction values are just the output of the model: the \hat{y} values, meaning that they are the output of sigmoid. The output of sigmoid is never exactly 0 or 1, right? Well, at least not from a mathematical standpoint. They can actually “saturate” and round to 0 or 1 in floating point.

So if you want to convert the prediction values to “yes/no” answers, you do that by comparing to 0.5, right?

Okay so do you mean to say like there will be threshold for the value of sigmoid if the predicted value is less than threshold set it to 0 else 1. Is that so sir?

Yes, exactly. If \hat{y} > 0.5 then the answer is “yes” and otherwise “no”, right?

We implemented exactly this in the “predict” functions in the Course 1 Week 2 and Week 3 assignments, if you recall.