MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / to_tensor

Method to_tensor

dzoedepth/data/vkitti.py:52–79  ·  view source on GitHub ↗
(self, pic)

Source from the content-addressed store, hash-verified

50 return {'image': image, 'depth': depth, 'dataset': "vkitti"}
51
52 def to_tensor(self, pic):
53
54 if isinstance(pic, np.ndarray):
55 img = torch.from_numpy(pic.transpose((2, 0, 1)))
56 return img
57
58 # # handle PIL Image
59 if pic.mode == 'I':
60 img = torch.from_numpy(np.array(pic, np.int32, copy=False))
61 elif pic.mode == 'I;16':
62 img = torch.from_numpy(np.array(pic, np.int16, copy=False))
63 else:
64 img = torch.ByteTensor(
65 torch.ByteStorage.from_buffer(pic.tobytes()))
66 # PIL image mode: 1, L, P, I, F, RGB, YCbCr, RGBA, CMYK
67 if pic.mode == 'YCbCr':
68 nchannel = 3
69 elif pic.mode == 'I;16':
70 nchannel = 1
71 else:
72 nchannel = len(pic.mode)
73 img = img.view(pic.size[1], pic.size[0], nchannel)
74
75 img = img.transpose(0, 1).transpose(0, 2).contiguous()
76 if isinstance(img, torch.ByteTensor):
77 return img.float()
78 else:
79 return img
80
81
82class VKITTI(Dataset):

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected