Dictionary-based wrapper of :py:class:`monai.transforms.ToDevice`.
| 1633 | |
| 1634 | |
| 1635 | class ToDeviced(MapTransform): |
| 1636 | """ |
| 1637 | Dictionary-based wrapper of :py:class:`monai.transforms.ToDevice`. |
| 1638 | """ |
| 1639 | |
| 1640 | backend = ToDevice.backend |
| 1641 | |
| 1642 | def __init__( |
| 1643 | self, keys: KeysCollection, device: torch.device | str, allow_missing_keys: bool = False, **kwargs |
| 1644 | ) -> None: |
| 1645 | """ |
| 1646 | Args: |
| 1647 | keys: keys of the corresponding items to be transformed. |
| 1648 | See also: :py:class:`monai.transforms.compose.MapTransform` |
| 1649 | device: target device to move the Tensor, for example: "cuda:1". |
| 1650 | allow_missing_keys: don't raise exception if key is missing. |
| 1651 | kwargs: other args for the PyTorch `Tensor.to()` API, for more details: |
| 1652 | https://pytorch.org/docs/stable/generated/torch.Tensor.to.html. |
| 1653 | """ |
| 1654 | super().__init__(keys, allow_missing_keys) |
| 1655 | self.converter = ToDevice(device=device, **kwargs) |
| 1656 | |
| 1657 | def __call__(self, data: Mapping[Hashable, torch.Tensor]) -> dict[Hashable, torch.Tensor]: |
| 1658 | d = dict(data) |
| 1659 | for key in self.key_iterator(d): |
| 1660 | d[key] = self.converter(d[key]) |
| 1661 | return d |
| 1662 | |
| 1663 | |
| 1664 | class CuCIMd(MapTransform): |
no outgoing calls
searching dependent graphs…