The dataset viewer is not available for this subset.
Need help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.
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, due to the sensitivity and privacy concerns associated with patient data, publicly releasing these multimodal datasets poses challenges. To overcome these limitations, we collected medical images and reports from the publicly accessible professional medical website Radiopaedia. Specifically, each patient case in our dataset consists of multiple 3D images and corresponding reports, which experts on the Radiopaedia platform have meticulously reviewed. Given the critical role of 3D CT in medical image analysis, particularly in the diagnosis, localization, and measurement of systemic lesions, we focused on 3D CT data and successfully built the largest-scale 3D medical image-text paired dataset, named M3D-Cap, comprising 120K image-text pairs.
The dataset is divided into two main folders named ct_case and ct_quizze. The ct_quizze folder is intended for medical exams and exhibits higher quality. Each folder contains subfolders for images and texts. The image folders contain multiple 2D slices of 3D images, and the text files provide English report descriptions corresponding to the 3D images, including anomaly types, lesion locations, etc.
- M3D_Cap.json: Provides the dataset split.
- data_examples: Provides examples of 24 sets of 3D images and text data.
- M3D_Cap: Provides the complete dataset, please download this folder.
- m3d_cap_data_prepare.py: Provides data preprocessing code, including image normalization, stack 3D images from 2D slices, image cropping, and effective text extraction.
Based on the image-text pairs in the M3D-Cap dataset, we created the M3D-VQA (Visual Question Answering) dataset. Please refer to the link.
Supported Tasks
M3D-Cap supports multimodal tasks in 3D medical scenarios such as image-text retrieval, report generation, and image generation.
Dataset Format and Structure
Data Format
M3D_Cap/ 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
The total size of the dataset is approximately 978G. Please note that the contents of the data_examples folder are only examples and do not need to be downloaded. The complete dataset is located in the M3D_Cap folder.
Clone with HTTP
git clone https://huggingface.co/datasets/GoodBaiBai88/M3D-Cap
SDK Download
from datasets import load_dataset
dataset = load_dataset("GoodBaiBai88/M3D-Cap")
Manual Download
Manually download all files from the dataset, and we recommend using a batch download tool.
Dataset Loading Method
1. Preprocessing
Preprocess the dataset according to m3d_cap_data_prepare.py, including:
stack 3D images from 2D slices in each folder of the dataset and name them with the image file name
(retaining plane and phase information), saving as npy
files,
image normalization and cropping, and filtering and extracting high-quality descriptions
from the text reports in the dataset.
2. Build Dataset
We provide examples 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 using a JSON file and can be divided into
train, validation, test100, test500, test1k, test
, where the test subset contains 2k samples.
Considering testing costs, we provide test sets with different sample sizes,
including 100, 500, 1k, and 2k samples.
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}
}
- Downloads last month
- 14