Machine learning models
The qim3d
library aims to ease the creation of ML models for volumetric images
qim3d.models.unet
UNet model and Hyperparameters class.
qim3d.models.unet.Hyperparameters
Hyperparameters for QIM segmentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Module
|
PyTorch model. |
required |
n_epochs |
int
|
Number of training epochs. Defaults to 10. |
10
|
learning_rate |
float
|
Learning rate for the optimizer. Defaults to 1e-3. |
0.001
|
optimizer |
str
|
Optimizer algorithm. Must be one of 'Adam', 'SGD', 'RMSprop'. Defaults to 'Adam'. |
'Adam'
|
momentum |
float
|
Momentum value for SGD and RMSprop optimizers. Defaults to 0. |
0
|
weight_decay |
float
|
Weight decay (L2 penalty) for the optimizer. Defaults to 0. |
0
|
loss_function |
str
|
Loss function criterion. Must be one of 'BCE', 'Dice', 'Focal', 'DiceCE'. Defaults to 'BCE'. |
'Focal'
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
Example
import qim3d
# This examples shows how to define a UNet model and its hyperparameters.
# Defining the model
my_model = qim3d.models.UNet(size='medium')
# Choosing the hyperparameters
hyperparams = qim3d.models.Hyperparameters(model=my_model, n_epochs=20, learning_rate=0.001)
params_dict = hyperparams() # Get the hyperparameters
optimizer = params_dict['optimizer']
criterion = params_dict['criterion']
n_epochs = params_dict['n_epochs']
Source code in qim3d/models/unet.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
qim3d.models.unet.UNet
Bases: Module
2D UNet model for QIM imaging.
This class represents a 2D UNet model designed for imaging segmentation tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
str
|
Size of the UNet model. Must be one of 'small', 'medium', or 'large'. Defaults to 'medium'. |
'medium'
|
dropout |
float
|
Dropout rate between 0 and 1. Defaults to 0. |
0
|
kernel_size |
int
|
Convolution kernel size. Defaults to 3. |
3
|
up_kernel_size |
int
|
Up-convolution kernel size. Defaults to 3. |
3
|
activation |
str
|
Activation function. Defaults to 'PReLU'. |
'PReLU'
|
bias |
bool
|
Whether to include bias in convolutions. Defaults to True. |
True
|
adn_order |
str
|
ADN (Activation, Dropout, Normalization) ordering. Defaults to 'NDA'. |
'NDA'
|
Raises:
Type | Description |
---|---|
ValueError
|
If |