MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / apply

Method apply

monai/transforms/regularization/array.py:74–84  ·  view source on GitHub ↗
(self, data: torch.Tensor)

Source from the content-addressed store, hash-verified

72 """
73
74 def apply(self, data: torch.Tensor):
75 weight, perm, _ = self._params
76 nsamples, *dims = data.shape
77 if len(weight) != nsamples:
78 raise ValueError(f"Expected batch of size: {len(weight)}, but got {nsamples}")
79
80 if len(dims) not in [3, 4]:
81 raise ValueError("Unexpected number of dimensions")
82
83 mixweight = weight[(Ellipsis,) + (None,) * len(dims)]
84 return mixweight * data + (1 - mixweight) * data[perm, ...]
85
86 def __call__(self, data: torch.Tensor, labels: torch.Tensor | None = None, randomize=True):
87 data_t = convert_to_tensor(data, track_meta=get_track_meta())

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected