what.models.detection.utils.array_utils
tools to convert specified type
1""" 2tools to convert specified type 3""" 4import torch as t 5import numpy as np 6 7 8def to_numpy(data): 9 if isinstance(data, np.ndarray): 10 return data 11 if isinstance(data, t.Tensor): 12 return data.detach().cpu().numpy() 13 14 15def to_tensor(data, device): 16 if isinstance(data, np.ndarray): 17 tensor = t.from_numpy(data) 18 if isinstance(data, t.Tensor): 19 tensor = data.detach() 20 return tensor.to(device) 21 22 23def to_scalar(data): 24 if isinstance(data, np.ndarray): 25 return data.reshape(1)[0] 26 if isinstance(data, t.Tensor): 27 return data.item()
def
to_numpy(data):
def
to_tensor(data, device):
def
to_scalar(data):