Valentin Boussot
commited on
Commit
·
b59fff8
1
Parent(s):
a5d671c
Add config
Browse files- CBCT/Model.py +63 -0
- CBCT/Prediction.yml +84 -0
- CBCT/metadata.json +7 -0
- CBCT/requirements.txt +1 -0
- MR/Model.py +63 -0
- MR/Prediction.yml +72 -0
- MR/metadata.json +7 -0
- MR/requirements.txt +1 -0
CBCT/Model.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from konfai.network import network
|
| 2 |
+
import segmentation_models_pytorch as smp
|
| 3 |
+
import torch
|
| 4 |
+
from konfai.predictor import Reduction
|
| 5 |
+
from konfai.data.transform import Transform
|
| 6 |
+
from konfai.utils.dataset import Attribute, Dataset, data_to_image
|
| 7 |
+
|
| 8 |
+
class Head(network.ModuleArgsDict):
|
| 9 |
+
|
| 10 |
+
def __init__(self):
|
| 11 |
+
super().__init__()
|
| 12 |
+
self.add_module("Tanh", torch.nn.Tanh())
|
| 13 |
+
|
| 14 |
+
class UNetpp(network.Network):
|
| 15 |
+
|
| 16 |
+
def __init__(self,
|
| 17 |
+
optimizer : network.OptimizerLoader = network.OptimizerLoader(),
|
| 18 |
+
schedulers: dict[str, network.LRSchedulersLoader] = {
|
| 19 |
+
"default:ReduceLROnPlateau": network.LRSchedulersLoader(0)
|
| 20 |
+
},
|
| 21 |
+
outputs_criterions: dict[str, network.TargetCriterionsLoader] = {"default" : network.TargetCriterionsLoader()},
|
| 22 |
+
pretrained: bool = False):
|
| 23 |
+
super().__init__(in_channels = 3, optimizer = optimizer, schedulers = schedulers, outputs_criterions = outputs_criterions, dim = 2)
|
| 24 |
+
self.add_module("model", smp.UnetPlusPlus(
|
| 25 |
+
encoder_name="resnet34",
|
| 26 |
+
encoder_weights=None if not pretrained else "imagenet",
|
| 27 |
+
in_channels=3,
|
| 28 |
+
classes=1,
|
| 29 |
+
activation=None
|
| 30 |
+
))
|
| 31 |
+
self.add_module("Head", Head())
|
| 32 |
+
|
| 33 |
+
class Concat(Reduction):
|
| 34 |
+
|
| 35 |
+
def __init__(self):
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
def __call__(self, tensors: list[torch.Tensor]) -> torch.Tensor:
|
| 39 |
+
return torch.cat(tensors, dim=1)
|
| 40 |
+
|
| 41 |
+
class Uncertainty(Transform):
|
| 42 |
+
|
| 43 |
+
def __init__(self):
|
| 44 |
+
pass
|
| 45 |
+
|
| 46 |
+
def __call__(self, name: str, tensors: torch.Tensor, cache_attribute: Attribute) -> torch.Tensor:
|
| 47 |
+
for i, tensor in enumerate(tensors):
|
| 48 |
+
dataset = Dataset("./Predictions/ImpactSynth/Dataset", "mha")
|
| 49 |
+
dataset.write(f"sCT_{i}", name, data_to_image(tensor.unsqueeze(0).numpy(), cache_attribute))
|
| 50 |
+
return tensors.mean(0).unsqueeze(0)
|
| 51 |
+
|
| 52 |
+
class UnNormalize(Transform):
|
| 53 |
+
|
| 54 |
+
def __init__(self) -> None:
|
| 55 |
+
super().__init__()
|
| 56 |
+
self.v_min = -1024
|
| 57 |
+
self.v_max = 3071
|
| 58 |
+
|
| 59 |
+
def __call__(self, name: str, input : torch.Tensor, cache_attribute: Attribute) -> torch.Tensor:
|
| 60 |
+
return (input + 1)/2*(self.v_max-self.v_min) + self.v_min
|
| 61 |
+
|
| 62 |
+
def inverse(self, name: str, input : torch.Tensor, cache_attribute: Attribute) -> torch.Tensor:
|
| 63 |
+
pass
|
CBCT/Prediction.yml
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Predictor:
|
| 2 |
+
Model:
|
| 3 |
+
classpath: Model:UNetpp
|
| 4 |
+
UNetpp:
|
| 5 |
+
outputs_criterions: None
|
| 6 |
+
pretrained: false
|
| 7 |
+
Dataset:
|
| 8 |
+
groups_src:
|
| 9 |
+
Volume:
|
| 10 |
+
groups_dest:
|
| 11 |
+
Volume:
|
| 12 |
+
transforms:
|
| 13 |
+
Clip:
|
| 14 |
+
min_value: min
|
| 15 |
+
max_value: percentile:99.5
|
| 16 |
+
save_clip_min: false
|
| 17 |
+
save_clip_max: false
|
| 18 |
+
mask: None
|
| 19 |
+
Normalize:
|
| 20 |
+
lazy: true
|
| 21 |
+
channels: None
|
| 22 |
+
min_value: -1
|
| 23 |
+
max_value: 1
|
| 24 |
+
inverse: true
|
| 25 |
+
patch_transforms:
|
| 26 |
+
Normalize:
|
| 27 |
+
lazy: false
|
| 28 |
+
channels: None
|
| 29 |
+
min_value: -1
|
| 30 |
+
max_value: 1
|
| 31 |
+
inverse: true
|
| 32 |
+
is_input: true
|
| 33 |
+
augmentations:
|
| 34 |
+
DataAugmentation_0:
|
| 35 |
+
data_augmentations:
|
| 36 |
+
Flip:
|
| 37 |
+
f_prob:
|
| 38 |
+
- 0
|
| 39 |
+
- 0.5
|
| 40 |
+
- 0.5
|
| 41 |
+
prob: 1
|
| 42 |
+
nb: 2
|
| 43 |
+
Patch:
|
| 44 |
+
patch_size:
|
| 45 |
+
- 1
|
| 46 |
+
- 512
|
| 47 |
+
- 512
|
| 48 |
+
overlap: None
|
| 49 |
+
mask: None
|
| 50 |
+
pad_value: -1
|
| 51 |
+
extend_slice: 2
|
| 52 |
+
subset: None
|
| 53 |
+
filter: None
|
| 54 |
+
dataset_filenames:
|
| 55 |
+
- ./Dataset:nii.gz
|
| 56 |
+
use_cache: false
|
| 57 |
+
batch_size: 8
|
| 58 |
+
outputs_dataset:
|
| 59 |
+
Head:Tanh:
|
| 60 |
+
OutputDataset:
|
| 61 |
+
name_class: OutSameAsGroupDataset
|
| 62 |
+
before_reduction_transforms: None
|
| 63 |
+
after_reduction_transforms: None
|
| 64 |
+
final_transforms:
|
| 65 |
+
Model:UnNormalize: {}
|
| 66 |
+
Model:Uncertainty: {}
|
| 67 |
+
TensorCast:
|
| 68 |
+
dtype: int16
|
| 69 |
+
inverse: true
|
| 70 |
+
dataset_filename: Dataset:mha
|
| 71 |
+
group: sCT
|
| 72 |
+
same_as_group: Volume:Volume
|
| 73 |
+
patch_combine: None
|
| 74 |
+
inverse_transform: false
|
| 75 |
+
reduction: Model:Concat
|
| 76 |
+
Model:Concat: {}
|
| 77 |
+
train_name: ImpactSynth
|
| 78 |
+
manual_seed: 32
|
| 79 |
+
gpu_checkpoints: None
|
| 80 |
+
images_log: None
|
| 81 |
+
combine: Model:Concat
|
| 82 |
+
autocast: false
|
| 83 |
+
data_log: None
|
| 84 |
+
Model:Concat: {}
|
CBCT/metadata.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"display_name": "CBCT",
|
| 3 |
+
"short_description": "<b>Description:</b><br>Supervised CBCT synthesis model developed as part of the <a href=\"https://synthrad2025.grand-challenge.org/\">SynthRAD 2025 Challenge (Task 2)</a>.<br><br><b>How to cite:</b><br><cite>V. Boussot et al., <i>Why Registration Quality Matters: Enhancing sCT Synthesis with IMPACT-Based Registration</i>, arXiv preprint arXiv:2510.21358, <a href=\"https://doi.org/10.48550/arXiv.2510.21358\">https://doi.org/10.48550/arXiv.2510.21358</a>.</cite>",
|
| 4 |
+
"description": "<b>Description:</b><br>Supervised CBCT synthesis model developed as part of the <a href=\"https://synthrad2025.grand-challenge.org/\">SynthRAD 2025 Challenge (Task 2)</a>.<br><br><b>Architecture:</b><br>Based on a 2.5D UNet++ with a ResNet34 encoder, the model was optimized using the <b>IMPACT-Synth loss</b>, a perceptual loss leveraging semantic priors from <b>SAM 2.1-s</b>. Training was conducted with the <b>KonfAI</b> deep learning framework.<br><br><b>Training data:</b><br>Paired CT–CBCT volumes from the <a href=\"https://synthrad2025.grand-challenge.org/\">SynthRAD 2025 Challenge (Task 2)</a>, <b>aligned using IMPACT-based registration</b>. Corresponding B-spline deformation fields are available in the <a href=\"https://huggingface.co/datasets/VBoussot/synthrad2025-impact-registration\">SynthRAD2025-IMPACT (aligned)</a> dataset repository.<br><br><b>How to cite:</b><br><cite>V. Boussot et al., <i>Why Registration Quality Matters: Enhancing sCT Synthesis with IMPACT-Based Registration</i>, arXiv preprint arXiv:2510.21358, <a href=\"https://doi.org/10.48550/arXiv.2510.21358\">https://doi.org/10.48550/arXiv.2510.21358</a>.</cite>",
|
| 5 |
+
"tta": 2,
|
| 6 |
+
"mc_dropout": false
|
| 7 |
+
}
|
CBCT/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
segmentation_models_pytorch
|
MR/Model.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from konfai.network import network
|
| 2 |
+
import segmentation_models_pytorch as smp
|
| 3 |
+
import torch
|
| 4 |
+
from konfai.predictor import Reduction
|
| 5 |
+
from konfai.data.transform import Transform
|
| 6 |
+
from konfai.utils.dataset import Attribute, Dataset, data_to_image
|
| 7 |
+
|
| 8 |
+
class Head(network.ModuleArgsDict):
|
| 9 |
+
|
| 10 |
+
def __init__(self):
|
| 11 |
+
super().__init__()
|
| 12 |
+
self.add_module("Tanh", torch.nn.Tanh())
|
| 13 |
+
|
| 14 |
+
class UNetpp(network.Network):
|
| 15 |
+
|
| 16 |
+
def __init__(self,
|
| 17 |
+
optimizer : network.OptimizerLoader = network.OptimizerLoader(),
|
| 18 |
+
schedulers: dict[str, network.LRSchedulersLoader] = {
|
| 19 |
+
"default:ReduceLROnPlateau": network.LRSchedulersLoader(0)
|
| 20 |
+
},
|
| 21 |
+
outputs_criterions: dict[str, network.TargetCriterionsLoader] = {"default" : network.TargetCriterionsLoader()},
|
| 22 |
+
pretrained: bool = False):
|
| 23 |
+
super().__init__(in_channels = 3, optimizer = optimizer, schedulers = schedulers, outputs_criterions = outputs_criterions, dim = 2)
|
| 24 |
+
self.add_module("model", smp.UnetPlusPlus(
|
| 25 |
+
encoder_name="resnet34",
|
| 26 |
+
encoder_weights=None if not pretrained else "imagenet",
|
| 27 |
+
in_channels=3,
|
| 28 |
+
classes=1,
|
| 29 |
+
activation=None
|
| 30 |
+
))
|
| 31 |
+
self.add_module("Head", Head())
|
| 32 |
+
|
| 33 |
+
class Concat(Reduction):
|
| 34 |
+
|
| 35 |
+
def __init__(self):
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
def __call__(self, tensors: list[torch.Tensor]) -> torch.Tensor:
|
| 39 |
+
return torch.cat(tensors, dim=1)
|
| 40 |
+
|
| 41 |
+
class Uncertainty(Transform):
|
| 42 |
+
|
| 43 |
+
def __init__(self):
|
| 44 |
+
pass
|
| 45 |
+
|
| 46 |
+
def __call__(self, name: str, tensors: torch.Tensor, cache_attribute: Attribute) -> torch.Tensor:
|
| 47 |
+
for i, tensor in enumerate(tensors):
|
| 48 |
+
dataset = Dataset("./Predictions/ImpactSynth/Dataset", "mha")
|
| 49 |
+
dataset.write(f"sCT_{i}", name, data_to_image(tensor.unsqueeze(0).numpy(), cache_attribute))
|
| 50 |
+
return tensors.mean(0).unsqueeze(0)
|
| 51 |
+
|
| 52 |
+
class UnNormalize(Transform):
|
| 53 |
+
|
| 54 |
+
def __init__(self) -> None:
|
| 55 |
+
super().__init__()
|
| 56 |
+
self.v_min = -1024
|
| 57 |
+
self.v_max = 3071
|
| 58 |
+
|
| 59 |
+
def __call__(self, name: str, input : torch.Tensor, cache_attribute: Attribute) -> torch.Tensor:
|
| 60 |
+
return (input + 1)/2*(self.v_max-self.v_min) + self.v_min
|
| 61 |
+
|
| 62 |
+
def inverse(self, name: str, input : torch.Tensor, cache_attribute: Attribute) -> torch.Tensor:
|
| 63 |
+
pass
|
MR/Prediction.yml
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Predictor:
|
| 2 |
+
Model:
|
| 3 |
+
classpath: Model:UNetpp
|
| 4 |
+
UNetpp:
|
| 5 |
+
outputs_criterions: None
|
| 6 |
+
pretrained: false
|
| 7 |
+
Dataset:
|
| 8 |
+
groups_src:
|
| 9 |
+
Volume:
|
| 10 |
+
groups_dest:
|
| 11 |
+
Volume:
|
| 12 |
+
transforms:
|
| 13 |
+
Standardize:
|
| 14 |
+
lazy: false
|
| 15 |
+
mean: None
|
| 16 |
+
std: None
|
| 17 |
+
mask: None
|
| 18 |
+
inverse: true
|
| 19 |
+
patch_transforms: None
|
| 20 |
+
is_input: true
|
| 21 |
+
augmentations:
|
| 22 |
+
DataAugmentation_0:
|
| 23 |
+
data_augmentations:
|
| 24 |
+
Flip:
|
| 25 |
+
f_prob:
|
| 26 |
+
- 0
|
| 27 |
+
- 0.5
|
| 28 |
+
- 0.5
|
| 29 |
+
prob: 1
|
| 30 |
+
nb: 2
|
| 31 |
+
Patch:
|
| 32 |
+
patch_size:
|
| 33 |
+
- 1
|
| 34 |
+
- 512
|
| 35 |
+
- 512
|
| 36 |
+
overlap: None
|
| 37 |
+
mask: None
|
| 38 |
+
pad_value: -1
|
| 39 |
+
extend_slice: 2
|
| 40 |
+
subset: None
|
| 41 |
+
filter: None
|
| 42 |
+
dataset_filenames:
|
| 43 |
+
- ./Dataset:nii.gz
|
| 44 |
+
use_cache: false
|
| 45 |
+
batch_size: 8
|
| 46 |
+
outputs_dataset:
|
| 47 |
+
Head:Tanh:
|
| 48 |
+
OutputDataset:
|
| 49 |
+
name_class: OutSameAsGroupDataset
|
| 50 |
+
before_reduction_transforms: None
|
| 51 |
+
after_reduction_transforms: None
|
| 52 |
+
final_transforms:
|
| 53 |
+
Model:UnNormalize: {}
|
| 54 |
+
Model:Uncertainty: {}
|
| 55 |
+
TensorCast:
|
| 56 |
+
dtype: int16
|
| 57 |
+
inverse: true
|
| 58 |
+
dataset_filename: Dataset:mha
|
| 59 |
+
group: sCT
|
| 60 |
+
same_as_group: Volume:Volume
|
| 61 |
+
patch_combine: None
|
| 62 |
+
inverse_transform: false
|
| 63 |
+
reduction: Model:Concat
|
| 64 |
+
Model:Concat: {}
|
| 65 |
+
train_name: ImpactSynth
|
| 66 |
+
manual_seed: 32
|
| 67 |
+
gpu_checkpoints: None
|
| 68 |
+
images_log: None
|
| 69 |
+
combine: Model:Concat
|
| 70 |
+
autocast: false
|
| 71 |
+
data_log: None
|
| 72 |
+
Model:Concat: {}
|
MR/metadata.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"display_name": "MR",
|
| 3 |
+
"short_description": "<b>Description:</b><br>Supervised MRI (T1-weighted) synthesis model developed as part of the <a href=\"https://synthrad2025.grand-challenge.org/\">SynthRAD 2025 Challenge (Task 1)</a>.<br><br><b>How to cite:</b><br><cite>V. Boussot et al., <i>Why Registration Quality Matters: Enhancing sCT Synthesis with IMPACT-Based Registration</i>, arXiv preprint arXiv:2510.21358, <a href=\"https://doi.org/10.48550/arXiv.2510.21358\">https://doi.org/10.48550/arXiv.2510.21358</a>.</cite>",
|
| 4 |
+
"description": "<b>Description:</b><br>Supervised MRI (T1-weighted) synthesis model developed as part of the <a href=\"https://synthrad2025.grand-challenge.org/\">SynthRAD 2025 Challenge (Task 1)</a>.<br><br><b>Architecture:</b><br>Based on a 2.5D UNet++ with a ResNet34 encoder, the model was optimized using the <b>IMPACT-Synth loss</b>, a perceptual loss leveraging semantic priors from <b>SAM 2.1-s</b>. Training was conducted with the <b>KonfAI</b> deep learning framework.<br><br><b>Training data:</b><br>Paired CT–MRI (T1-weighted) volumes from the <a href=\"https://synthrad2025.grand-challenge.org/\">SynthRAD 2025 Challenge (Task 1)</a>, <b>aligned using IMPACT-based registration</b>. Corresponding B-spline deformation fields are available in the <a href=\"https://huggingface.co/datasets/VBoussot/synthrad2025-impact-registration\">SynthRAD2025-IMPACT (aligned)</a> dataset repository.<br><br><b>How to cite:</b><br><cite>V. Boussot et al., <i>Why Registration Quality Matters: Enhancing sCT Synthesis with IMPACT-Based Registration</i>, arXiv preprint arXiv:2510.21358, <a href=\"https://doi.org/10.48550/arXiv.2510.21358\">https://doi.org/10.48550/arXiv.2510.21358</a>.</cite>",
|
| 5 |
+
"tta": 2,
|
| 6 |
+
"mc_dropout": false
|
| 7 |
+
}
|
MR/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
segmentation_models_pytorch
|