Skip to content

Instantly share code, notes, and snippets.

@tnarihi
Last active August 29, 2015 14:28
Show Gist options
  • Save tnarihi/9d807c993d7f30d112bf to your computer and use it in GitHub Desktop.
Save tnarihi/9d807c993d7f30d112bf to your computer and use it in GitHub Desktop.
import numpy as np
from sklearn.metrics import confusion_matrix
preds = ()
labels = ()
n_samples = ... number of examples in test set ...
batch_size = ... batch size ...
net = ... caffe test net ...
n_batch = int(np.ceil(n_samples / batch_size))
for i in range(n_batch):
net.forward()
score, label = net.blobs['fc8'], net.blobs['label']
pred = score.argmax(axis=1)
preds += pred,
labels ++ label,
preds = np.vstack(preds)[:n_samples]
labels = np.vstack(labels)[:n_samples]
cm = confusion_matrix(labels.flatten(), preds.flatten())
plt.figure()
plt.imshow(cm, interpolation='nearest', cmap=plt.jet)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment