(motion_loaders, file)
| 31 | |
| 32 | |
| 33 | def evaluate_matching_score(motion_loaders, file): |
| 34 | match_score_dict = OrderedDict({}) |
| 35 | R_precision_dict = OrderedDict({}) |
| 36 | activation_dict = OrderedDict({}) |
| 37 | # print(motion_loaders.keys()) |
| 38 | print('========== Evaluating Matching Score ==========') |
| 39 | for motion_loader_name, motion_loader in motion_loaders.items(): |
| 40 | all_motion_embeddings = [] |
| 41 | score_list = [] |
| 42 | all_size = 0 |
| 43 | matching_score_sum = 0 |
| 44 | top_k_count = 0 |
| 45 | # print(motion_loader_name) |
| 46 | with torch.no_grad(): |
| 47 | for idx, batch in enumerate(motion_loader): |
| 48 | word_embeddings, pos_one_hots, _, sent_lens, motions, m_lens, _ = batch |
| 49 | text_embeddings, motion_embeddings = eval_wrapper.get_co_embeddings( |
| 50 | word_embs=word_embeddings, |
| 51 | pos_ohot=pos_one_hots, |
| 52 | cap_lens=sent_lens, |
| 53 | motions=motions, |
| 54 | m_lens=m_lens |
| 55 | ) |
| 56 | dist_mat = euclidean_distance_matrix(text_embeddings.cpu().numpy(), |
| 57 | motion_embeddings.cpu().numpy()) |
| 58 | matching_score_sum += dist_mat.trace() |
| 59 | |
| 60 | argsmax = np.argsort(dist_mat, axis=1) |
| 61 | top_k_mat = calculate_top_k(argsmax, top_k=3) |
| 62 | top_k_count += top_k_mat.sum(axis=0) |
| 63 | |
| 64 | all_size += text_embeddings.shape[0] |
| 65 | |
| 66 | all_motion_embeddings.append(motion_embeddings.cpu().numpy()) |
| 67 | |
| 68 | all_motion_embeddings = np.concatenate(all_motion_embeddings, axis=0) |
| 69 | matching_score = matching_score_sum / all_size |
| 70 | R_precision = top_k_count / all_size |
| 71 | match_score_dict[motion_loader_name] = matching_score |
| 72 | R_precision_dict[motion_loader_name] = R_precision |
| 73 | activation_dict[motion_loader_name] = all_motion_embeddings |
| 74 | |
| 75 | print(f'---> [{motion_loader_name}] Matching Score: {matching_score:.4f}') |
| 76 | print(f'---> [{motion_loader_name}] Matching Score: {matching_score:.4f}', file=file, flush=True) |
| 77 | |
| 78 | line = f'---> [{motion_loader_name}] R_precision: ' |
| 79 | for i in range(len(R_precision)): |
| 80 | line += '(top %d): %.4f ' % (i+1, R_precision[i]) |
| 81 | print(line) |
| 82 | print(line, file=file, flush=True) |
| 83 | |
| 84 | return match_score_dict, R_precision_dict, activation_dict |
| 85 | |
| 86 | |
| 87 | def evaluate_fid(groundtruth_loader, activation_dict, file): |
no test coverage detected