CBCT Maxillofacial Segmentation (ToothFairy2 nnU-Net ResEnc-L)
Replaces the old 2D tooth-only U-Net. Segments jaws, inferior alveolar canals,
maxillary sinuses and all 32 teeth from a CBCT .nii.gz, and returns one
colored .glb scene (one named node per structure) for Unity (glTFast).
app.py– Gradio app. Exposesprocess_nifti→/gradio_api/call/process_nifti.make_glb.py– label volume → colored multi-node GLB (marching cubes).model/– the trained nnU-Net (plans.json,dataset.json,fold_0/checkpoint_best.pth).requirements.txt– CPU torch/torchvision (pinned & matched) + nnU-Net + mesh stack.
⚠️ Performance note
This runs on the free CPU Space. The model is a 3D nnU-Net; inference is several minutes per scan (TTA disabled, large sliding-window step to cope with CPU). The 49-class probability volume is memory-heavy — if the Space OOMs on large scans, upgrade to a GPU Space or reduce input resolution.
Updating the live Space (replace the old model)
The Space repo is a git repo. The 236 MB checkpoint must go through git LFS.
# 1. Clone the existing Space (uses your HF token / git credential helper)
git clone https://huggingface.co/spaces/mostafamousa/gp-segmentation
cd gp-segmentation
# 2. Remove the old 2D model and copy the new files in
git rm -f model.pth # old 2D U-Net weights
# copy app.py, make_glb.py, requirements.txt, README.md and the model/ folder
# from this Hugging_Face_Deployment/ folder into the clone, overwriting.
# 3. Track the checkpoint with LFS
git lfs install
git lfs track "*.pth"
git add .gitattributes
# 4. Commit and push
git add app.py make_glb.py requirements.txt README.md model/
git commit -m "Swap 2D U-Net for ToothFairy2 nnU-Net ResEnc-L; output combined GLB"
git push
The Space rebuilds automatically. First build is slow (installs torch + nnU-Net).
Unity client
The Unity client (openGradio.cs) now downloads the single .glb and loads it
with glTFast. Install glTFast via Package Manager (com.unity.cloud.gltfast)
and ensure a Tooth tag exists in Project Settings → Tags and Layers.