MCPcopy Create free account
hub / github.com/open-mmlab/mmengine / tensor2ndarray

Function tensor2ndarray

mmengine/visualization/utils.py:13–24  ·  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

11
12
13def tensor2ndarray(value: Union[np.ndarray, torch.Tensor]) -> np.ndarray:
14 """If the type of value is torch.Tensor, convert the value to np.ndarray.
15
16 Args:
17 value (np.ndarray, torch.Tensor): value.
18
19 Returns:
20 Any: value.
21 """
22 if isinstance(value, torch.Tensor):
23 value = value.detach().cpu().numpy()
24 return value
25
26
27def 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.80
detachMethod · 0.80
cpuMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…