Sliding window method for model inference, with `sw_batch_size` windows for every model.forward(). Usage example can be found in the :py:class:`monai.inferers.Inferer` base class. Args: roi_size: the window size to execute SlidingWindow evaluation. If it has non
| 444 | |
| 445 | |
| 446 | class SlidingWindowInferer(Inferer): |
| 447 | """ |
| 448 | Sliding window method for model inference, |
| 449 | with `sw_batch_size` windows for every model.forward(). |
| 450 | Usage example can be found in the :py:class:`monai.inferers.Inferer` base class. |
| 451 | |
| 452 | Args: |
| 453 | roi_size: the window size to execute SlidingWindow evaluation. |
| 454 | If it has non-positive components, the corresponding `inputs` size will be used. |
| 455 | if the components of the `roi_size` are non-positive values, the transform will use the |
| 456 | corresponding components of img size. For example, `roi_size=(32, -1)` will be adapted |
| 457 | to `(32, 64)` if the second spatial dimension size of img is `64`. |
| 458 | sw_batch_size: the batch size to run window slices. |
| 459 | overlap: Amount of overlap between scans along each spatial dimension, defaults to ``0.25``. |
| 460 | mode: {``"constant"``, ``"gaussian"``} |
| 461 | How to blend output of overlapping windows. Defaults to ``"constant"``. |
| 462 | |
| 463 | - ``"constant``": gives equal weight to all predictions. |
| 464 | - ``"gaussian``": gives less weight to predictions on edges of windows. |
| 465 | |
| 466 | sigma_scale: the standard deviation coefficient of the Gaussian window when `mode` is ``"gaussian"``. |
| 467 | Default: 0.125. Actual window sigma is ``sigma_scale`` * ``dim_size``. |
| 468 | When sigma_scale is a sequence of floats, the values denote sigma_scale at the corresponding |
| 469 | spatial dimensions. |
| 470 | padding_mode: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``} |
| 471 | Padding mode when ``roi_size`` is larger than inputs. Defaults to ``"constant"`` |
| 472 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html |
| 473 | cval: fill value for 'constant' padding mode. Default: 0 |
| 474 | sw_device: device for the window data. |
| 475 | By default the device (and accordingly the memory) of the `inputs` is used. |
| 476 | Normally `sw_device` should be consistent with the device where `predictor` is defined. |
| 477 | device: device for the stitched output prediction. |
| 478 | By default the device (and accordingly the memory) of the `inputs` is used. If for example |
| 479 | set to device=torch.device('cpu') the gpu memory consumption is less and independent of the |
| 480 | `inputs` and `roi_size`. Output is on the `device`. |
| 481 | progress: whether to print a tqdm progress bar. |
| 482 | cache_roi_weight_map: whether to precompute the ROI weight map. |
| 483 | cpu_thresh: when provided, dynamically switch to stitching on cpu (to save gpu memory) |
| 484 | when input image volume is larger than this threshold (in pixels/voxels). |
| 485 | Otherwise use ``"device"``. Thus, the output may end-up on either cpu or gpu. |
| 486 | buffer_steps: the number of sliding window iterations along the ``buffer_dim`` |
| 487 | to be buffered on ``sw_device`` before writing to ``device``. |
| 488 | (Typically, ``sw_device`` is ``cuda`` and ``device`` is ``cpu``.) |
| 489 | default is None, no buffering. For the buffer dim, when spatial size is divisible by buffer_steps*roi_size, |
| 490 | (i.e. no overlapping among the buffers) non_blocking copy may be automatically enabled for efficiency. |
| 491 | buffer_dim: the spatial dimension along which the buffers are created. |
| 492 | 0 indicates the first spatial dimension. Default is -1, the last spatial dimension. |
| 493 | with_coord: whether to pass the window coordinates to ``network``. Defaults to False. |
| 494 | If True, the ``network``'s 2nd input argument should accept the window coordinates. |
| 495 | |
| 496 | Note: |
| 497 | ``sw_batch_size`` denotes the max number of windows per network inference iteration, |
| 498 | not the batch size of inputs. |
| 499 | |
| 500 | """ |
| 501 | |
| 502 | def __init__( |
| 503 | self, |
no outgoing calls
searching dependent graphs…