MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / resolves_modes

Function resolves_modes

monai/transforms/utils.py:2320–2367  ·  view source on GitHub ↗

Automatically adjust the resampling interpolation mode and padding mode, so that they are compatible with the corresponding API of the `backend`. Depending on the availability of the backends, when there's no exact equivalent, a similar mode is returned. Args: interp_mo

(
    interp_mode: str | None = "constant", padding_mode="zeros", backend=TransformBackends.TORCH, **kwargs
)

Source from the content-addressed store, hash-verified

2318
2319@lru_cache(None)
2320def resolves_modes(
2321 interp_mode: str | None = "constant", padding_mode="zeros", backend=TransformBackends.TORCH, **kwargs
2322):
2323 """
2324 Automatically adjust the resampling interpolation mode and padding mode,
2325 so that they are compatible with the corresponding API of the `backend`.
2326 Depending on the availability of the backends, when there's no exact
2327 equivalent, a similar mode is returned.
2328
2329 Args:
2330 interp_mode: interpolation mode.
2331 padding_mode: padding mode.
2332 backend: optional backend of `TransformBackends`. If None, the backend will be decided from `interp_mode`.
2333 kwargs: additional keyword arguments. currently support ``torch_interpolate_spatial_nd``, to provide
2334 additional information to determine ``linear``, ``bilinear`` and ``trilinear``;
2335 ``use_compiled`` to use MONAI's precompiled backend (pytorch c++ extensions), default to ``False``.
2336 """
2337 _interp_mode, _padding_mode, _kwargs = None, None, (kwargs or {}).copy()
2338 if backend is None: # infer backend
2339 backend = (
2340 TransformBackends.NUMPY
2341 if look_up_option(str(interp_mode), SplineMode, default=None) is not None
2342 else TransformBackends.TORCH
2343 )
2344 if backend == TransformBackends.NUMPY:
2345 _interp_mode = _to_numpy_resample_interp_mode(interp_mode)
2346 _padding_mode = _to_numpy_resample_padding_mode(padding_mode)
2347 return backend, _interp_mode, _padding_mode, _kwargs
2348 _interp_mode = _to_torch_resample_interp_mode(interp_mode)
2349 _padding_mode = _to_torch_resample_padding_mode(padding_mode)
2350 if str(_interp_mode).endswith("linear"):
2351 nd = _kwargs.pop("torch_interpolate_spatial_nd", 2)
2352 if nd == 1:
2353 _interp_mode = InterpolateMode.LINEAR
2354 elif nd == 3:
2355 _interp_mode = InterpolateMode.TRILINEAR
2356 else:
2357 _interp_mode = InterpolateMode.BILINEAR # torch grid_sample bilinear is trilinear in 3D
2358 if not _kwargs.pop("use_compiled", False):
2359 return backend, _interp_mode, _padding_mode, _kwargs
2360 _padding_mode = 1 if _padding_mode == "reflection" else _padding_mode
2361 if _interp_mode == "bicubic":
2362 _interp_mode = 3
2363 elif str(_interp_mode).endswith("linear"):
2364 _interp_mode = 1
2365 else:
2366 _interp_mode = GridSampleMode(_interp_mode)
2367 return backend, _interp_mode, _padding_mode, _kwargs
2368
2369
2370def check_applied_operations(entry: list | dict, status_key: str, default_message: str = "No message provided"):

Callers 6

spatial_resampleFunction · 0.90
resizeFunction · 0.90
rotateFunction · 0.90
zoomFunction · 0.90
inverse_transformMethod · 0.90
__call__Method · 0.90

Calls 7

look_up_optionFunction · 0.90
GridSampleModeClass · 0.90
popMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…