| 110 | return recall_nums, one_percent_recall, running_time |
| 111 | |
| 112 | def get_recall(self, database_feature, queries_feature, num_neighbors=30): |
| 113 | database_output = database_feature |
| 114 | queries_output = queries_feature |
| 115 | |
| 116 | database_nbrs = KDTree(database_output) |
| 117 | # num_neighbors = (int)(queries_feature.shape[0]*0.01) |
| 118 | recall = [0] * num_neighbors |
| 119 | |
| 120 | top1_similarity_score = [] |
| 121 | one_percent_retrieved = 0 |
| 122 | threshold = max(int(round(len(database_output) / 100.0)), 1) |
| 123 | |
| 124 | num_evaluated = 0 |
| 125 | topk_dict = {} |
| 126 | top_recalls = np.zeros(num_neighbors+2) |
| 127 | |
| 128 | for i in range(len(queries_output)): |
| 129 | |
| 130 | true_neighbors = [i] |
| 131 | if len(true_neighbors) == 0: |
| 132 | continue |
| 133 | num_evaluated += 1 |
| 134 | |
| 135 | distances, indices = database_nbrs.query(np.array([queries_output[i]]), k=num_neighbors) |
| 136 | # indices = np.setdiff1d(indices[0], [i]) |
| 137 | indices = indices[0] |
| 138 | |
| 139 | for j in range(0, len(indices)): |
| 140 | if indices[j] in true_neighbors: |
| 141 | if (j == 0): |
| 142 | similarity = np.dot(queries_output[i], database_output[indices[j]]) |
| 143 | top1_similarity_score.append(similarity) |
| 144 | recall[j] += 1 |
| 145 | break |
| 146 | |
| 147 | if len(list(set(indices[0:threshold]).intersection(set(true_neighbors)))) > 0: |
| 148 | one_percent_retrieved += 1 |
| 149 | |
| 150 | for recall_num in range(num_neighbors): |
| 151 | if len(list(set(indices[0:recall_num+1]).intersection(set(true_neighbors)))) > 0: |
| 152 | top_recalls[recall_num] += 1 |
| 153 | |
| 154 | top_recalls[-2] = one_percent_retrieved |
| 155 | top_recalls[-1] = num_evaluated |
| 156 | one_percent_recall = (one_percent_retrieved / float(num_evaluated)) * 100 |
| 157 | top_one_recall = (top_recalls[0] / float(num_evaluated)) * 100 |
| 158 | top_five_recall = (top_recalls[4] / float(num_evaluated)) * 100 |
| 159 | top_ten_recall = (top_recalls[9] / float(num_evaluated)) * 100 |
| 160 | recall = (np.cumsum(recall) / float(num_evaluated)) * 100 |
| 161 | |
| 162 | return (top_one_recall, top_five_recall, top_ten_recall), \ |
| 163 | top_recalls, \ |
| 164 | top1_similarity_score, one_percent_recall |
| 165 | |
| 166 | @staticmethod |
| 167 | def apply_noise(pcd, mu=0, sigma=0.1): |