prediction_writer_callback
Module containing PredictionWriterCallback class.
PredictionWriterCallback #
Bases: BasePredictionWriter
PyTorch Lightning callback to save predictions.
A WriteStrategy must be provided at instantiation or later via set_writing_strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dirpath | Path or str | The path to the directory where prediction outputs will be saved. If | "predictions" |
write_strategy | WriteStrategy or None | A strategy for writing predictions. | None |
Attributes:
| Name | Type | Description |
|---|---|---|
writing_predictions | bool | If writing predictions is turned on or off. |
dirpath | pathlib.Path, default="" | The path to the directory where prediction outputs will be saved. If |
write_strategy | WriteStrategy or None | A strategy for writing predictions. |
Source code in src/careamics/lightning/dataset_ng/callbacks/prediction_writer/prediction_writer_callback.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 | |
__init__(dirpath='', write_strategy=None) #
Constructor.
A WriteStrategy must be provided at instantiation or later via set_writing_strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dirpath | Path or str | The path to the directory where prediction outputs will be saved. If | "predictions" |
write_strategy | WriteStrategy or None | A strategy for writing predictions. | None |
Source code in src/careamics/lightning/dataset_ng/callbacks/prediction_writer/prediction_writer_callback.py
disable_writing(disable_writing) #
Disable writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
disable_writing | bool | If writing predictions should be disabled. | required |
Source code in src/careamics/lightning/dataset_ng/callbacks/prediction_writer/prediction_writer_callback.py
set_writing_strategy(write_type, tiled, write_func=None, write_extension=None, write_func_kwargs=None) #
Set the writing strategy.
Must be called before writing predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
write_type | SupportedWriteType | The type of writing to perform. | required |
tiled | bool | Whether to write in tiled format. | required |
write_func | WriteFunc or None | A custom writing function. | None |
write_extension | str or None | The file extension to use when writing files. | None |
write_func_kwargs | dict of str to Any | Additional keyword arguments to pass to | None |
Source code in src/careamics/lightning/dataset_ng/callbacks/prediction_writer/prediction_writer_callback.py
setup(trainer, pl_module, stage) #
Create the prediction output directory when predict begins.
Called when fit, validate, test, predict, or tune begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainer | Trainer | PyTorch Lightning trainer. | required |
pl_module | LightningModule | PyTorch Lightning module. | required |
stage | str | Stage of training e.g. 'predict', 'fit', 'validate'. | required |
Source code in src/careamics/lightning/dataset_ng/callbacks/prediction_writer/prediction_writer_callback.py
write_on_batch_end(trainer, pl_module, prediction, batch_indices, batch, batch_idx, dataloader_idx) #
Write predictions at the end of a batch.
Writing method is determined by the attribute write_strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainer | Trainer | PyTorch Lightning trainer. | required |
pl_module | LightningModule | PyTorch Lightning module. | required |
prediction | ImageRegionData | Prediction outputs of | required |
batch_indices | sequence of Any | Batch indices. | required |
batch | ImageRegionData | Input batch. | required |
batch_idx | int | Batch index. | required |
dataloader_idx | int | Dataloader index. | required |