Replies: 1 comment 1 reply
-
Could do. Are you thinking (untested): class InvertibleLambdad(Lambdad, InvertibleTransform):
def __init__(
self,
keys: KeysCollection,
func: Union[Sequence[Callable], Callable],
inv_func: Union[Sequence[Callable], Callable],
overwrite: Union[Sequence[bool], bool] = True,
allow_missing_keys: bool = False,
) -> None:
super().__init__(keys, func, overwrite, allow_missing_keys)
self.inv_func = ensure_tuple_rep(inv_func, len(self.keys))
def __call__(self, data):
d = dict(data)
for key, func, overwrite in self.key_iterator(d, self.func, self.overwrite):
ret = self._lambd(d[key], func=func)
if overwrite:
d[key] = ret
self.push_transform(d, key)
return d
def inverse(self, data):
d = deepcopy(dict(data))
for key, inv_func, overwrite in self.key_iterator(d, self.inv_func, self.overwrite):
transform = self.get_most_recent_transform(d, key)
ret = self._lambd(d[key], func=inv_func)
if overwrite:
d[key] = ret
self.pop_transform(d, key)
return d N.B.: Doesn't allow the user to define |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
not sure if this should become a feature request,
do we need an invertible LambdaD with a customisable
.inverse()
?MONAI/monai/transforms/utility/dictionary.py
Lines 703 to 707 in 583e35b
Beta Was this translation helpful? Give feedback.
All reactions