MCPcopy Create free account
hub / github.com/MaureenZOU/TSAM / ToTorchFormatTensor

Class ToTorchFormatTensor

src/data_loader/transform_flow.py:349–362  ·  view source on GitHub ↗

Converts a PIL.Image (RGB) or numpy.ndarray (H x W x C) in the range [0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0]

Source from the content-addressed store, hash-verified

347
348
349class ToTorchFormatTensor(object):
350 """ Converts a PIL.Image (RGB) or numpy.ndarray (H x W x C) in the range [0, 255]
351 to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0] """
352 def __init__(self, div=True):
353 self.div = div
354
355 def __call__(self, img_dict):
356 # handle numpy array
357 img_dict['gt_frames'] = torch.from_numpy(img_dict['gt_frames']).permute(2, 3, 0, 1).contiguous().float().div(255)
358 img_dict['flow_forward'] = torch.from_numpy(img_dict['flow_forward']).permute(2, 3, 0, 1).contiguous().float()
359 img_dict['flow_backward'] = torch.from_numpy(img_dict['flow_backward']).permute(2, 3, 0, 1).contiguous().float()
360 img_dict['flowmask_forward'] = torch.from_numpy(img_dict['flowmask_forward']).permute(2, 3, 0, 1).contiguous().float().div(255)
361 img_dict['flowmask_backward'] = torch.from_numpy(img_dict['flowmask_backward']).permute(2, 3, 0, 1).contiguous().float().div(255)
362 return img_dict
363
364class IdentityTransform(object):
365 def __call__(self, data):

Callers 4

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
transform_flow.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected