From 242bd232a97e8165ce38e145d005b3ee4946828d Mon Sep 17 00:00:00 2001 From: ParikshitGupta2605 Date: Sun, 13 Sep 2026 02:57:26 +0530 Subject: [PATCH] Fix cnn prediction (#14904) * Fix CNN prediction threshold for binary classification * Use ternary operator for binary prediction --------- Co-authored-by: Christian Clauss --- computer_vision/cnn_classification.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/computer_vision/cnn_classification.py b/computer_vision/cnn_classification.py index 115333eba..2cf2de00f 100644 --- a/computer_vision/cnn_classification.py +++ b/computer_vision/cnn_classification.py @@ -94,7 +94,6 @@ if __name__ == "__main__": test_image = np.expand_dims(test_image, axis=0) result = classifier.predict(test_image) # training_set.class_indices - if result[0][0] == 0: - prediction = "Normal" - if result[0][0] == 1: - prediction = "Abnormality detected" + # 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. + prediction = "Normal" if result[0][0] < 0.5 else "Abnormality detected"