INNER CODE UNIT · Python
softmax_scores_batch
haitongli/knowledge-distillation-pytorch · distillation_analysis.py:47
softmax_scores_batch = F.softmax(output_batch/temperature, dim=1)
softmax_scores_batch = softmax_scores_batch.data.cpu().numpy()
softmax_scores.append(softmax_scores_batch)
# extract data from torch Variable, move to cpu, convert to numpy arrays
output_batch = output_batch.data.cpu().numpy()
labels_batch = labels_batch.data.cpu().numpy()
predict_correct_batch = (np.argmax(output_batch, axis=1) == labels_batch).astype(int)
predict_correct.append(np.reshape(predict_correct_batch, (labels_batch.size, 1)))
t.update()
softmax_scores = np.vstack(softmax_scores)
predict_correct = np.vstack(predict_correct)
return softmax_scores, predict_correct, confusion_matrix.value().astype(int)