dlsia.core.networks package
Submodules
dlsia.core.conformalize.conformalize_segmentation module
- dlsia.core.conformalize.conformalize_segmentation.build_conformalizer_classify(model, testloader, alpha=0.1, missing_label=-1, device='cuda:0', norma=True)
Given a model, some test data, a threshold alpha, build me a conformalizer object
- Parameters:
model (a neural network) – the input neural network
testloader (pytorch data loader) – pytorch data loader
alpha (float) – the level alpha
missing_label (int, typically -1) – missing label - data can be annotated sparsely
device ('cpu' / 'cuda:0') – where do we calculate things
norma (bool) – does the network return a normalized score? If False, run an additonal softmax
- Returns:
a conformalize_classification object
- Return type:
- class dlsia.core.conformalize.conformalize_segmentation.conformalize_classification(alpha, estimated_label_probabilities, true_labels)
Bases:
ModuleConformalize a set of predictions. This is performed on hold-out data.
- forward(p_scores)
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.
- recalibrate(alpha=None)
Reset thresholds such that a new confidence limit is returned
- Parameters:
alpha (float) – The power of the test / level of confidence interval
- Returns:
qhat, the score threshold
- Return type:
float
- training: bool
- dlsia.core.conformalize.conformalize_segmentation.does_not_have_label_in_set(conformal_set, label)
Checks if a conformal set does not contain a specific label
- Parameters:
conformal_set (torch.Tensor, type bool (N,C, ...)) – The conformal set
label (torch.Tensor, type int) – the label of interest
- Returns:
does it have this label
- Return type:
torch.Tensor, type bool (N, …)
- dlsia.core.conformalize.conformalize_segmentation.has_label_in_set(conformal_set, label)
Checks if a conformal set contains a specific label
- Parameters:
conformal_set (torch.Tensor, type bool (N,C, ...)) – The conformal set
label (torch.Tensor, type int) – the label of interest
- Returns:
does it have this label
- Return type:
torch.Tensor, type bool (N, …)
- dlsia.core.conformalize.conformalize_segmentation.index_it(scores, labs)
index the scores
- Parameters:
scores – scores
labs – labels
- Returns:
indexed scores
- Return type:
- dlsia.core.conformalize.conformalize_segmentation.set_size(conformal_set)
Compute the size of the conformal set, i.e. how many elements are in the set. The shape of the conformal_set tensor should be (N C …), we count the number of elements in channel 1. The conformal set is an indicator array, i.e. it contains True / False for each class.
- Parameters:
conformal_set (torch.Tensor, type bool) – The conformal set
- Returns:
The size of the conformal set
- Return type:
(N, ….), type int