Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try ensembling/bagging for prediction #63

Open
jcohenadad opened this issue Jan 30, 2023 · 5 comments
Open

Try ensembling/bagging for prediction #63

jcohenadad opened this issue Jan 30, 2023 · 5 comments

Comments

@jcohenadad
Copy link
Member

jcohenadad commented Jan 30, 2023

Concept

Training several models in production (split 80/20/0) with different seeds, the idea is to average all predictions to generate a more reliable soft prediction (ie: bagging ensemble).

Prototyping script
# Loop across multiple subjects
list_sub=(001 002 003 004 005)
for sub in ${list_sub[@]}; do
  # Crop input image
  sct_deepseg_sc -i ~/data.neuro/basel-mp2rage/sub-P${sub}/anat/sub-P${sub}_UNIT1.nii.gz -c t1 
  sct_maths -i sub-P${sub}_UNIT1_seg.nii.gz -dilate 5 -shape ball -o sub-P${sub}_UNIT1_seg_dilate.nii.gz
  sct_maths -i sub-P${sub}_UNIT1_seg_dilate.nii.gz -dilate 32 -dim 1 -shape disk -o sub-P${sub}_UNIT1_seg_dilate.nii.gz
  sct_crop_image -i /Users/julien/data.neuro/basel-mp2rage/sub-P${sub}/anat/sub-P${sub}_UNIT1.nii.gz -m sub-P${sub}_UNIT1_seg_dilate.nii.gz -o sub-P${sub}_UNIT1_crop.nii.gz
  # Loop across models and run prediction
  list_seed=(7 8 9 10 11)
  for seed in ${list_seed[@]}; do ivadomed_segment_image -i sub-P${sub}_UNIT1_crop.nii.gz -m models/seed${seed}/model_seg_lesion_mp2rage -s _pred${seed}; done
  # Average
  sct_image -i sub-P${sub}_UNIT1_crop_pred*.nii.gz -concat t -o sub-P${sub}_UNIT1_crop_predMean.nii.gz
  sct_maths -i sub-P${sub}_UNIT1_crop_predMean.nii.gz -mean t -o sub-P${sub}_UNIT1_crop_predMean.nii.gz
  # Display
  fsleyes -S ~/data.neuro/basel-mp2rage/sub-P${sub}/anat/sub-P${sub}_UNIT1.nii.gz sub-P${sub}_UNIT1_crop_predMean.nii.gz -cm red-yellow
done
@jcohenadad
Copy link
Member Author

jcohenadad commented Jan 30, 2023

Results

The prediction is averaged across 5 models (yellow: high confidence, red: low confidence).

P001

anim

P002

anim

P003

anim

P004

anim

@Nilser3
Copy link
Contributor

Nilser3 commented May 30, 2023

Hi @jcohenadad
Following this pipeline,
Test on a UNI and T1q contrasts from CRMBM, Marseille dataset,

Results UNI image:
UNI
UNI_2
UNI_cor
DSC (lesion_GT VS lesion_seg_thr_0.5) = 0.456
cDSC (lesion_GT VS lesion_seg) = 0.39

Results T1q image:
T1q
Fail to segment T1q contrast, models trained in UNI contrast only, perhaps.

@jcohenadad
Copy link
Member Author

Very cool @Nilser3 ! Could you please clarify which version of the model you used? Which release (if you used a release). I find that results are pretty decent 😊

@Nilser3
Copy link
Contributor

Nilser3 commented May 30, 2023

yes! @jcohenadad
I used this release : r20230210

@Nilser3
Copy link
Contributor

Nilser3 commented Jun 15, 2023

Hi @jcohenadad

Continuing the ensembling test on the Marseille data (40 subjects with 3T UNI contrast)
I calculated the Continuous Dice Coefficient for "soft masks" based on this implementation and the Classic Dice between the GT and binarized masks (thresholding at 1/5 = 0.2) because we have 5 segmentation models.

image

There are 2 empy masks from GT (subject 3 and 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants