If the type of value is torch.Tensor, convert the value to np.ndarray. Args: value (np.ndarray, torch.Tensor): value. Returns: Any: value.
(value: Union[np.ndarray, torch.Tensor])
| 39 | |
| 40 | |
| 41 | def tensor2ndarray(value: Union[np.ndarray, torch.Tensor]) -> np.ndarray: |
| 42 | """If the type of value is torch.Tensor, convert the value to np.ndarray. |
| 43 | |
| 44 | Args: |
| 45 | value (np.ndarray, torch.Tensor): value. |
| 46 | |
| 47 | Returns: |
| 48 | Any: value. |
| 49 | """ |
| 50 | if isinstance(value, torch.Tensor): |
| 51 | value = value.detach().cpu().numpy() |
| 52 | return value |
| 53 | |
| 54 | |
| 55 | def value2list(value: Any, valid_type: Union[Type, Tuple[Type, ...]], |
no test coverage detected