license: apache-2.0
tags:
- medical
- 3D medical image caption
- image-text pair
- medical report
size_categories:
- 100K<n<1M
Dataset Description
Large-scale 3D medical multi-modal dataset - Image-Text Pair Dataset (M3D-Cap)
Dataset Introduction
Medical institutions, such as hospitals, store vast amounts of multi-modal data, including medical images and diagnostic reports. However, disclosing these multi-modal datasets involving patient data faces challenges due to sensitivity and privacy concerns. To circumvent these limitations, we collected medical images and reports from publicly accessible professional medical websites Radiopaedia. Specifically, each patient case in our dataset includes multiple images and corresponding reports, which experts from the Radiopaedia platform meticulously review. Given the crucial role of 3D CT in medical image analysis, particularly in the diagnosis, localization, and measurement of systemic lesions, we focus on 3D CT data. We successfully constructed the largest-scale 3D medical image-text paired dataset, M3D-Cap, comprising 120K pairs of image-text data. Overall, it is divided into two data folders named ct_case and ct_quizze. ct_quizze is used for medical exams and has higher quality. Each folder contains some image folders and one text file. The image folders contain multiple 2D slices of 3D images, while the text files provide English reports describing the corresponding 3D images, including types of abnormalities and lesions. M3D_Cap.json provides the split scheme.
Supported Tasks
M3D-Cap supports various image-text multimodal tasks in 3D medical scenarios, including image-text retrieval, report generation, and image generation.
Dataset Format and Structure
Data Format
M3D_Seg/ ct_case/ 000006/ Axial_non_contrast/ 0.jpeg 1.jpeg ...... text.txt ...... ct_quizze/ 000007/ Axial_non_contrast/ 0.png 1.png ...... text.txt ...... ......
Dataset Download
Clone with HTTP
git clone
Manual Download
Download all files from the dataset manually, which can be done using batch download tools. Note: Due to the large size of the overall dataset, it is divided into subfiles of 20G each. After downloading all files, extract them together to obtain the complete data.
Dataset Loading Method
1. Preprocessing
Combine slices under each folder in the dataset to form 3D images and name them according to the image file names (retain plane and phase information), saving them as npy files. Filter the text reports in the dataset to obtain high-quality descriptions.
2. Build Dataset
We provide sample code for building the dataset
class CapDataset(Dataset):
def __init__(self, args, tokenizer, mode="train"):
self.args = args
self.data_root = args.data_root
self.tokenizer = tokenizer
self.mode = mode
self.image_tokens = "<im_patch>" * args.proj_out_num
with open(args.cap_data_path, 'r') as file:
self.json_file = json.load(file)
self.data_list = self.json_file[mode]
self.caption_prompts = [
"Can you provide a caption consists of findings for this medical image?",
"Describe the findings of the medical image you see.",
"Please caption this medical scan with findings.",
"What is the findings of this image?",
"Describe this medical scan with findings.",
"Please write a caption consists of findings for this image.",
"Can you summarize with findings the images presented?",
"Please caption this scan with findings.",
"Please provide a caption consists of findings for this medical image.",
"Can you provide a summary consists of findings of this radiograph?",
"What are the findings presented in this medical scan?",
"Please write a caption consists of findings for this scan.",
"Can you provide a description consists of findings of this medical scan?",
"Please caption this medical scan with findings.",
"Can you provide a caption consists of findings for this medical scan?"
]
train_transform = mtf.Compose(
[
mtf.RandRotate90(prob=0.5, spatial_axes=(1, 2)),
mtf.RandFlip(prob=0.10, spatial_axis=0),
mtf.RandFlip(prob=0.10, spatial_axis=1),
mtf.RandFlip(prob=0.10, spatial_axis=2),
mtf.RandScaleIntensity(factors=0.1, prob=0.5),
mtf.RandShiftIntensity(offsets=0.1, prob=0.5),
mtf.ToTensor(dtype=torch.float),
]
)
val_transform = mtf.Compose(
[
mtf.ToTensor(dtype=torch.float),
]
)
set_track_meta(False)
if mode == 'train':
self.transform = train_transform
elif mode == 'validation':
self.transform = val_transform
elif mode == 'test':
self.transform = val_transform
def __len__(self):
return len(self.data_list)
def __getitem__(self, idx):
max_attempts = 100
for _ in range(max_attempts):
try:
data = self.data_list[idx]
image_path = data["image"]
image_abs_path = os.path.join(self.data_root, image_path)
image = np.load(image_abs_path) # nomalized 0-1, C,D,H,W
image = self.transform(image)
text_path = data["text"]
text_abs_path = os.path.join(self.data_root, text_path)
with open(text_abs_path, 'r') as text_file:
raw_text = text_file.read()
answer = raw_text
prompt_question = random.choice(self.caption_prompts)
question = self.image_tokens + prompt_question
text_tensor = self.tokenizer(
question + ' ' + answer, max_length=self.args.max_length, truncation=True, padding="max_length", return_tensors="pt"
)
input_id = text_tensor["input_ids"][0]
attention_mask = text_tensor["attention_mask"][0]
valid_len = torch.sum(attention_mask)
if valid_len < len(input_id):
input_id[valid_len] = self.tokenizer.eos_token_id
question_tensor = self.tokenizer(
question, max_length=self.args.max_length, truncation=True, padding="max_length", return_tensors="pt"
)
question_len = torch.sum(question_tensor["attention_mask"][0])
label = input_id.clone()
label[label == self.tokenizer.pad_token_id] = -100
label[:question_len] = -100
ret = {
'image': image,
'input_id': input_id,
'label': label,
'attention_mask': attention_mask,
'question': question,
'answer': answer,
'question_type': "Caption",
}
return ret
except Exception as e:
print(f"Error in __getitem__ at index {idx}: {e}")
idx = random.randint(0, len(self.data_list) - 1)
Data Splitting
The entire dataset is split into ‘train, validation, test100, test500, test1k, and test’ using a JSON file. considering testing costs, we provide different quantities of test samples from 100 to 2k, with the number of ‘test‘ being 2k.
Dataset Copyright Information
All images and reports involved in this dataset are publicly available data. For detailed copyright information, please refer to the corresponding links.
Citation
If you use this dataset, please cite the following works:
@misc{bai2024m3d,
title={M3D: Advancing 3D Medical Image Analysis with Multi-Modal Large Language Models},
author={Fan Bai and Yuxin Du and Tiejun Huang and Max Q. -H. Meng and Bo Zhao},
year={2024},
eprint={2404.00578},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@misc{du2024segvol,
title={SegVol: Universal and Interactive Volumetric Medical Image Segmentation},
author={Yuxin Du and Fan Bai and Tiejun Huang and Bo Zhao},
year={2024},
eprint={2311.13385},
archivePrefix={arXiv},
primaryClass={cs.CV}
}