CoolFace
Modelpublic

htsn/lung_nodule_ct_detection

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
utils.py27 linesDownload Raw Back to scripts
1from typing import Dict, List, Union2 3import numpy as np4import torch5 6 7def detach_to_numpy(data: Union[List, Dict, torch.Tensor]) -> Union[List, Dict, torch.Tensor]:8    """9    Recursively detach elements in data10    """11    if isinstance(data, torch.Tensor):12        return data.cpu().detach().numpy()  # pytype: disable=attribute-error13 14    elif isinstance(data, np.ndarray):15        return data16 17    elif isinstance(data, list):18        return [detach_to_numpy(d) for d in data]19 20    elif isinstance(data, dict):21        for k in data.keys():22            data[k] = detach_to_numpy(data[k])23        return data24 25    else:26        raise ValueError("data should be tensor, numpy array, dict, or list.")27