Get list of true positives, false positives, false negatives and true negatives with tensorflow

Viewed 2337

Here is my work :

  • I have annotated images of "Living" cells (circa 8.000) and images of "Dead" cells (circa 2.000) (+ 800 and 200 for testing set)
  • I am using CNN (with tensorflow and keras) in order to classify images as "Living" or "Dead".
  • I trained my model : validation loss = 0.35, recall = 0.81, accuracy = 0.81.

Here is the problem : how can I get the list of images classified as "Living" or "Dead" so I can check them (maybe some of images are not in the right folder ? Or model has issue with specific type of images ?)

Please, could you let me know if you have any clue in order to solve this issue ?

Kindly yours.

1 Answers

For the case of binary classification you can take difference between the vector of true labels and the predicted labels. The difference vector will contain zeros where it classified correctly, -1 for false positives, 1 for false negatives. You can then for example use np.where to find the indices of false positives and whatnot.

To get the indices of false positives and false negatives etc you can simply do:

import numpy as np 

real = np.array([1,0,0,1,1,1,1,1])
predicted = np.array([1,1,0,0,1,1,0,1])

diff = real-predicted
print('diff: ',diff)

# Correct is 0 
# FP is -1 
# FN is 1
print('Correctly classified: ', np.where(diff == 0)[0])
print('Incorrectly classified: ', np.where(diff != 0)[0])
print('False positives: ', np.where(diff == -1)[0])
print('False negatives: ', np.where(diff == 1)[0])

output:

diff:  [ 0 -1  0  1  0  0  1  0]
Correctly classified:  [0 2 4 5 7]
Incorrectly classified:  [1 3 6]
False positives:  [1]
False negatives:  [3 6]
Related