Skip to content

Commit 6ba04b7

Browse files
authored
Fix multi-image format for expert model training (#71)
Update training data json files to use `"images": [path1, path2, ...]` format and using only `<image>` placeholder in prompts. This will follow the VILA training format, e.g.: ``` { "images": ["a.jpg", "b.jpg", "c.jpg"] conversations": [ { "from": "human", "value": "<image> <image> <image> what object is shown in the images?\n" }, } ```
1 parent 9d947b1 commit 6ba04b7

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

m3/data_prepare/experts/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ We can take existing CT datasets, run [VISTA3D](https://github.com/Project-MONAI
77
export PYTHONPATH=${PWD}/..
88
ROOT_DIR=../../data/experts/vista3d/inference_results
99
OUT_FILEPREFIX="../../data/experts/vista3d/llama_gen_expert_data_vista3d_what"
10-
python expert_train_data_cxr.py --in_datapath ${IN_DATAPATH} --root_dir ${ROOT_DIR} --out_fileprefix ${OUT_FILEPREFIX}
10+
python expert_train_data_vista3d.py --in_datapath ${IN_DATAPATH} --root_dir ${ROOT_DIR} --out_fileprefix ${OUT_FILEPREFIX}
1111
```
1212

1313
### 2. Prepare expert training data for BRATS
@@ -43,3 +43,11 @@ python expert_train_data_brats.py --in_meta_data ${META_DATA} --images_root ${RO
4343

4444
### 2. Prepare expert training data for TorchXRayVision
4545
For details on how to prepare training & evaluation data with an TorchXRayVision expert model ensemble, see [here](./torchxrayvision/README.md).
46+
47+
And run a command similar to this
48+
```commandline
49+
export PYTHONPATH=${PWD}/..
50+
ROOT_DIR=../../data/experts/cxr/inference_results
51+
OUT_FILEPREFIX="../../data/experts/cxr/cxr_expert"
52+
python expert_train_data_cxr.py --in_datapath ${IN_DATAPATH} --root_dir ${ROOT_DIR} --out_fileprefix ${OUT_FILEPREFIX}
53+
```

m3/data_prepare/experts/expert_train_data_brats.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import random
1515

1616
from data_utils import read_json, read_txt, write_json
17-
from expert_utils import add_brats_expert_conversation, assert_image_placeholder, get_predictions, model_list
17+
from expert_utils import add_brats_expert_conversation, model_list
1818
from tqdm import tqdm
1919

2020
random.seed(0)
@@ -37,11 +37,7 @@ def main(args):
3737
for meta in tqdm(in_data, desc="creating train data..."):
3838
# create a q & a conversation
3939
entry = {
40-
"image1": meta["image"][0],
41-
"image2": meta["image"][1],
42-
"image3": meta["image"][2],
43-
"image4": meta["image"][3],
44-
"segmentation": meta["label"],
40+
"images": [meta["image"][0], meta["image"][1], meta["image"][2], meta["image"][3], meta["label"]],
4541
}
4642

4743
# what question

m3/data_prepare/experts/expert_train_data_vista3d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def main(args):
156156

157157
id = str(uuid.uuid4())
158158

159-
entry = {"image": image, "id": id}
159+
entry = {"images": [image], "id": id}
160160

161161
if "tumor" in group_name or "lesion" in group_name:
162162
# tumor task
@@ -173,7 +173,7 @@ def main(args):
173173
conv.append(
174174
{
175175
"from": "human",
176-
"value": f"The results are <segmentation>. The colors in this image describe {m['label_colors']}. "
176+
"value": f"The results are <image>. The colors in this image describe {m['label_colors']}. "
177177
f"Use this result to respond to this prompt:\n{question}.",
178178
}
179179
)
@@ -206,7 +206,7 @@ def main(args):
206206
answer = "no"
207207
conv.append({"from": "gpt", "value": answer})
208208

209-
entry["segmentation"] = label
209+
entry["images"].append(label)
210210
else: # segmentation or what is task
211211
segment_task = True if random.random() > 0.5 else False
212212
if segment_task:
@@ -230,7 +230,7 @@ def main(args):
230230
conv.append(
231231
{
232232
"from": "human",
233-
"value": f"The results are <segmentation>. "
233+
"value": f"The results are <image>. "
234234
f"The colors in this image describe {m['label_colors']}. "
235235
f"Use this result to respond to this prompt:\n{question}.",
236236
}

m3/data_prepare/experts/expert_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ def add_brats_expert_conversation(conv, trigger="This looks like an MRI image se
8787
{
8888
"from": "human",
8989
"value": model_list
90-
+ f"T1(contrast enhanced): <image1>, T1: <image2>, T2: <image3>, FLAIR: <image4> These are different MRI modalities.\n"
90+
+ f"T1(contrast enhanced): <image>, T1: <image>, T2: <image>, FLAIR: <image> These are different MRI modalities.\n"
9191
+ first_prompt,
9292
}
9393
)
9494
new_conv.append({"from": "gpt", "value": trigger})
9595
new_conv.append(
9696
{
9797
"from": "human",
98-
"value": f"The results are <segmentation>. The colors in this image describe\nyellow and red: tumor core, only yellow: enhancing tumor, all colors: whole tumor\nUse this result to respond to this prompt:\n{first_prompt}.",
98+
"value": f"The results are <image>. The colors in this image describe\nyellow and red: tumor core, only yellow: enhancing tumor, all colors: whole tumor\nUse this result to respond to this prompt:\n{first_prompt}.",
9999
}
100100
)
101101
new_conv.extend(conv[1::])

0 commit comments

Comments
 (0)