Creates model instances from config. The factory looks up config.model['name'] in the models module namespace and passes every other key of config.model as a constructor keyword argument (flat keys, no params wrapper), e.g. "model": {"name": "UNet3D", "in_channels": 4, "num_classes": 4, "size": 32, "depth": 4}.
🧠 UNet2D.py:
- 2D U-Net architecture
- Configurable:
in_channels,num_classes,size=32(base number of features),depth=3(number of down-sampling levels),t_prime_init=0.1,bias_init=-10.0(learnable SigLIP temperature/bias parameters) - Exposes
bottleneck_channels(size * 2**(depth+1));forward(x, return_bottleneck=False)returns(logits, bottleneck)whenreturn_bottleneck=True, as required by BaseTrainerText - Inputs whose spatial size is not divisible by
2**depthare padded and unpadded automatically (utils/pad_unpad.py)
🧠 UNet3D.py:
- 3D U-Net architecture
- Configurable:
in_channels,num_classes,size=32,depth=3,t_prime_init=0.1,bias_init=-10.0 - Inputs whose spatial size is not divisible by
2**depthare padded and unpadded automatically (utils/pad_unpad.py)
UNet3Dwith a built-in 3DReportGuidanceHeadon the bottleneck- Configurable:
in_channels,num_classes,size=32,depth=3,text_dim=768,guidance_hidden_dim=1024,guidance_out_dim=512 forward(x, text_emb=None): returns the segmentation logits, or(logits, z_img, z_txt)whentext_embis given (used by Trainer_3DText)
ReportGuidanceHead(bottleneck_channels, text_dim=768, hidden_dim=1024, out_dim=512, spatial_dims=2): not a standalone model; projects the bottleneck with a 1x1 conv + global average pooling (spatial_dims2 or 3) and the text embedding with an MLP (Linear -> GELU -> LayerNorm -> Linear) into a sharedout_dimspaceforward(feat, text_emb)returns(z_img [B, out_dim], z_txt [B, out_dim])- Used by BaseTrainerText (2D) and
UNet3DText(3D)
- Create a new file in
models/with your model class that inherits fromBaseModel(or directly fromnn.Module) - Implement
__init__()to define layers - Implement
forward()method that must at least return the output of the model - Add your model class to
__init__.pyin themodels/folder so the ModelFactory can find it:from .YourModel import YourModel
- To use it, specify in config:
"model": {"name": "YourModel", "num_classes": ..., "arg1": ...}(num_classesis required, since it is also read by the trainer and the metrics)