(self, output: List[Dict], target: List[Dict])
| 68 | } |
| 69 | |
| 70 | def metric(self, output: List[Dict], target: List[Dict]): |
| 71 | prediction = [] |
| 72 | for x in output: |
| 73 | prediction.append(x['final_prediction']) |
| 74 | # if x is not None: |
| 75 | # prediction.append(x['final_prediction']) |
| 76 | # else: |
| 77 | # prediction.append(None) |
| 78 | all_element_acc, all_action_f1, all_step_sr = [], [], [] |
| 79 | assert len(target) == len(prediction) |
| 80 | for pred, tar in zip(prediction, target): |
| 81 | if tar is None or pred is None: |
| 82 | all_element_acc.append(0) |
| 83 | all_action_f1.append(0) |
| 84 | else: |
| 85 | if pred[0] in tar['element']: |
| 86 | all_element_acc.append(1) |
| 87 | else: |
| 88 | all_element_acc.append(0) |
| 89 | all_action_f1.append( |
| 90 | self.calculate_f1(pred[1], tar['action']) |
| 91 | ) |
| 92 | if all_element_acc[-1] > 0 and all_action_f1[-1] >= 1.0: |
| 93 | all_step_sr.append(1) |
| 94 | else: |
| 95 | all_step_sr.append(0) |
| 96 | overall = { |
| 97 | 'element_acc': sum(all_element_acc) / len(all_element_acc) * 100, |
| 98 | 'action_f1': np.mean(all_action_f1) * 100, |
| 99 | 'step_sr': np.mean(all_step_sr) * 100, |
| 100 | 'each_f1': all_action_f1, |
| 101 | 'each_sr': all_step_sr |
| 102 | } |
| 103 | return overall |
| 104 | |
| 105 | def get_data(self): |
| 106 | ret = Dataset() |
nothing calls this directly
no test coverage detected