``SomeOf`` samples a different sequence of transforms to apply each time it is called. It can be configured to sample a fixed or varying number of transforms each time its called. Samples are drawn uniformly, or from user supplied transform weights. When varying the number of transform
| 662 | |
| 663 | |
| 664 | class SomeOf(Compose): |
| 665 | """ |
| 666 | ``SomeOf`` samples a different sequence of transforms to apply each time it is called. |
| 667 | |
| 668 | It can be configured to sample a fixed or varying number of transforms each time its called. Samples are drawn |
| 669 | uniformly, or from user supplied transform weights. When varying the number of transforms sampled per call, |
| 670 | the number of transforms to sample that call is sampled uniformly from a range supplied by the user. |
| 671 | |
| 672 | Args: |
| 673 | transforms: list of callables. |
| 674 | map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. |
| 675 | Defaults to `True`. |
| 676 | unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. |
| 677 | Defaults to `False`. |
| 678 | log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. |
| 679 | Setting this to False disables logging. Setting it to True enables logging to the default loggers. |
| 680 | Setting a string overrides the logger name to which logging is performed. |
| 681 | num_transforms: a 2-tuple, int, or None. The 2-tuple specifies the minimum and maximum (inclusive) number of |
| 682 | transforms to sample at each iteration. If an int is given, the lower and upper bounds are set equal. |
| 683 | None sets it to `len(transforms)`. Default to `None`. |
| 684 | replace: whether to sample with replacement. Defaults to `False`. |
| 685 | weights: weights to use in for sampling transforms. Will be normalized to 1. Default: None (uniform). |
| 686 | lazy: whether to enable :ref:`Lazy Resampling<lazy_resampling>` for lazy transforms. If False, transforms will |
| 687 | be carried out on a transform by transform basis. If True, all lazy transforms will be executed by |
| 688 | accumulating changes and resampling as few times as possible. If lazy is None, `Compose` will |
| 689 | perform lazy execution on lazy transforms that have their `lazy` property set to True. |
| 690 | overrides: this optional parameter allows you to specify a dictionary of parameters that should be overridden |
| 691 | when executing a pipeline. These each parameter that is compatible with a given transform is then applied |
| 692 | to that transform before it is executed. Note that overrides are currently only applied when |
| 693 | :ref:`Lazy Resampling<lazy_resampling>` is enabled for the pipeline or a given transform. If lazy is False |
| 694 | they are ignored. Currently supported args are: |
| 695 | {``"mode"``, ``"padding_mode"``, ``"dtype"``, ``"align_corners"``, ``"resample_mode"``, ``device``}. |
| 696 | """ |
| 697 | |
| 698 | def __init__( |
| 699 | self, |
| 700 | transforms: Sequence[Callable] | Callable | None = None, |
| 701 | map_items: bool = True, |
| 702 | unpack_items: bool = False, |
| 703 | log_stats: bool | str = False, |
| 704 | num_transforms: int | tuple[int, int] | None = None, |
| 705 | replace: bool = False, |
| 706 | weights: list[int] | None = None, |
| 707 | lazy: bool | None = False, |
| 708 | overrides: dict | None = None, |
| 709 | ) -> None: |
| 710 | super().__init__(transforms, map_items, unpack_items, log_stats=log_stats, lazy=lazy, overrides=overrides) |
| 711 | self.min_num_transforms, self.max_num_transforms = self._ensure_valid_num_transforms(num_transforms) |
| 712 | self.replace = replace |
| 713 | self.weights = self._normalize_probabilities(weights) |
| 714 | self.log_stats = log_stats |
| 715 | |
| 716 | def _ensure_valid_num_transforms(self, num_transforms: int | tuple[int, int] | None) -> tuple: |
| 717 | if ( |
| 718 | not isinstance(num_transforms, tuple) |
| 719 | and not isinstance(num_transforms, list) |
| 720 | and not isinstance(num_transforms, int) |
| 721 | and num_transforms is not None |
no outgoing calls
searching dependent graphs…