MCPcopy Create free account
hub / github.com/OpenTalker/StyleHEAT / tensor2im

Function tensor2im

utils/logging.py:50–59  ·  view source on GitHub ↗
(var, vmin=-1, vmax=1)

Source from the content-addressed store, hash-verified

48
49
50def tensor2im(var, vmin=-1, vmax=1):
51 # var shape: (3, H, W)
52 if len(var.shape) == 4:
53 var = var[0]
54 var = var.cpu().detach().transpose(0, 2).transpose(0, 1).numpy()
55 var = ((var - vmin) / (vmax - vmin))
56 var[var < 0] = 0
57 var[var > 1] = 1
58 var = var * 255
59 return Image.fromarray(var.astype('uint8'))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected