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

Method numpy

mmengine/structures/base_data_element.py:557–565  ·  view source on GitHub ↗

Convert all tensors to np.ndarray in data.

(self)

Source from the content-addressed store, hash-verified

555
556 # Tensor-like methods
557 def numpy(self) -> 'BaseDataElement':
558 """Convert all tensors to np.ndarray in data."""
559 new_data = self.new()
560 for k, v in self.items():
561 if isinstance(v, (torch.Tensor, BaseDataElement)):
562 v = v.detach().cpu().numpy()
563 data = {k: v}
564 new_data.set_data(data)
565 return new_data
566
567 def to_tensor(self) -> 'BaseDataElement':
568 """Convert all np.ndarray to tensor in data."""

Callers 8

test_numpy_tensorMethod · 0.95
tensor2imgsFunction · 0.80
add_scalarMethod · 0.80
tensor2ndarrayFunction · 0.80
convert_overlay_heatmapFunction · 0.80
__getitem__Method · 0.80
test_apply_toFunction · 0.80
test_draw_bboxesMethod · 0.80

Calls 5

newMethod · 0.95
itemsMethod · 0.95
detachMethod · 0.80
set_dataMethod · 0.80
cpuMethod · 0.45

Tested by 3

test_numpy_tensorMethod · 0.76
test_apply_toFunction · 0.64
test_draw_bboxesMethod · 0.64