MCPcopy Create free account
hub / github.com/pytorch/tutorials / ToTensor

Class ToTensor

beginner_source/data_loading_tutorial.py:277–288  ·  view source on GitHub ↗

Convert ndarrays in sample to Tensors.

Source from the content-addressed store, hash-verified

275
276
277class ToTensor(object):
278 """Convert ndarrays in sample to Tensors."""
279
280 def __call__(self, sample):
281 image, landmarks = sample['image'], sample['landmarks']
282
283 # swap color axis because
284 # numpy image: H x W x C
285 # torch image: C x H x W
286 image = image.transpose((2, 0, 1))
287 return {'image': torch.from_numpy(image),
288 'landmarks': torch.from_numpy(landmarks)}
289
290######################################################################
291# .. note::

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected