MCPcopy Create free account
hub / github.com/WeChatCV/WeVisionOne / NestedTensor

Class NestedTensor

WeVisionOne/utils/misc.py:26–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class NestedTensor(object):
27 def __init__(self, tensors, mask: Optional[Tensor]):
28 self.tensors = tensors
29 self.mask = mask
30
31 def to(self, device):
32 # type: (Device) -> NestedTensor # noqa
33 cast_tensor = self.tensors.to(device)
34 mask = self.mask
35 if mask is not None:
36 assert mask is not None
37 cast_mask = mask.to(device)
38 else:
39 cast_mask = None
40 return NestedTensor(cast_tensor, cast_mask)
41
42 def decompose(self):
43 return self.tensors, self.mask
44
45 def __repr__(self):
46 return str(self.tensors)
47
48
49def nested_tensor_from_tensor_list(tensor_list: List[Tensor]):

Callers 3

toMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected