Fine tuning API¶
fine_tune(images_dir, masks_dir, output_dir, *, mode='2D', patch_size=None, initial_weights=None, epochs=10, batch_size=None, steps_per_epoch=None, learning_rate=0.0001, validation_fraction=0.2, validation_images_dir=None, validation_masks_dir=None, seed=42)
¶
Fine tune published weights with paired grayscale TIFFs and instance masks.
Images and masks have matching filename stems in separate directories and
the same shape. Mask value 0 is background; each positive integer
identifies one cell. Training writes best weights, epoch history, and run
metadata into output_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images_dir
|
path - like
|
Directories of paired training images and instance masks. |
required |
masks_dir
|
path - like
|
Directories of paired training images and instance masks. |
required |
output_dir
|
path - like
|
Directory for |
required |
mode
|
('2D', '3D')
|
Dimension of the image data. |
"2D"
|
patch_size
|
int
|
Published model size; defaults to 256 for 2D and 128 for 3D. |
None
|
initial_weights
|
path - like
|
Starting weights. If omitted, use the published model cache. |
None
|
epochs
|
int
|
Maximum number of training epochs. |
10
|
batch_size
|
int
|
Samples per batch; defaults to 4 for 2D and 1 for 3D. |
None
|
steps_per_epoch
|
int
|
Training batches per epoch; inferred from pair count when omitted. |
None
|
learning_rate
|
float
|
Adam optimizer learning rate. |
1e-4
|
validation_fraction
|
float
|
Fraction of pairs held out when no explicit validation set is given. |
0.2
|
validation_images_dir
|
path - like
|
Separate paired validation directories. Supply both or neither. |
None
|
validation_masks_dir
|
path - like
|
Separate paired validation directories. Supply both or neither. |
None
|
seed
|
int
|
Seed for splitting, sampling, and TensorFlow initialization. |
42
|
Returns:
| Type | Description |
|---|---|
FineTuneResult
|
Paths to the saved weights and history, and split sizes. |
FineTuneResult
dataclass
¶
Paths to the best weights and history, with training split sizes.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_path |
Path
|
Best validation weights saved by training. |
history_path |
Path
|
CSV containing metrics for each epoch. |
train_count |
int
|
Number of training image/mask pairs. |
validation_count |
int
|
Number of validation image/mask pairs. |
fine_tune is also available as from morphodeep.training import fine_tune.