Mc-Dropout mean standard deviation query strategy. Returns the indexes of the instances with the largest mean of the per class calculated standard deviations over multiple dropout cycles and the corresponding metric. Based on the equations of: Deep Bay
(classifier: BaseEstimator, X: modALinput, n_instances: int = 1,
random_tie_break: bool = False, dropout_layer_indexes: list = [],
num_cycles: int = 50, sample_per_forward_pass: int = 1000,
logits_adaptor: Callable[[
torch.tensor, modALinput], torch.tensor] = default_logits_adaptor,
**mc_dropout_kwargs)
| 69 | |
| 70 | |
| 71 | def mc_dropout_mean_st(classifier: BaseEstimator, X: modALinput, n_instances: int = 1, |
| 72 | random_tie_break: bool = False, dropout_layer_indexes: list = [], |
| 73 | num_cycles: int = 50, sample_per_forward_pass: int = 1000, |
| 74 | logits_adaptor: Callable[[ |
| 75 | torch.tensor, modALinput], torch.tensor] = default_logits_adaptor, |
| 76 | **mc_dropout_kwargs) -> np.ndarray: |
| 77 | """ |
| 78 | Mc-Dropout mean standard deviation query strategy. Returns the indexes of the instances |
| 79 | with the largest mean of the per class calculated standard deviations over multiple dropout cycles |
| 80 | and the corresponding metric. |
| 81 | |
| 82 | Based on the equations of: |
| 83 | Deep Bayesian Active Learning with Image Data. |
| 84 | (Yarin Gal, Riashat Islam, and Zoubin Ghahramani. 2017.) |
| 85 | |
| 86 | Args: |
| 87 | classifier: The classifier for which the labels are to be queried. |
| 88 | X: The pool of samples to query from. |
| 89 | n_instances: Number of samples to be queried. |
| 90 | random_tie_break: If True, shuffles utility scores to randomize the order. This |
| 91 | can be used to break the tie when the highest utility score is not unique. |
| 92 | dropout_layer_indexes: Indexes of the dropout layers which should be activated |
| 93 | Choose indices from : list(torch_model.modules()) |
| 94 | num_cycles: Number of forward passes with activated dropout |
| 95 | sample_per_forward_pass: max. sample number for each forward pass. |
| 96 | The allocated RAM does mainly depend on this. |
| 97 | Small number --> small RAM allocation |
| 98 | logits_adaptor: Callable which can be used to adapt the output of a forward pass |
| 99 | to the required vector format for the vectorised metric functions |
| 100 | **uncertainty_measure_kwargs: Keyword arguments to be passed for the uncertainty |
| 101 | measure function. |
| 102 | |
| 103 | Returns: |
| 104 | The indices of the instances from X chosen to be labelled; |
| 105 | The mc-dropout metric of the chosen instances; |
| 106 | """ |
| 107 | |
| 108 | # set dropout layers to train mode |
| 109 | predictions = get_predictions( |
| 110 | classifier, X, dropout_layer_indexes, num_cycles, sample_per_forward_pass, logits_adaptor) |
| 111 | |
| 112 | mean_standard_deviations = _mean_standard_deviation(predictions) |
| 113 | |
| 114 | if not random_tie_break: |
| 115 | return multi_argmax(mean_standard_deviations, n_instances=n_instances) |
| 116 | |
| 117 | return shuffled_argmax(mean_standard_deviations, n_instances=n_instances) |
| 118 | |
| 119 | |
| 120 | def mc_dropout_max_entropy(classifier: BaseEstimator, X: modALinput, n_instances: int = 1, |
nothing calls this directly
no test coverage detected
searching dependent graphs…