(tensor, cmap_fn=cm.turbo)
| 226 | |
| 227 | @torch.no_grad() |
| 228 | def 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 |
nothing calls this directly
no outgoing calls
no test coverage detected