Datasets:
Anonymous
commited on
Update nova.py
Browse files
nova.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import os
|
| 2 |
import pandas as pd
|
| 3 |
-
from datasets import
|
| 4 |
|
| 5 |
|
| 6 |
-
class NovaDataset(
|
| 7 |
def _info(self):
|
| 8 |
-
return
|
| 9 |
description="NOVA benchmark: anomaly localization and clinical reasoning in brain MRI.",
|
| 10 |
features=Features({
|
| 11 |
"image": Image(),
|
|
@@ -19,29 +19,40 @@ class NovaDataset(DatasetBuilder):
|
|
| 19 |
"differential_diagnosis": Value("string"),
|
| 20 |
"final_diagnosis": Value("string"),
|
| 21 |
"link": Value("string"),
|
| 22 |
-
"bbox_gold":
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
supervised_keys=None,
|
| 26 |
)
|
| 27 |
|
| 28 |
def _split_generators(self, dl_manager):
|
| 29 |
-
|
| 30 |
-
csvs =
|
| 31 |
-
"captions": "
|
| 32 |
-
"bboxes_gold": "
|
| 33 |
-
"bboxes_raters": "
|
| 34 |
-
"case_metadata": "
|
| 35 |
-
}
|
|
|
|
| 36 |
|
| 37 |
return [
|
| 38 |
SplitGenerator(
|
| 39 |
name=Split.TEST,
|
| 40 |
-
gen_kwargs={"
|
| 41 |
)
|
| 42 |
]
|
| 43 |
|
| 44 |
-
def _generate_examples(self,
|
| 45 |
captions = pd.read_csv(csvs["captions"])
|
| 46 |
gold = pd.read_csv(csvs["bboxes_gold"])
|
| 47 |
raters = pd.read_csv(csvs["bboxes_raters"])
|
|
@@ -50,18 +61,21 @@ class NovaDataset(DatasetBuilder):
|
|
| 50 |
captions["case_id"] = captions["filename"].str.extract(r"^(case\d+)_")
|
| 51 |
|
| 52 |
gold_grouped = gold.groupby("filename").apply(
|
| 53 |
-
lambda df: df[["x", "y", "width", "height"]].
|
| 54 |
).to_dict()
|
|
|
|
| 55 |
raters_grouped = raters.groupby("filename").apply(
|
| 56 |
-
lambda df: df[["rater", "x", "y", "width", "height"]].
|
| 57 |
).to_dict()
|
| 58 |
meta = meta.set_index("case_id").to_dict("index")
|
| 59 |
|
|
|
|
|
|
|
| 60 |
for idx, row in captions.iterrows():
|
| 61 |
filename = row["filename"]
|
| 62 |
case_id = row["case_id"]
|
| 63 |
record = {
|
| 64 |
-
"image":
|
| 65 |
"filename": filename,
|
| 66 |
"caption": row["caption"],
|
| 67 |
"case_id": case_id,
|
|
|
|
| 1 |
import os
|
| 2 |
import pandas as pd
|
| 3 |
+
from datasets import GeneratorBasedBuilder, SplitGenerator, Split, Value, Features, Image, DatasetInfo, Sequence
|
| 4 |
|
| 5 |
|
| 6 |
+
class NovaDataset(GeneratorBasedBuilder):
|
| 7 |
def _info(self):
|
| 8 |
+
return DatasetInfo(
|
| 9 |
description="NOVA benchmark: anomaly localization and clinical reasoning in brain MRI.",
|
| 10 |
features=Features({
|
| 11 |
"image": Image(),
|
|
|
|
| 19 |
"differential_diagnosis": Value("string"),
|
| 20 |
"final_diagnosis": Value("string"),
|
| 21 |
"link": Value("string"),
|
| 22 |
+
"bbox_gold": Sequence({
|
| 23 |
+
"x": Value("float32"),
|
| 24 |
+
"y": Value("float32"),
|
| 25 |
+
"width": Value("float32"),
|
| 26 |
+
"height": Value("float32"),
|
| 27 |
+
}),
|
| 28 |
+
"bbox_raters": Sequence({
|
| 29 |
+
"rater": Value("string"),
|
| 30 |
+
"x": Value("float32"),
|
| 31 |
+
"y": Value("float32"),
|
| 32 |
+
"width": Value("float32"),
|
| 33 |
+
"height": Value("float32"),
|
| 34 |
+
}), }),
|
| 35 |
supervised_keys=None,
|
| 36 |
)
|
| 37 |
|
| 38 |
def _split_generators(self, dl_manager):
|
| 39 |
+
# Download CSVs
|
| 40 |
+
csvs = {
|
| 41 |
+
"captions": dl_manager.download("captions.csv"),
|
| 42 |
+
"bboxes_gold": dl_manager.download("bboxes_gold.csv"),
|
| 43 |
+
"bboxes_raters": dl_manager.download("bboxes_raters.csv"),
|
| 44 |
+
"case_metadata": dl_manager.download("case_metadata.csv"),
|
| 45 |
+
}
|
| 46 |
+
image_files = list(dl_manager.iter_files("test"))
|
| 47 |
|
| 48 |
return [
|
| 49 |
SplitGenerator(
|
| 50 |
name=Split.TEST,
|
| 51 |
+
gen_kwargs={"image_files": image_files, "csvs": csvs},
|
| 52 |
)
|
| 53 |
]
|
| 54 |
|
| 55 |
+
def _generate_examples(self, image_files, csvs):
|
| 56 |
captions = pd.read_csv(csvs["captions"])
|
| 57 |
gold = pd.read_csv(csvs["bboxes_gold"])
|
| 58 |
raters = pd.read_csv(csvs["bboxes_raters"])
|
|
|
|
| 61 |
captions["case_id"] = captions["filename"].str.extract(r"^(case\d+)_")
|
| 62 |
|
| 63 |
gold_grouped = gold.groupby("filename").apply(
|
| 64 |
+
lambda df: df[["x", "y", "width", "height"]].astype(float).to_dict(orient="records")
|
| 65 |
).to_dict()
|
| 66 |
+
|
| 67 |
raters_grouped = raters.groupby("filename").apply(
|
| 68 |
+
lambda df: df[["rater", "x", "y", "width", "height"]].astype({"x": float, "y": float, "width": float, "height": float}).to_dict(orient="records")
|
| 69 |
).to_dict()
|
| 70 |
meta = meta.set_index("case_id").to_dict("index")
|
| 71 |
|
| 72 |
+
images_map = {os.path.basename(f): f for f in image_files}
|
| 73 |
+
|
| 74 |
for idx, row in captions.iterrows():
|
| 75 |
filename = row["filename"]
|
| 76 |
case_id = row["case_id"]
|
| 77 |
record = {
|
| 78 |
+
"image": images_map.get(filename, None),
|
| 79 |
"filename": filename,
|
| 80 |
"caption": row["caption"],
|
| 81 |
"case_id": case_id,
|