MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / colorize

Function colorize

utils/render.py:228–235  ·  view source on GitHub ↗
(tensor, cmap_fn=cm.turbo)

Source from the content-addressed store, hash-verified

226
227@torch.no_grad()
228def colorize(tensor, cmap_fn=cm.turbo):
229 colors = cmap_fn(np.linspace(0, 1, 256))[:, :3]
230 colors = torch.from_numpy(colors).to(tensor)
231 tensor = tensor.squeeze(1) if tensor.ndim == 4 else tensor
232 ids = (tensor * 256).clamp(0, 255).long()
233 tensor = F.embedding(ids, colors).permute(0, 3, 1, 2)
234 tensor = tensor.mul(255).clamp(0, 255).byte()
235 return tensor

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected