--- license: apache-2.0 tags: - image-text pair - image-captioning - 3D medical images - medical reports size_categories: - 100K 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 ```bash git clone https://huggingface.co/datasets/GoodBaiBai88/M3D-Cap ``` #### SDK Download ```bash 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: ```python 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 = "" * 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: ```BibTeX @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} } ```