MCPcopy Create free account
hub / github.com/NVlabs/blade / tensor2ndarray

Function tensor2ndarray

sapiens/engine/mmengine/visualization/utils.py:41–52  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

39
40
41def 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
55def value2list(value: Any, valid_type: Union[Type, Tuple[Type, ...]],

Callers 7

draw_pointsMethod · 0.90
draw_textsMethod · 0.90
draw_linesMethod · 0.90
draw_circlesMethod · 0.90
draw_bboxesMethod · 0.90
draw_polygonsMethod · 0.90
draw_binary_masksMethod · 0.90

Calls 3

numpyMethod · 0.45
cpuMethod · 0.45
detachMethod · 0.45

Tested by

no test coverage detected