def add_all_variable_images(self, last_var, exclude_params=True, global_step=None, pattern='.*'):
cp = re.compile(pattern)
g = c.build_computational_graph(last_var)
names = NodeName(g.nodes)
for n in g.nodes:
if isinstance(n, chainer.variable.VariableNode) and \
(exclude_params and not isinstance(n._variable(), chainer.Parameter)) and \
n.data is not None and \
cp.match(names.name(n)):
data = chainer.cuda.to_cpu(n.data)
assert data.ndim < 5, "'variable.data' must be less than 5. the given 'variable.data.ndim' is %d." % data.ndim
if data.ndim == 4:
for i, d in enumerate(data):
img = make_grid(np.expand_dims(d, 1) if d.shape[0] != 3 else d)
self.add_image(names.name(n) + '/' + str(i), img, global_step)
else:
img = make_grid(np.expand_dims(data, 1) if data.shape[0] != 3 else data)
self.add_image(names.name(n), img, global_step)
评论列表
文章目录