compute LP-F-score over two set of patches. Args: gen_patches (torch.Tensor): patches from generated shape ref_patches (torch.Tensor): patches from reference shape threshold (float, optional): F-score threshold. Defaults to 0.95. Returns: average max F-score
(gen_patches: torch.Tensor, ref_patches: torch.Tensor, threshold=0.95)
| 98 | |
| 99 | |
| 100 | def eval_LP_Fscore(gen_patches: torch.Tensor, ref_patches: torch.Tensor, threshold=0.95): |
| 101 | """compute LP-F-score over two set of patches. |
| 102 | |
| 103 | Args: |
| 104 | gen_patches (torch.Tensor): patches from generated shape |
| 105 | ref_patches (torch.Tensor): patches from reference shape |
| 106 | threshold (float, optional): F-score threshold. Defaults to 0.95. |
| 107 | |
| 108 | Returns: |
| 109 | average max F-score, LP-F-score |
| 110 | """ |
| 111 | values = [] |
| 112 | for i in range(gen_patches.shape[0]): |
| 113 | true_positives = torch.logical_and(ref_patches, gen_patches[i:i+1]).sum(dim=(1, 2, 3)) |
| 114 | precision = true_positives / gen_patches[i:i+1].sum() |
| 115 | recall = true_positives / ref_patches.sum(dim=(1, 2, 3)) |
| 116 | Fscores = 2 * precision * recall / (precision + recall + 1e-8) |
| 117 | Fscore = torch.max(Fscores) |
| 118 | values.append(Fscore) |
| 119 | values = torch.stack(values) |
| 120 | avg_fscore = torch.mean(values).item() |
| 121 | percent = torch.sum((values > threshold).int()).item() * 1.0 / len(values) |
| 122 | return avg_fscore, percent |
| 123 | |
| 124 | |
| 125 | def eval_LP_given_paths(data_paths, ref_path, patch_size=11, stride=5, patch_num=1000, device="cpu"): |
no outgoing calls
no test coverage detected