Skip to content

Commit 242bd23

Browse files
Fix cnn prediction (#14904)
* Fix CNN prediction threshold for binary classification * Use ternary operator for binary prediction --------- Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 2f4a9fe commit 242bd23

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

computer_vision/cnn_classification.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
test_image = np.expand_dims(test_image, axis=0)
9595
result = classifier.predict(test_image)
9696
# training_set.class_indices
97-
if result[0][0] == 0:
98-
prediction = "Normal"
99-
if result[0][0] == 1:
100-
prediction = "Abnormality detected"
97+
# The sigmoid output is a probability in the range [0, 1].
98+
# Use a threshold of 0.5 to convert the probability into a binary prediction.
99+
prediction = "Normal" if result[0][0] < 0.5 else "Abnormality detected"

0 commit comments

Comments
 (0)