Spaces:
Sleeping
Sleeping
Commit
·
10fdd1f
1
Parent(s):
be196af
Resolve paths to images
Browse files- src/generate_emr_csv.py +1 -1
- src/triage_dataset.py +4 -7
- tests/test_generate_emr_csv.py +1 -1
src/generate_emr_csv.py
CHANGED
|
@@ -145,7 +145,7 @@ def generate_dataset(image_dir_override=None, output_path_override=None):
|
|
| 145 |
|
| 146 |
for i in range(SAMPLES_PER_CLASS):
|
| 147 |
image_path = str(
|
| 148 |
-
random.choice(image_files).relative_to(
|
| 149 |
)
|
| 150 |
text = build_emr(label, i)
|
| 151 |
triage = triage_map[label]
|
|
|
|
| 145 |
|
| 146 |
for i in range(SAMPLES_PER_CLASS):
|
| 147 |
image_path = str(
|
| 148 |
+
random.choice(image_files).relative_to(CURRENT_DIR.parent) # path of image respective to the project root
|
| 149 |
)
|
| 150 |
text = build_emr(label, i)
|
| 151 |
triage = triage_map[label]
|
src/triage_dataset.py
CHANGED
|
@@ -89,14 +89,11 @@ class TriageDataset(Dataset):
|
|
| 89 |
# Process image
|
| 90 |
image_path = Path(row["image_path"])
|
| 91 |
|
| 92 |
-
# Normalize if CSV path includes redundant 'data/images/' prefix
|
| 93 |
-
redundant_prefix = Path("data/images")
|
| 94 |
-
if image_path.parts[:2] == redundant_prefix.parts:
|
| 95 |
-
image_path = Path(*image_path.parts[2:]) # drop 'data/images'
|
| 96 |
-
|
| 97 |
-
# Combine with base directory if not absolute
|
| 98 |
if not image_path.is_absolute():
|
| 99 |
-
image_path
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
if not image_path.exists():
|
| 102 |
if IS_CI:
|
|
|
|
| 89 |
# Process image
|
| 90 |
image_path = Path(row["image_path"])
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
if not image_path.is_absolute():
|
| 93 |
+
if image_path.parts[:2] == ("data", self.image_base_dir.name):
|
| 94 |
+
image_path = self.image_base_dir.parent / Path(*image_path.parts[1:])
|
| 95 |
+
else:
|
| 96 |
+
image_path = self.image_base_dir / image_path
|
| 97 |
|
| 98 |
if not image_path.exists():
|
| 99 |
if IS_CI:
|
tests/test_generate_emr_csv.py
CHANGED
|
@@ -115,7 +115,7 @@ def test_emr_text_quality():
|
|
| 115 |
|
| 116 |
|
| 117 |
def test_image_path_format():
|
| 118 |
-
expected_path =
|
| 119 |
with open(CSV_PATH, newline="") as f:
|
| 120 |
reader = csv.DictReader(f)
|
| 121 |
for row in reader:
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
def test_image_path_format():
|
| 118 |
+
expected_path = (DATA_DIR / ("dummy_images" if IS_CI else "images")).relative_to(BASE_DIR)
|
| 119 |
with open(CSV_PATH, newline="") as f:
|
| 120 |
reader = csv.DictReader(f)
|
| 121 |
for row in reader:
|