MCPcopy Create free account
hub / github.com/MotrixLab/ADHMR / im_to_torch

Function im_to_torch

ADHMR/lib/utils/transforms.py:75–93  ·  view source on GitHub ↗

Transform ndarray image to torch tensor. Parameters ---------- img: numpy.ndarray An ndarray with shape: `(H, W, 3)`. Returns ------- torch.Tensor A tensor with shape: `(3, H, W)`.

(img)

Source from the content-addressed store, hash-verified

73
74
75def im_to_torch(img):
76 """Transform ndarray image to torch tensor.
77
78 Parameters
79 ----------
80 img: numpy.ndarray
81 An ndarray with shape: `(H, W, 3)`.
82
83 Returns
84 -------
85 torch.Tensor
86 A tensor with shape: `(3, H, W)`.
87
88 """
89 img = np.transpose(img, (2, 0, 1)) # C*H*W
90 img = to_torch(img).float()
91 if img.max() > 1:
92 img /= 255
93 return img
94
95
96def torch_to_im(img):

Callers 15

__getitem__Method · 0.90
load_imageFunction · 0.85
cv_cropBoxFunction · 0.85
cv_cropBox_rotFunction · 0.85
cv_cropBoxInverseFunction · 0.85
cv_rotateFunction · 0.85
test_transformMethod · 0.85
__call__Method · 0.85
test_transformMethod · 0.85
__call__Method · 0.85
test_transformMethod · 0.85
__call__Method · 0.85

Calls 1

to_torchFunction · 0.85

Tested by 7

test_transformMethod · 0.68
test_transformMethod · 0.68
test_transformMethod · 0.68
test_transformMethod · 0.68
test_transformMethod · 0.68
test_transformMethod · 0.68
test_transformMethod · 0.68