Joint Brain Tumor Classification and Segmentation from MRI with an Adapted Multimodal Large Language Model

Simon Tong Sing HeeZeng YiFeng Peilin Ye XiaomengLyu MuyangTimothy Aw Bang Hao

Nanyang Technological University · GP8001 Group Project, Group 3

Code Model Try the demo

Brain tumor MRI analysis asks two questions: which type of tumor is present, and where it is. They are usually answered by a classifier and a separate segmentation network that never share information, so their answers can contradict each other. We adapt MedPLIB-7b-2e, a biomedical multimodal large language model, so that one model answers both questions in one response. It writes the tumor type followed by a special <SEG> token, and the hidden state of that token is decoded into the tumor mask.

Method

One model, one answer, two outputs.

The class and the mask come from one answer

Given an MRI slice \(x\) and a fixed instruction \(q\), MedPLIB writes an answer of the form “\(c\) <SEG>”, where \(c\) is one of the four classes. A projector \(P\) maps the hidden state \(h\) of the <SEG> token to a prompt vector. The SAM-Med2D mask decoder \(D\) combines this prompt with the image features \(F = E(x)\):

\[ S = \sigma\big(D(F, P(h))\big), \qquad \hat{M}_{ij} = \mathbb{I}\big[S_{ij} > 0.5\big]. \]

The prompt takes the place of the click or box that a user would normally give to SAM. The mask is therefore drawn from what the language model has just decided.

The answer is chosen by scoring

Only four answers are valid, so we do not parse free text. Each candidate \(a^{(c)}\) is scored by its log-likelihood and the best one is kept:

\[ \hat{y} = \arg\max_{c \in \mathcal{C}} \sum_{t=1}^{T_c} \log p_\theta\big(a^{(c)}_t \mid a^{(c)}_{<t}, x, q\big). \]

The mask comes from the <SEG> state of the winning answer. No rule removes it afterwards, so an empty mask on a non-tumorous slice has to come from the model itself.

Two-stage adaptation

Stage A trains only the modules that connect the parts: the image projector, the router, the <SEG> projector and the mask decoder. Stage B adds LoRA, \(W = W_0 + \tfrac{\alpha}{r}BA\) with \(r = 16\), to all 32 language model layers and switches on the adapters of the SAM-Med2D encoder. It minimizes

\[ \mathcal{L} = \mathcal{L}_{\mathrm{CE}} + 2\,\mathcal{L}_{\mathrm{BCE}} + 2\,\mathcal{L}_{\mathrm{Dice}} + \mathcal{L}_{\mathrm{IoU}}, \]

where the first term trains the answer and the other three train the mask. Non-tumorous slices are trained with an empty mask. Half of the training prompts ask for the class and the mask, a quarter for the class only and a quarter for the mask only.

Training losses per epoch
Training losses per epoch. The answer loss is close to zero after a few epochs, while the mask loss keeps falling through Stage B. Learning the mask is the harder part of the task.

Ask the model

Pick a test slice. The model scores each of the four valid answers, keeps the most likely one, and draws the mask from that answer's <SEG> token.

Selected MRI slice
InstructionClassify this contrast-enhanced T1 brain MRI as glioma, meningioma, pituitary tumor, or non-tumorous, and segment the tumor region.

Results at a glance

ModelAccuracyTumor DiceDice, all slicesFalse masksContradictions
MedPLIB, no adaptation0.2940.0400.08563.6%7.0%
MedPLIB, unified, ours0.9800.8540.8740.0%0.0%
EfficientNet-B0 + U-Net0.9930.8810.81261.4%9.0%
EfficientNet-B0 + U-Net, with a hand-written rule0.9930.8810.8980.0%0.4%

Dice over all slices also scores the 140 non-tumorous slices, where an empty mask counts as correct. The hand-written rule removes the U-Net mask whenever EfficientNet-B0 predicts no tumor. Accuracy of the unified model is about the same on all three imaging planes: 0.980 on axial, 0.984 on coronal and 0.976 on sagittal slices. The full comparison is in the README.

What adaptation changes

The same model on the same 1,000 test slices, before and after our two training stages.

Confusion matrices before and after adaptation
Confusion matrices. Without adaptation, MedPLIB calls almost every slice a meningioma and never answers non-tumorous. After adaptation, all 140 non-tumorous slices are recognized, and the 20 remaining errors are all between tumor types. No tumor is ever called non-tumorous.

Real answers before and after adaptation

Main instruction, glioma sliceClassify this contrast-enhanced T1 brain MRI as glioma, meningioma, pituitary tumor, or non-tumorous, and segment the tumor region.
No adaptationNon-enhancing tumor.no class, no mask
Unified modelglioma <SEG>class and mask
Question it was never trained on, non-tumorous sliceDescribe this contrast-enhanced T1 brain MRI. Is there a tumor? If so, what type is it and where is it located?
No adaptationThe tumor appears as areas of increased signal intensity on the image, indicating abnormal growth in the head and neck region.invents a tumor
Unified modelNocorrect
Imaging plane question, axial sliceWhich imaging plane is this brain MRI: axial, coronal, or sagittal?
No adaptationaxialcorrect
Unified modelcoronalwrong

The first two cases show the gain from adaptation. The third shows its cost: training on one narrow task made the model lose some general skills, and its free descriptions shrank to a single word. Mixing general question and answer data into training is one way to keep these skills.

The model knows when it is unsure

The four answer scores give a confidence for every prediction, at no extra cost.

Answer confidence
Confidence of the chosen answer. Correct answers have a median confidence of 0.9997, while the 20 wrong answers average 0.78. Keeping only answers with a confidence of 0.99 or more covers 84.3% of the slices at 99.9% accuracy, with a single error. The expected calibration error is 0.009. In practice, the remaining slices could be sent to a radiologist for review.

Case gallery

For each tumor type, the test slices where the unified model scored its best, median and worst Dice, and the two non-tumorous slices with the largest false masks before adaptation. Nothing is hand picked.

ground truthpredicted mask
Input
MedPLIB, no adaptation
EfficientNet-B0 + U-Net
MedPLIB, unified, ours

Team

Simon Tong Sing Hee
Asian School of the Environment
Zeng Yi
College of Computing and Data Science
Feng Peilin
School of Electrical and Electronic Engineering
Ye Xiaomeng
Lee Kong Chian School of Medicine
Lyu Muyang
School of Mechanical and Aerospace Engineering
Timothy Aw Bang Hao
School of Social Sciences