| 293 | return self.total_len |
| 294 | |
| 295 | def __getitem__(self, index): |
| 296 | if index < len(self.score_samples): |
| 297 | task_type = "score" |
| 298 | example = self.score_samples[index] |
| 299 | elif index < len(self.score_samples) + len(self.deficiency_samples): |
| 300 | task_type = "deficiency" |
| 301 | deficiency_index = index - len(self.score_samples) |
| 302 | example = self.deficiency_samples[deficiency_index] |
| 303 | else: |
| 304 | task_type = "comparison" |
| 305 | comparison_index = index - len(self.score_samples) - len(self.deficiency_samples) |
| 306 | example = self.comparison_samples[comparison_index] |
| 307 | |
| 308 | sample = {"task": task_type} |
| 309 | |
| 310 | if task_type == "score": |
| 311 | sample["prompt_text"] = self.score_prompt_text |
| 312 | sol = example.get("score", None) or example.get("gt_score_norm", None) |
| 313 | # When score is a dict with multiple dimensions, use only the overall value |
| 314 | if isinstance(sol, dict): |
| 315 | sol = sol.get("overall") |
| 316 | sample["solution"] = sol |
| 317 | sample["score_reward_threshold"] = self.script_args.score_reward_threshold |
| 318 | elif task_type == "deficiency": |
| 319 | sample["prompt_text"] = self.deficiency_prompt_text |
| 320 | sample["solution"] = example.get("deficiencies", []) |
| 321 | sample["deficiency_f1_threshold"] = self.script_args.deficiency_f1_threshold |
| 322 | else: # comparison task |
| 323 | sample["prompt_text"] = self.comparison_prompt_text |
| 324 | sample["solution"] = example.get("result") |
| 325 | sample["system_prompt"] = SYSTEM_PROMPT |
| 326 | sample["custom_question"] = self.comparison_prompt_text |
| 327 | |
| 328 | if task_type == "comparison": |
| 329 | # Handle comparison task with multiple images |
| 330 | image_root = example.get("image_root") |
| 331 | |
| 332 | # Reference image |
| 333 | ref_rel = example.get("ref_image") |
| 334 | ref_fp = os.path.join(image_root, ref_rel) if image_root else ref_rel |
| 335 | if not os.path.exists(ref_fp): |
| 336 | raise FileNotFoundError(f"Reference image not found: {ref_fp}") |
| 337 | sample["ref_image"] = Image.open(ref_fp).convert("RGB") |
| 338 | sample["ref_image_path"] = ref_fp |
| 339 | |
| 340 | # Slide A |
| 341 | A_rel = example.get("ImageA") |
| 342 | A_fp = os.path.join(image_root, A_rel) if image_root else A_rel |
| 343 | if not os.path.exists(A_fp): |
| 344 | raise FileNotFoundError(f"Slide A not found: {A_fp}") |
| 345 | sample["imageA"] = Image.open(A_fp).convert("RGB") |
| 346 | sample["imageA_path"] = A_fp |
| 347 | |
| 348 | # Slide B |
| 349 | B_rel = example.get("ImageB") |
| 350 | B_fp = os.path.join(image_root, B_rel) if image_root else B_rel |
| 351 | if not os.path.exists(B_fp): |
| 352 | raise FileNotFoundError(f"Slide B not found: {B_fp}") |