It seems very easy with Python:
(1) load your network
(2) forward_all your dataset, blobs=['your_last_layer_name']
(3) the return value is a dict, take your_last_layer_name value which is a matrix (list of feature vectors)
(4) compute distances between your image feature and the rest of features, take top-k, where k=6 in this paper.