Mc-Dropout maximum entropy query strategy. Returns the indexes of the instances with the largest entropy of the per class calculated entropies over multiple dropout cycles and the corresponding metric. Based on the equations of: Deep Bayesian Active Le
(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)
| 118 | |
| 119 | |
| 120 | def mc_dropout_max_entropy(classifier: BaseEstimator, X: modALinput, n_instances: int = 1, |
| 121 | random_tie_break: bool = False, dropout_layer_indexes: list = [], |
| 122 | num_cycles: int = 50, sample_per_forward_pass: int = 1000, |
| 123 | logits_adaptor: Callable[[ |
| 124 | torch.tensor, modALinput], torch.tensor] = default_logits_adaptor, |
| 125 | **mc_dropout_kwargs) -> np.ndarray: |
| 126 | """ |
| 127 | Mc-Dropout maximum entropy query strategy. Returns the indexes of the instances |
| 128 | with the largest entropy of the per class calculated entropies over multiple dropout cycles |
| 129 | and the corresponding metric. |
| 130 | |
| 131 | Based on the equations of: |
| 132 | Deep Bayesian Active Learning with Image Data. |
| 133 | (Yarin Gal, Riashat Islam, and Zoubin Ghahramani. 2017.) |
| 134 | |
| 135 | Args: |
| 136 | classifier: The classifier for which the labels are to be queried. |
| 137 | X: The pool of samples to query from. |
| 138 | n_instances: Number of samples to be queried. |
| 139 | random_tie_break: If True, shuffles utility scores to randomize the order. This |
| 140 | can be used to break the tie when the highest utility score is not unique. |
| 141 | dropout_layer_indexes: Indexes of the dropout layers which should be activated |
| 142 | Choose indices from : list(torch_model.modules()) |
| 143 | num_cycles: Number of forward passes with activated dropout |
| 144 | sample_per_forward_pass: max. sample number for each forward pass. |
| 145 | The allocated RAM does mainly depend on this. |
| 146 | Small number --> small RAM allocation |
| 147 | logits_adaptor: Callable which can be used to adapt the output of a forward pass |
| 148 | to the required vector format for the vectorised metric functions |
| 149 | **uncertainty_measure_kwargs: Keyword arguments to be passed for the uncertainty |
| 150 | measure function. |
| 151 | |
| 152 | Returns: |
| 153 | The indices of the instances from X chosen to be labelled; |
| 154 | The mc-dropout metric of the chosen instances; |
| 155 | """ |
| 156 | predictions = get_predictions( |
| 157 | classifier, X, dropout_layer_indexes, num_cycles, sample_per_forward_pass, logits_adaptor) |
| 158 | |
| 159 | # get entropy values for predictions |
| 160 | entropy = _entropy(predictions) |
| 161 | |
| 162 | if not random_tie_break: |
| 163 | return multi_argmax(entropy, n_instances=n_instances) |
| 164 | |
| 165 | return shuffled_argmax(entropy, n_instances=n_instances) |
| 166 | |
| 167 | |
| 168 | def mc_dropout_max_variationRatios(classifier: BaseEstimator, X: modALinput, n_instances: int = 1, |
nothing calls this directly
no test coverage detected
searching dependent graphs…