def run_index_pred_eval(args): t0 = time() run_index(args) t1 = time() run_pred(args) t2 = time() evaluate_recall(args) print('run_index: %.1f mins, run_pred: %.1f mins' % ((t1 - t0) / 60, (t2 - t1) / 60))
def evaluation(feature_set, label_set, k_set=[1, 2, 4, 8, 16, 32], distance_type=None): if distance_type == 'cosine': squared_feature_set = np.sqrt(np.sum(np.power(feature_set, 2), axis=1, keepdims=True)) distM = np.divide(np.matmul(feature_set, np.transpose(feature_set, (1, 0))), np.matmul(squared_feature_set, np.transpose(squared_feature_set, (1, 0)))) distM = 1. - distM elif distance_type == "Euclidean": distM = distance.cdist(feature_set, feature_set) nn_av, ft_av, st_av, dcg_av, e_av, map_, p_points, pre, rec, rankArray = RetrievalEvaluation.RetrievalEvaluation(distM, label_set, label_set, testMode=2) recall_k = evaluate_recall.evaluate_recall(feature_set, label_set, k_set) for i, k in enumerate(k_set): print("Recall@{:1d}: {:6.5f}".format(k_set[i], recall_k[i])) normalized_mutual_information, RI, F = evaluate_clustering.evaluate_clustering(feature_set, label_set) print("") print("normalized_mutual_information = {}".format(normalized_mutual_information)) print("RI = {}".format(RI)) print("F_1 = {}".format(F)) print("") print(('The NN is {:5.5f}\nThe FT is {:5.5f}\n' + 'The ST is {:5.5f}\nThe DCG is {:5.5f}\n' + 'The E is {:5.5f}\nThe MAP {:5.5f}\n').format( nn_av, ft_av, st_av, dcg_av, e_av, map_)) rec = np.expand_dims(rec, axis=1) pre = np.expand_dims(pre, axis=1) rec_pre = np.concatenate([rec, pre], axis=1) return rec_pre
def evaluate_online(self, sess, test_mode=1): if test_mode == 1: train_feature_set, train_label_set = \ get_feature_and_label(self.train_init_op, sess, self.features, self.labels) test_feature_set, test_label_set = \ get_feature_and_label(self.test_init_op, sess, self.features, self.labels) distM = distance.cdist(test_feature_set, train_feature_set) nn_av, ft_av, st_av, dcg_av, e_av, map_, p_points, pre, rec, rankArray = RetrievalEvaluation.RetrievalEvaluation( distM, train_label_set, test_label_set, testMode=1) elif test_mode == 2: batch_num = int(self.test_img_num / self.batch_size) + 2 test_feature_set, test_label_set = \ self.get_feature_and_label(self.test_init_op, sess, self.features, self.labels, batch_num) distM = distance.cdist(test_feature_set, test_feature_set) nn_av, ft_av, st_av, dcg_av, e_av, map_, p_points, pre, rec, rankArray = RetrievalEvaluation.RetrievalEvaluation( distM, test_label_set, test_label_set, testMode=2) recall_k = evaluate_recall.evaluate_recall(test_feature_set, test_label_set, self.k_set) for i, k in enumerate(self.k_set): print("Recall@{:1d}: {:6.5f}".format(self.k_set[i], recall_k[i])) normalized_mutual_information, RI, F = evaluate_clustering.evaluate_clustering( test_feature_set, test_label_set) print("") print("normalized_mutual_information = {}".format( normalized_mutual_information)) print("RI = {}".format(RI)) print("F_1 = {}".format(F)) print("") print(('The NN is {:5.5f}\nThe FT is {:5.5f}\n' + 'The ST is {:5.5f}\nThe DCG is {:5.5f}\n' + 'The E is {:5.5f}\nThe MAP {:5.5f}\n').format( nn_av, ft_av, st_av, dcg_av, e_av, map_))
def evaluate(self, sess, test_mode=2): ckpt = self.get_checkpoint_file() sess.run(tf.global_variables_initializer()) if ckpt is None: raise IOError("No check point file found") else: self.saver.restore(sess, ckpt.model_checkpoint_path) def get_feature_and_label(init_op, sess, feature_tensor, label_tensor): feature_set = [] label_set = [] counter = 0 sess.run(init_op) while True: try: features, labels = sess.run( [self.features, self.labels], feed_dict={self.is_training: False}) counter += 1 print("Processing the {:3d}-th batch".format(counter)) except tf.errors.OutOfRangeError: break feature_set.append(features) label_set.append(labels) feature_set = np.concatenate(feature_set, axis=0) label_set = np.concatenate(label_set, axis=0) return feature_set, label_set if test_mode == 1: train_feature_set, train_label_set = \ get_feature_and_label(self.train_init_op, sess, self.features, self.labels) test_feature_set, test_label_set = \ get_feature_and_label(self.test_init_op, sess, self.features, self.labels) distM = distance.cdist(test_feature_set, train_feature_set) nn_av, ft_av, st_av, dcg_av, e_av, map_, p_points, pre, rec, rankArray = RetrievalEvaluation.RetrievalEvaluation( distM, train_label_set, test_label_set, testMode=1) elif test_mode == 2: test_feature_set, test_label_set = \ get_feature_and_label(self.test_init_op, sess, self.features, self.labels) distM = distance.cdist(test_feature_set, test_feature_set) nn_av, ft_av, st_av, dcg_av, e_av, map_, p_points, pre, rec, rankArray = RetrievalEvaluation.RetrievalEvaluation( distM, test_label_set, test_label_set, testMode=2) recall_k = evaluate_recall.evaluate_recall(test_feature_set, test_label_set, self.k_set) for i, k in enumerate(self.k_set): print("Recall@{:1d}: {:6.5f}".format(self.k_set[i], recall_k[i])) normalized_mutual_information, RI, F = evaluate_clustering.evaluate_clustering( test_feature_set, test_label_set) print("") print("normalized_mutual_information = {}".format( normalized_mutual_information)) print("RI = {}".format(RI)) print("F_1 = {}".format(F)) print("") print(('The NN is {:5.5f}\nThe FT is {:5.5f}\n' + 'The ST is {:5.5f}\nThe DCG is {:5.5f}\n' + 'The E is {:5.5f}\nThe MAP {:5.5f}\n').format( nn_av, ft_av, st_av, dcg_av, e_av, map_))