``RandomOrder`` provides the ability to apply a list of transformations in random order. Args: transforms: sequence of callables. map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. defaults to `True`. unp
| 565 | |
| 566 | |
| 567 | class RandomOrder(Compose): |
| 568 | """ |
| 569 | ``RandomOrder`` provides the ability to apply a list of transformations in random order. |
| 570 | |
| 571 | Args: |
| 572 | transforms: sequence of callables. |
| 573 | map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. |
| 574 | defaults to `True`. |
| 575 | unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. |
| 576 | defaults to `False`. |
| 577 | log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. |
| 578 | Setting this to False disables logging. Setting it to True enables logging to the default loggers. |
| 579 | Setting a string overrides the logger name to which logging is performed. |
| 580 | lazy: whether to enable :ref:`Lazy Resampling<lazy_resampling>` for lazy transforms. If False, transforms will |
| 581 | be carried out on a transform by transform basis. If True, all lazy transforms will be executed by |
| 582 | accumulating changes and resampling as few times as possible. If lazy is None, `Compose` will |
| 583 | perform lazy execution on lazy transforms that have their `lazy` property set to True. |
| 584 | overrides: this optional parameter allows you to specify a dictionary of parameters that should be overridden |
| 585 | when executing a pipeline. These each parameter that is compatible with a given transform is then applied |
| 586 | to that transform before it is executed. Note that overrides are currently only applied when |
| 587 | :ref:`Lazy Resampling<lazy_resampling>` is enabled for the pipeline or a given transform. If lazy is False |
| 588 | they are ignored. Currently supported args are: |
| 589 | {``"mode"``, ``"padding_mode"``, ``"dtype"``, ``"align_corners"``, ``"resample_mode"``, ``device``}. |
| 590 | """ |
| 591 | |
| 592 | def __init__( |
| 593 | self, |
| 594 | transforms: Sequence[Callable] | Callable | None = None, |
| 595 | map_items: bool = True, |
| 596 | unpack_items: bool = False, |
| 597 | log_stats: bool | str = False, |
| 598 | lazy: bool | None = False, |
| 599 | overrides: dict | None = None, |
| 600 | ) -> None: |
| 601 | super().__init__(transforms, map_items, unpack_items, log_stats, lazy, overrides) |
| 602 | self.log_stats = log_stats |
| 603 | |
| 604 | def __call__(self, input_, start=0, end=None, threading=False, lazy: bool | None = None): |
| 605 | if start != 0: |
| 606 | raise ValueError(f"RandomOrder requires 'start' parameter to be 0 (start set to {start})") |
| 607 | if end is not None: |
| 608 | raise ValueError(f"RandomOrder requires 'end' parameter to be None (end set to {end}") |
| 609 | |
| 610 | if len(self.transforms) == 0: |
| 611 | return input_ |
| 612 | |
| 613 | num = len(self.transforms) |
| 614 | applied_order = self.R.permutation(range(num)) |
| 615 | _lazy = self._lazy if lazy is None else lazy |
| 616 | |
| 617 | input_ = execute_compose( |
| 618 | input_, |
| 619 | [self.transforms[ind] for ind in applied_order], |
| 620 | start=start, |
| 621 | end=end, |
| 622 | map_items=self.map_items, |
| 623 | unpack_items=self.unpack_items, |
| 624 | lazy=_lazy, |
no outgoing calls
searching dependent graphs…