anomalib
Visualizer()
¶
Anomaly Visualization.
The visualizer object is responsible for collating all the images passed to it into a single image. This can then
either be logged by accessing the figure
attribute or can be saved directly by calling save()
method.
Example
visualizer = Visualizer() visualizer.add_image(image=image, title="Image") visualizer.close()
Source code in quadra/callbacks/anomalib.py
40 41 42 43 44 |
|
add_image(image, title, color_map=None)
¶
Add image to figure.
Parameters:
-
image
(
ndarray
) –Image which should be added to the figure.
-
title
(
str
) –Image title shown on the plot.
-
color_map
(
str | None
, default:None
) –Name of matplotlib color map used to map scalar data to colours. Defaults to None.
Source code in quadra/callbacks/anomalib.py
46 47 48 49 50 51 52 53 54 55 |
|
close()
¶
Close figure.
Source code in quadra/callbacks/anomalib.py
87 88 89 |
|
generate()
¶
Generate the image.
Source code in quadra/callbacks/anomalib.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
save(filename)
¶
Save image.
Parameters:
-
filename
(
Path
) –Filename to save image
Source code in quadra/callbacks/anomalib.py
78 79 80 81 82 83 84 85 |
|
show()
¶
Show image on a matplotlib figure.
Source code in quadra/callbacks/anomalib.py
74 75 76 |
|
VisualizerCallback(task='segmentation', output_path='anomaly_output', inputs_are_normalized=True, threshold_type='pixel', disable=False, plot_only_wrong=False, plot_raw_outputs=False)
¶
Bases: Callback
Callback that visualizes the inference results of a model.
The callback generates a figure showing the original image, the ground truth segmentation mask,
the predicted error heat map, and the predicted segmentation mask.
To save the images to the filesystem, add the 'local' keyword to the project.log_images_to
parameter in the
config.yaml file.
Parameters:
-
task
(
str
, default:'segmentation'
) –either 'segmentation' or 'classification'
-
output_path
(
str
, default:'anomaly_output'
) –location where the images will be saved.
-
inputs_are_normalized
(
bool
, default:True
) –whether the input images are normalized (like when using MinMax or Treshold callback).
-
threshold_type
(
str
, default:'pixel'
) –Either 'pixel' or 'image'. If 'pixel', the threshold is computed on the pixel-level.
-
disable
(
bool
, default:False
) –whether to disable the callback.
-
plot_only_wrong
(
bool
, default:False
) –whether to plot only the images that are not correctly predicted.
-
plot_raw_outputs
(
bool
, default:False
) –Saves the raw images of the segmentation and heatmap output.
Source code in quadra/callbacks/anomalib.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
on_test_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0)
¶
Log images at the end of every batch.
Parameters:
-
trainer
(
Trainer
) –Pytorch lightning trainer object (unused).
-
pl_module
(
AnomalyModule
) –Lightning modules derived from BaseAnomalyLightning object as currently only they support logging images.
-
outputs
(
STEP_OUTPUT | None
) –Outputs of the current test step.
-
batch
(
Any
) –Input batch of the current test step (unused).
-
batch_idx
(
int
) –Index of the current test batch (unused).
-
dataloader_idx
(
int
, default:0
) –Index of the dataloader that yielded the current batch (unused).
Source code in quadra/callbacks/anomalib.py
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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
on_test_end(_trainer, pl_module)
¶
Sync logs.
Currently only AnomalibWandbLogger
is called from this method. This is because logging as a single batch
ensures that all images appear as part of the same step.
Parameters:
-
_trainer
(
Trainer
) –Pytorch Lightning trainer (unused)
-
pl_module
(
LightningModule
) –Anomaly module
Source code in quadra/callbacks/anomalib.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|