Add a fallback bbox adjustment when json parsing fails on ideogram4 captioner

This commit is contained in:
Jaret Burkett
2026-06-19 07:25:54 -06:00
parent 4af4fb9d58
commit 99f8fd44e3
2 changed files with 42 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ from PIL import Image
from .Qwen3VLCaptioner import Qwen3VLCaptioner
from .prompts.ideogram4_caption_prompt import ideogram4_caption_prompt
from toolkit.ideogram_caption import normalize_caption_dict
from toolkit.ideogram_caption import normalize_caption_dict, swap_bbox_xy_in_text
import transformers
import logging
import warnings
@@ -169,9 +169,11 @@ class Ideogram4Captioner(Qwen3VLCaptioner):
if data is None:
print(
f"[IdeogramCaptioner] Could not parse JSON for {file_path}; "
f"saving raw output."
f"saving raw output with regex-adapted bboxes."
)
return output_text
# JSON is malformed so we can't swap bboxes per-element. Adapt them
# directly in the raw text instead, so the boxes still render right.
return swap_bbox_xy_in_text(output_text)
data = self._normalize_caption(data)
# Store pretty JSON for QC/editing; the dataloader minifies at load.