|
a |
|
b/README.md |
|
|
1 |
<p align="center"> |
|
|
2 |
<h1 align="center">Bootstrapping Large Language Models for Radiology Report Generation</h1> |
|
|
3 |
|
|
|
4 |
The official GitHub repository of the AAAI-2024 paper ["Bootstrapping Large Language Models for Radiology Report Generation"](https://ojs.aaai.org/index.php/AAAI/article/view/29826). |
|
|
5 |
|
|
|
6 |
# Reference |
|
|
7 |
If our work is helpful to your research, please cite our paper: |
|
|
8 |
``` latex |
|
|
9 |
@inproceedings{chang2024bootstrapping, |
|
|
10 |
author = {Chang Liu and |
|
|
11 |
Yuanhe Tian and |
|
|
12 |
Weidong Chen and |
|
|
13 |
Yan Song and |
|
|
14 |
Yongdong Zhang}, |
|
|
15 |
editor = {Michael J. Wooldridge and |
|
|
16 |
Jennifer G. Dy and |
|
|
17 |
Sriraam Natarajan}, |
|
|
18 |
title = {Bootstrapping Large Language Models for Radiology Report Generation}, |
|
|
19 |
booktitle = {AAAI}, |
|
|
20 |
pages = {18635--18643}, |
|
|
21 |
year = {2024}, |
|
|
22 |
} |
|
|
23 |
``` |
|
|
24 |
|
|
|
25 |
# Getting Started |
|
|
26 |
1. Before you run the code, you need to create a virtual environment and activate it via the following command: |
|
|
27 |
```bash |
|
|
28 |
conda env create -f environment.yaml |
|
|
29 |
conda activate venv |
|
|
30 |
``` |
|
|
31 |
|
|
|
32 |
2. Once the virtual environment is created, you need to download the LLM model weights following the instruction in [MiniGPT-4](https://github.com/Vision-CAIR/MiniGPT-4). Once the model weights are downloaded, you need to modify some configuration files: |
|
|
33 |
- `minigpt4/models/minigpt4-7b.yaml`: line 16 with the path of Vicuna 7b model weights. |
|
|
34 |
- `minigpt4/models/minigpt4.yaml`: line 16 with the path of Vicuna 13b model weights. |
|
|
35 |
|
|
|
36 |
3. You need to download the dataset from the official websites of [IU X-Ray](https://openi.nlm.nih.gov/faq#collection) and [MIMIC-CXR](https://physionet.org/content/mimic-cxr/2.0.0/). Once the datasets are ready, you need to modify some configuration files: |
|
|
37 |
- `minigpt4/configs/datasets/iuxray/align.yaml`: line 5 with the path of pre-training dataset. |
|
|
38 |
- `minigpt4/configs/datasets/iuxray/generate_then_refine.yaml`: line 5 with the path of IU X-Ray dataset, line 6 with the path of public medical corpora. |
|
|
39 |
- `minigpt4/configs/datasets/mimic/align.yaml`: line 5 with the path of pre-training dataset. |
|
|
40 |
- `minigpt4/configs/datasets/mimic/generate_then_refine.yaml`: line 5 with the path of MIMIC-CXR dataset, line 6 with the path of public medical corpora. |
|
|
41 |
|
|
|
42 |
# Training |
|
|
43 |
1. **Pre-training.** We recommend you to follow the instructions below to pre-train MiniGPT-4 on MIMIC-CXR. |
|
|
44 |
|
|
|
45 |
(1) Modify the configuration files. |
|
|
46 |
- `train_configs/stage1/config.yaml`: line 12 with the path of the linear projection layer of MiniGPT-4, line 59 with the output path. |
|
|
47 |
|
|
|
48 |
(2) Run the following command lines to pre-train MiniGPT-4 on MIMIC-CXR. |
|
|
49 |
``` |
|
|
50 |
python train.py --cfg-path train_configs/stage1/config.yaml |
|
|
51 |
``` |
|
|
52 |
|
|
|
53 |
If you need to reduce the memory usage, we recommend you to use the first stage strategy of `ZeRO` optimizer. Run the following command lines to pre-train MiniGPT-4 on MIMIC-CXR with a lower memory usage. |
|
|
54 |
|
|
|
55 |
``` |
|
|
56 |
deepspeed --nproc-per-gpu NUM_GPUS --master-port MASTER_PORT train.py --cfg-path train_configs/stage1/config.yaml use_zero_optimizer --deepspeed_config train_configs/stage1/zero.json |
|
|
57 |
``` |
|
|
58 |
|
|
|
59 |
You can download our pre-trained model weights from [here](https://huggingface.co/a-b-c-d-e-g/R2-LLM). |
|
|
60 |
|
|
|
61 |
2. **Fine-tuning.** We recommend you to follow the instructions below to fine-tune MiniGPT-4 on IU X-Ray and MIMIC-CXR. |
|
|
62 |
|
|
|
63 |
(1) Modify the configuration files. Herein, we take the IU X-Ray configuration as an example. |
|
|
64 |
- `train_configs/stage2/iuxray/config.yaml`: line 11 with the path of the linear projection layer of pre-trained MiniGPT-4 on MIMIC-CXR, line 56 with the output path. |
|
|
65 |
|
|
|
66 |
(2) Run the following command lines to fine-tune MiniGPT-4. |
|
|
67 |
|
|
|
68 |
``` |
|
|
69 |
python train.py --cfg-path train_configs/stage2/iuxray/config.yaml |
|
|
70 |
``` |
|
|
71 |
|
|
|
72 |
Our codebase supports `ZeRO` to reduce the memory usage. You can run the following command lines with `ZeRO`. |
|
|
73 |
|
|
|
74 |
``` |
|
|
75 |
deepspeed --nproc-per-gpu NUM_GPUS --master-port MASTER_PORT train.py --cfg-path train_configs/stage2/iuxray/config.yaml use_zero_optimizer --deepspeed_config train_configs/stage2/iuxray/zero.json |
|
|
76 |
``` |
|
|
77 |
|
|
|
78 |
You can download our fine-tuned model weights from [here](https://huggingface.co/a-b-c-d-e-g/R2-LLM). |
|
|
79 |
|
|
|
80 |
# Inference |
|
|
81 |
Run the following command lines to generate radiology reports. |
|
|
82 |
|
|
|
83 |
``` |
|
|
84 |
python generate_reports.py \ |
|
|
85 |
--cfg-path configs/eval_configs/eval.yaml \ |
|
|
86 |
--gpu-id GPU_IDS \ |
|
|
87 |
--image_path IMAGE_PATH \ |
|
|
88 |
--annotations ANNOTATIONS_PATH_OF_IUXRAY_OR_MIMIC \ |
|
|
89 |
--checkpoint PATH_TO_PRETRAINED_MODEL_WEIGHTS \ |
|
|
90 |
``` |
|
|
91 |
|
|
|
92 |
# Acknowledgement |
|
|
93 |
This GitHub repository is heavily built based on the [MiniGPT-4](https://github.com/Vision-CAIR/MiniGPT-4) repository. Thanks to the authors for their great work! |