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
)
| 2318 | |
| 2319 | @lru_cache(None) |
| 2320 | def 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 | |
| 2370 | def check_applied_operations(entry: list | dict, status_key: str, default_message: str = "No message provided"): |
no test coverage detected
searching dependent graphs…