Args: keys: keys of the corresponding items to be stack and execute ensemble. if only 1 key provided, suppose it's a PyTorch Tensor with data stacked on dimension `E`. output_key: the key to store ensemble result in the dictionary. if
(
self,
keys: KeysCollection,
output_key: str | None = None,
weights: Sequence[float] | NdarrayOrTensor | None = None,
)
| 464 | backend = MeanEnsemble.backend |
| 465 | |
| 466 | def __init__( |
| 467 | self, |
| 468 | keys: KeysCollection, |
| 469 | output_key: str | None = None, |
| 470 | weights: Sequence[float] | NdarrayOrTensor | None = None, |
| 471 | ) -> None: |
| 472 | """ |
| 473 | Args: |
| 474 | keys: keys of the corresponding items to be stack and execute ensemble. |
| 475 | if only 1 key provided, suppose it's a PyTorch Tensor with data stacked on dimension `E`. |
| 476 | output_key: the key to store ensemble result in the dictionary. |
| 477 | if only 1 key provided in `keys`, `output_key` can be None and use `keys` as default. |
| 478 | weights: can be a list or tuple of numbers for input data with shape: [E, C, H, W[, D]]. |
| 479 | or a Numpy ndarray or a PyTorch Tensor data. |
| 480 | the `weights` will be added to input data from highest dimension, for example: |
| 481 | 1. if the `weights` only has 1 dimension, it will be added to the `E` dimension of input data. |
| 482 | 2. if the `weights` has 2 dimensions, it will be added to `E` and `C` dimensions. |
| 483 | it's a typical practice to add weights for different classes: |
| 484 | to ensemble 3 segmentation model outputs, every output has 4 channels(classes), |
| 485 | so the input data shape can be: [3, 4, H, W, D]. |
| 486 | and add different `weights` for different classes, so the `weights` shape can be: [3, 4]. |
| 487 | for example: `weights = [[1, 2, 3, 4], [4, 3, 2, 1], [1, 1, 1, 1]]`. |
| 488 | |
| 489 | """ |
| 490 | ensemble = MeanEnsemble(weights=weights) |
| 491 | super().__init__(keys, ensemble, output_key) |
| 492 | |
| 493 | |
| 494 | class VoteEnsembled(Ensembled): |
nothing calls this directly
no test coverage detected