Skip to content

Commit b607f7f

Browse files
Fix CNN prediction threshold for binary classification
1 parent e3b01ec commit b607f7f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

computer_vision/cnn_classification.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
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:
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+
if result[0][0] < 0.5:
98100
prediction = "Normal"
99-
if result[0][0] == 1:
101+
else:
100102
prediction = "Abnormality detected"

0 commit comments

Comments
 (0)