AlexNet's authors probed what the network had learned by taking the 4096-dimensional activations of the last hidden layer for a test image and retrieving the training images whose activations were closest in Euclidean distance. Implement the retrieval, and a score for whether the retrieved images share the query's class.
nearest(query, bank, k)
query has shape (D,), bank has shape (M, D). Return the indices (Python ints) of the k rows of bank with the smallest Euclidean distance to query, nearest first; break ties by the lower index.label_agreement(indices, bank_labels, query_label)
indices whose label in bank_labels equals query_label, rounded to 4 decimals.kind="stable") keeps tied rows in index order.