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

Function tensor2map

utils/common.py:8–24  ·  view source on GitHub ↗
(var)

Source from the content-addressed store, hash-verified

6
7
8def tensor2map(var):
9 # if len(var.shape) == 4:
10 # var = var[0]
11 if torch.is_tensor(var) and torch.max(var) < 1:
12 mask = np.argmax(var.data.cpu().numpy(), axis=0)
13 elif torch.is_tensor(var):
14 mask = var.data.cpu().long().numpy()
15 else:
16 if len(var.shape) == 3:
17 var = var[0]
18 mask = var
19 colors = get_colors()
20 mask_image = np.ones(shape=(mask.shape[0], mask.shape[1], 3))
21 for class_idx in np.unique(mask):
22 mask_image[mask == class_idx] = colors[class_idx]
23 mask_image = mask_image.astype('uint8')
24 return Image.fromarray(mask_image)
25
26
27def tensor2sketch(var):

Callers

nothing calls this directly

Calls 1

get_colorsFunction · 0.85

Tested by

no test coverage detected