konfai.metric package¶
Submodules¶
konfai.metric.measure module¶
Criterion and metric implementations used by KonfAI workflows.
- class konfai.metric.measure.Criterion[source]¶
-
- abstractmethod forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.CriterionWithAttribute[source]¶
Bases:
Criterion- accepts_attributes = True¶
- abstractmethod forward(output, *targets, attributes)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.MaskedLoss(loss, mode_image_masked)[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.MSE(reduction='mean')[source]¶
Bases:
MaskedLoss
- class konfai.metric.measure.MAE(reduction='mean')[source]¶
Bases:
MaskedLoss
- class konfai.metric.measure.ME[source]¶
Bases:
MaskedLoss
- class konfai.metric.measure.MAESaveMap(reduction='mean', dataset=None, group=None)[source]¶
Bases:
MAE- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.PSNR(dynamic_range=None)[source]¶
Bases:
MaskedLoss
- class konfai.metric.measure.SSIM(dynamic_range=None)[source]¶
Bases:
MaskedLoss
- class konfai.metric.measure.LPIPS(model='alex')[source]¶
Bases:
MaskedLoss
- class konfai.metric.measure.TRE[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.Dice(labels=None)[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.DiceSaveMap(labels=None, dataset=None, group=None)[source]¶
Bases:
Dice- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.GradientImages[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.BCE(target=0)[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.PatchGanLoss(target=0)[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.WGP[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.Gram[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.PerceptualLoss(model_loader=<konfai.network.network.ModelLoader object>, path_model='name', modules={'UNetBlock_0.DownConvBlock.Activation_1': <konfai.metric.measure.PerceptualLoss.Module object>}, shape=[128, 128, 128])[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.KLDivergence(shape, dim=100, mu=0, std=1)[source]¶
Bases:
CriterionWithInit- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.Accuracy[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.TripletLoss[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.L1LossRepresentation[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.FocalLoss(gamma=2.0, alpha=[0.5, 2.0, 0.5, 0.5, 1], reduction='mean')[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.FID[source]¶
Bases:
Criterion- class InceptionV3[source]¶
Bases:
Module- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.MutualInformationLoss(num_bins=23, sigma_ratio=0.5, smooth_nr=1e-07, smooth_dr=1e-07)[source]¶
Bases:
Module- forward(pred, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.CrossEntropyLoss(weight=None, reduction='mean')[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.IMPACTReg(name='Reg', model_name='TS/M291.pt', shape=[0, 0], in_channels=3, loss='torch:nn:L1Loss', weights=[0, 1])[source]¶
Bases:
CriterionWithAttribute- forward(output, *targets, attributes)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.IMPACTSynth(model_content_name, model_style_name, shape_content=[0, 0], shape_style=[0, 0], in_channels_content=1, in_channels_style=1, weights_criterion_content=[0, 0, 1], weights_criterion_style=[1, 1, 1])[source]¶
Bases:
CriterionWithAttribute- forward(output, *targets, attributes)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.SAM_Perceptual[source]¶
Bases:
CriterionWithAttribute- forward(output, *targets, attributes)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class konfai.metric.measure.Variance(name='Variance')[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
- class konfai.metric.measure.Mean(name='Mean')[source]¶
Bases:
Criterion- forward(output, *targets)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type:
konfai.metric.schedulers module¶
Schedulers used to modulate metric and loss weights during training.
- class konfai.metric.schedulers.Scheduler(start_value)[source]¶
Bases:
objectBase class for scalar schedulers used by KonfAI criteria.
- class konfai.metric.schedulers.Constant(value=1)[source]¶
Bases:
SchedulerScheduler returning a constant value for all iterations.
- class konfai.metric.schedulers.CosineAnnealing(start_value=1, eta_min=1e-05, t_max=100)[source]¶
Bases:
SchedulerCosine annealing scheduler for criterion weights.
- class konfai.metric.schedulers.Warmup(optimizer, warmup_steps=10, last_epoch=-1, verbose='deprecated')[source]¶
Bases:
LambdaLRLearning-rate warmup wrapper compatible with PyTorch optimizers.
- class konfai.metric.schedulers.PolyLRScheduler(optimizer, initial_lr, max_steps, exponent=0.9, current_step=None)[source]¶
Bases:
_LRScheduler- step(current_step=None)[source]¶
Step the scheduler.
- Parameters:
epoch (int, optional) –
Deprecated since version 1.4: If provided, sets
last_epochtoepochand uses_get_closed_form_lr()if it is available. This is not universally supported. Usestep()without arguments instead.
Note
Call this method after calling the optimizer’s
step().
- get_last_lr()[source]¶
Get the most recent learning rates computed by this scheduler.
- Returns:
A
listof learning rates with entries for each of the optimizer’sparam_groups, with the same types as theirgroup["lr"]s.- Return type:
Note
The returned
Tensors are copies, and never alias the optimizer’sgroup["lr"]s.
Module contents¶
Metric and scheduler primitives used by KonfAI training and evaluation.