After great meetings with @diazandr3s we were able to set the MONAILabel lung segmentation up from scratch, train a model, and autosegment lungs and airways.
Windows: We recommend doing this in Windows 11 using Powershell.
Follow the instructions from the ML Github to install the prerequisites and ML itself.
All in the above link:
- Test that CUDA is available.
- Fork MONAILabel from Github
- Download ML radiology app
- Download lung dataset
Use Slicer 5.1 and ML extension
We found that the Deepedit model is best suited for our task.
We modified the deepedit.py in /apps/lib/conf as follows:
# Single label
self.labels = {
"right lung-1": 1,
"left lung-2": 2,
"airways-3": 3,
"background": 0,
}
# Number of input channels - 4 for BRATS and 1 for spleen
self.number_intensity_ch = 1
network = self.conf.get("network", "dynunet")
# Model Files
self.path = [
os.path.join(self.model_dir, f"pretrained_{self.name}_{network}.pt"), # pretrained
os.path.join(self.model_dir, f"{self.name}_{network}.pt"), # published
]
# Download PreTrained Model
if strtobool(self.conf.get("use_pretrained_model", "false")):
url = f"{self.conf.get('pretrained_path', self.PRE_TRAINED_PATH)}/deepedit_{network}_singlelabel.pt"
download_file(url, self.path[0])
self.target_spacing = (1.0, 1.0, 1.0) # target space for image
self.spatial_size = (128, 128, 64) # train input size
Then we started the ML server with:
monailabel start_server --app apps/radiology --studies datasets/Task06_Lung/imagesTr --conf models deepedit
In 3D Slicer, we connected to ML Server in the ML extension and pressed “Next sample”.
Then we made a couple of lung and airway segmentation with Lung CT Segmenter and “submit Label” for each in ML.
We trained a test model with only 50 epochs, and did an autosegmentation on the “next sample”.
The result was still suboptimal, so I produced 9 more labels in Lung CT Segmenter, uploaded them via “submit Label” to ML one by one, then trained the model with CUDA on my GTX 3070 Ti for 1000 epochs (10 hours)
After that, autosegmentation was very fast and shows promising results: