Datasets:
Update image loader to support subdirectory structure
Browse files- src/mcr/data/emcr.py +13 -3
src/mcr/data/emcr.py
CHANGED
|
@@ -58,9 +58,7 @@ class SearchTaoTask(RetrievalTask):
|
|
| 58 |
|
| 59 |
if content_id not in corpus:
|
| 60 |
img = row.get("doc_image") or ""
|
| 61 |
-
img_path =
|
| 62 |
-
if img_path and not os.path.exists(img_path):
|
| 63 |
-
img_path = ""
|
| 64 |
corpus[content_id] = {"text": _render_doc(row), "image": img_path}
|
| 65 |
|
| 66 |
if query_text not in query_index:
|
|
@@ -109,6 +107,18 @@ class SearchTaoTask(RetrievalTask):
|
|
| 109 |
}
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
def _task_group(task_type: str) -> str:
|
| 113 |
"""Coarse group: price+negative > price > negative > general."""
|
| 114 |
has_price = "price" in task_type
|
|
|
|
| 58 |
|
| 59 |
if content_id not in corpus:
|
| 60 |
img = row.get("doc_image") or ""
|
| 61 |
+
img_path = _find_image(self._image_dir, img) if (self._image_dir and img) else ""
|
|
|
|
|
|
|
| 62 |
corpus[content_id] = {"text": _render_doc(row), "image": img_path}
|
| 63 |
|
| 64 |
if query_text not in query_index:
|
|
|
|
| 107 |
}
|
| 108 |
|
| 109 |
|
| 110 |
+
def _find_image(image_dir: str, filename: str) -> str:
|
| 111 |
+
"""Find image in flat dir or part_N subdirectories."""
|
| 112 |
+
direct = os.path.join(image_dir, filename)
|
| 113 |
+
if os.path.exists(direct):
|
| 114 |
+
return direct
|
| 115 |
+
for subdir in ("part_0", "part_1", "part_2", "part_3"):
|
| 116 |
+
candidate = os.path.join(image_dir, subdir, filename)
|
| 117 |
+
if os.path.exists(candidate):
|
| 118 |
+
return candidate
|
| 119 |
+
return ""
|
| 120 |
+
|
| 121 |
+
|
| 122 |
def _task_group(task_type: str) -> str:
|
| 123 |
"""Coarse group: price+negative > price > negative > general."""
|
| 124 |
has_price = "price" in task_type
|