Calculates the bald divergence for each instance As it is explicitly formulated in: Deep Bayesian Active Learning with Image Data. (Yarin Gal, Riashat Islam, and Zoubin Ghahramani. 2017.) Args: proba: list with the predictions over th
(proba: list)
| 364 | |
| 365 | |
| 366 | def _bald_divergence(proba: list) -> np.ndarray: |
| 367 | """ |
| 368 | Calculates the bald divergence for each instance |
| 369 | |
| 370 | As it is explicitly formulated in: |
| 371 | Deep Bayesian Active Learning with Image Data. |
| 372 | (Yarin Gal, Riashat Islam, and Zoubin Ghahramani. 2017.) |
| 373 | |
| 374 | Args: |
| 375 | proba: list with the predictions over the dropout cycles |
| 376 | mask: mask to detect the padded classes (must be of same shape as elements in proba) |
| 377 | Return: |
| 378 | Returns the mean standard deviation of the dropout cycles over all classes. |
| 379 | """ |
| 380 | proba_stacked = np.stack(proba, axis=len(proba[0].shape)) |
| 381 | |
| 382 | # entropy along dropout cycles |
| 383 | accumulated_entropy = entropy_sum(proba_stacked, axis=-1) |
| 384 | f_x = accumulated_entropy/len(proba) |
| 385 | |
| 386 | # score sums along dropout cycles |
| 387 | accumulated_score = np.sum(proba_stacked, axis=-1) |
| 388 | average_score = accumulated_score/len(proba) |
| 389 | # expand dimension w/o data for entropy calculation |
| 390 | average_score = np.expand_dims(average_score, axis=-1) |
| 391 | |
| 392 | # entropy over average prediction score |
| 393 | g_x = entropy_sum(average_score, axis=-1) |
| 394 | |
| 395 | # entropy differences |
| 396 | diff = np.subtract(g_x, f_x) |
| 397 | |
| 398 | # sum all dimensions of diff besides first dim (instances) |
| 399 | shaped = np.reshape(diff, (diff.shape[0], -1)) |
| 400 | |
| 401 | bald = np.sum(shaped, where=~np.isnan(shaped), axis=-1) |
| 402 | return bald |
| 403 | |
| 404 | |
| 405 | def set_dropout_mode(model, dropout_layer_indexes: list, train_mode: bool): |
no test coverage detected
searching dependent graphs…