MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / _pad_patch_list

Function _pad_patch_list

tensorpack/utils/viz.py:78–104  ·  view source on GitHub ↗
(plist, bgcolor)

Source from the content-addressed store, hash-verified

76
77
78def _pad_patch_list(plist, bgcolor):
79 if isinstance(bgcolor, int):
80 bgcolor = (bgcolor, bgcolor, bgcolor)
81
82 def _pad_channel(plist):
83 ret = []
84 for p in plist:
85 if len(p.shape) == 2:
86 p = p[:, :, np.newaxis]
87 if p.shape[2] == 1:
88 p = np.repeat(p, 3, 2)
89 ret.append(p)
90 return ret
91
92 plist = _pad_channel(plist)
93 shapes = [x.shape for x in plist]
94 ph = max(s[0] for s in shapes)
95 pw = max(s[1] for s in shapes)
96
97 ret = np.zeros((len(plist), ph, pw, 3), dtype=plist[0].dtype)
98 ret[:, :, :] = bgcolor
99 for idx, p in enumerate(plist):
100 s = p.shape
101 sh = (ph - s[0]) // 2
102 sw = (pw - s[1]) // 2
103 ret[idx, sh:sh + s[0], sw:sw + s[1], :] = p
104 return ret
105
106
107class Canvas(object):

Callers 1

stack_patchesFunction · 0.85

Calls 1

_pad_channelFunction · 0.85

Tested by

no test coverage detected