From b607f7fe8239b87e47274a85f59558e1607fc25f Mon Sep 17 00:00:00 2001 From: Parikshit Date: Mon, 6 Jul 2026 18:27:37 +0530 Subject: [PATCH] Fix CNN prediction threshold for binary classification --- computer_vision/cnn_classification.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/computer_vision/cnn_classification.py b/computer_vision/cnn_classification.py index 115333eba0d1..08f824dd46b8 100644 --- a/computer_vision/cnn_classification.py +++ b/computer_vision/cnn_classification.py @@ -94,7 +94,9 @@ test_image = np.expand_dims(test_image, axis=0) result = classifier.predict(test_image) # training_set.class_indices - if result[0][0] == 0: + # The sigmoid output is a probability in the range [0, 1]. + # Use a threshold of 0.5 to convert the probability into a binary prediction. + if result[0][0] < 0.5: prediction = "Normal" - if result[0][0] == 1: + else: prediction = "Abnormality detected"