MCPcopy Create free account
hub / github.com/modAL-python/modAL / mc_dropout_max_variationRatios

Function mc_dropout_max_variationRatios

modAL/dropout.py:168–213  ·  view source on GitHub ↗

Mc-Dropout maximum variation ratios query strategy. Returns the indexes of the instances with the largest variation ratios over multiple dropout cycles and the corresponding metric. Based on the equations of: Deep Bayesian Active Learning with Image Da

(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)

Source from the content-addressed store, hash-verified

166
167
168def mc_dropout_max_variationRatios(classifier: BaseEstimator, X: modALinput, n_instances: int = 1,
169 random_tie_break: bool = False, dropout_layer_indexes: list = [],
170 num_cycles: int = 50, sample_per_forward_pass: int = 1000,
171 logits_adaptor: Callable[[
172 torch.tensor, modALinput], torch.tensor] = default_logits_adaptor,
173 **mc_dropout_kwargs) -> np.ndarray:
174 """
175 Mc-Dropout maximum variation ratios query strategy. Returns the indexes of the instances
176 with the largest variation ratios over multiple dropout cycles
177 and the corresponding metric.
178
179 Based on the equations of:
180 Deep Bayesian Active Learning with Image Data.
181 (Yarin Gal, Riashat Islam, and Zoubin Ghahramani. 2017.)
182
183 Args:
184 classifier: The classifier for which the labels are to be queried.
185 X: The pool of samples to query from.
186 n_instances: Number of samples to be queried.
187 random_tie_break: If True, shuffles utility scores to randomize the order. This
188 can be used to break the tie when the highest utility score is not unique.
189 dropout_layer_indexes: Indexes of the dropout layers which should be activated
190 Choose indices from : list(torch_model.modules())
191 num_cycles: Number of forward passes with activated dropout
192 sample_per_forward_pass: max. sample number for each forward pass.
193 The allocated RAM does mainly depend on this.
194 Small number --> small RAM allocation
195 logits_adaptor: Callable which can be used to adapt the output of a forward pass
196 to the required vector format for the vectorised metric functions
197 **uncertainty_measure_kwargs: Keyword arguments to be passed for the uncertainty
198 measure function.
199
200 Returns:
201 The indices of the instances from X chosen to be labelled;
202 The mc-dropout metric of the chosen instances;
203 """
204 predictions = get_predictions(
205 classifier, X, dropout_layer_indexes, num_cycles, sample_per_forward_pass, logits_adaptor)
206
207 # get variation ratios values for predictions
208 variationRatios = _variation_ratios(predictions)
209
210 if not random_tie_break:
211 return multi_argmax(variationRatios, n_instances=n_instances)
212
213 return shuffled_argmax(variationRatios, n_instances=n_instances)
214
215
216def get_predictions(classifier: BaseEstimator, X: modALinput, dropout_layer_indexes: list = [],

Callers

nothing calls this directly

Calls 4

multi_argmaxFunction · 0.90
shuffled_argmaxFunction · 0.90
get_predictionsFunction · 0.85
_variation_ratiosFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…