utils/framework.py
def data_to_device(self, data: Any, device: Any) -> Any:
        """This function moves data to CPU/GPU recursively (i.e. Tensor, tuple, list, dict).
        Anything else such as int, float, np.array, etc, will be ignored.
        """
        if isinstance(data, torch.Tensor):
            data = data.to(device)
        elif isinstance(data, tuple):
            data = tuple(self.data_to_device(item, device) for item in data)
        elif isinstance(data, list):
            data = list(self.data_to_device(item, device) for item in data)
        elif isinstance(data, dict):
            data = dict((key, self.data_to_device(data[key], device)) for key in data)
        else:
            pass  # keep as is for other data types
        return data
This function moves data to CPU/GPU recursively (i.e. Tensor, tuple, list, dict).
        Anything else such as int, float, np.array, etc, will be ignored.
        
This function moves data to CPU/GPU recursively .
Anything else such as int, float, np.array, etc, will be ignored.
This function moves data to CPU / GPU recursively . Anything else such as int float np . array etc will be ignored .
def data_to_device(self, data: Any, device: Any) -> Any:
        if isinstance(data, torch.Tensor):
            data = data.to(device)
        elif isinstance(data, tuple):
            data = tuple(self.data_to_device(item, device) for item in data)
        elif isinstance(data, list):
            data = list(self.data_to_device(item, device) for item in data)
        elif isinstance(data, dict):
            data = dict((key, self.data_to_device(data[key], device)) for key in data)
        else:
            pass  
        return data
def data_to_device ( self , data : Any , device : Any ) -> Any : if isinstance ( data , torch . Tensor ) : data = data . to ( device ) elif isinstance ( data , tuple ) : data = tuple ( self . data_to_device ( item , device ) for item in data ) elif isinstance ( data , list ) : data = list ( self . data_to_device ( item , device ) for item in data ) elif isinstance ( data , dict ) : data = dict ( ( key , self . data_to_device ( data [ key ] , device ) ) for key in data ) else : pass return data
This function moves data to CPU/GPU recursively (i.e.
This function moves data to CPU / GPU recursively ( i . e .
"""This function moves data to CPU/GPU recursively (i.e. Tensor, tuple, list, dict).
        Anything else such as int, float, np.array, etc, will be ignored.
        """ # keep as is for other data types
self
data
Any
device
Any