(args: argparse.Namespace, dataset, use_caption=True)
| 259 | |
| 260 | @beartype |
| 261 | def eval_from_file(args: argparse.Namespace, dataset, use_caption=True) -> None: |
| 262 | result_path = Path(args.result_dir) / f"actions_{'caption' if use_caption else 'no_caption'}.json" |
| 263 | with open(result_path, "r") as f: |
| 264 | all_actions = json.load(f) |
| 265 | all_labels = {} |
| 266 | for example in dataset: |
| 267 | all_labels[example["id"]] = example["label"] |
| 268 | |
| 269 | evaluator = StepEvaluator() |
| 270 | |
| 271 | correct = {} |
| 272 | for example_id, action in all_actions.items(): |
| 273 | label = all_labels[example_id] |
| 274 | correct[example_id] = evaluator(action, label) |
| 275 | |
| 276 | print(f"Benign success rate: {sum(correct.values())}/{len(all_actions)}") |
| 277 | |
| 278 | # write to file |
| 279 | with open(Path(args.result_dir) / f"correct_{'caption' if use_caption else 'no_caption'}.json", "w") as f: |
| 280 | json.dump(correct, f, indent=4) |
| 281 | |
| 282 | |
| 283 | def prepare(args: argparse.Namespace) -> None: |
no test coverage detected