def draw_conv_weights(self): for i, (name, weight) in enumerate(zip(self.layer_names, self._weights)): if len(weight.shape) != 4: return for j, _w in enumerate(weight): for k, _ww in enumerate(_w): VisUtil.show_img(_ww, "{} {} filter {} channel {}".format(name, i+1, j+1, k+1))
def draw_conv_weights(self): for i, (name, weight) in enumerate(zip(self.layer_names, self._weights)): if len(weight.shape) != 4: return for j, _w in enumerate(weight): for k, _ww in enumerate(_w): VisUtil.show_img(_ww, "{} {} filter {} channel {}".format(name, i+1, j+1, k+1))
def draw_conv_series(self, x, shape=None): x = np.array(x) for xx in x: VisUtil.show_img(VisUtil.trans_img(xx, shape), "Original") for i, (layer, ac) in enumerate( zip( self._layers, self._get_acts( np.array([xx.transpose(1, 2, 0)], dtype=np.float32)))): if len(ac.shape) == 4: VisUtil.show_batch_img( ac[0].transpose(2, 0, 1), "Layer {} ({})".format(i + 1, layer.name)) else: ac = ac[0] length = sqrt(np.prod(ac.shape)) if length < 10: continue (height, width) = xx.shape[1:] if shape is None else shape[1:] sqrt_shape = sqrt(height * width) oh, ow = int(length * height / sqrt_shape), int( length * width / sqrt_shape) VisUtil.show_img(ac[:oh * ow].reshape(oh, ow), "Layer {} ({})".format(i + 1, layer.name))
def draw_conv_series(self, x, shape=None): x = np.asarray(x) for xx in x: VisUtil.show_img(VisUtil.trans_img(xx, shape), "Original") for i, (layer, ac) in enumerate(zip( self._layers, self._get_acts(np.array([xx.transpose(1, 2, 0)], dtype=np.float32)))): if len(ac.shape) == 4: VisUtil.show_batch_img(ac[0].transpose(2, 0, 1), "Layer {} ({})".format(i + 1, layer.name)) else: ac = ac[0] length = sqrt(np.prod(ac.shape)) if length < 10: continue (height, width) = xx.shape[1:] if shape is None else shape[1:] sqrt_shape = sqrt(height * width) oh, ow = int(length * height / sqrt_shape), int(length * width / sqrt_shape) VisUtil.show_img(ac[:oh * ow].reshape(oh, ow), "Layer {} ({})".format(i + 1, layer.name))
def draw_conv_series(self, x, shape=None): for xx in x: VisUtil.show_img(VisUtil.trans_img(xx, shape), "Original") activations = self._get_activations(np.array([xx]), predict=True) for i, (layer, ac) in enumerate(zip(self._layers, activations)): if len(ac.shape) == 4: for n in ac: _n, height, width = n.shape a = int(ceil(sqrt(_n))) g = np.ones((a * height + a, a * width + a), n.dtype) g *= np.min(n) _i = 0 for y in range(a): for x in range(a): if _i < _n: g[y * height + y:(y + 1) * height + y, x * width + x:(x + 1) * width + x] = n[ _i, :, :] _i += 1 # normalize to [0,1] max_g = g.max() min_g = g.min() g = (g - min_g) / (max_g - min_g) VisUtil.show_img(g, "Layer {} ({})".format(i + 1, layer.name)) else: ac = ac[0] length = sqrt(np.prod(ac.shape)) if length < 10: continue (height, width) = xx.shape[1:] if shape is None else shape[1:] sqrt_shape = sqrt(height * width) oh, ow = int(length * height / sqrt_shape), int(length * width / sqrt_shape) VisUtil.show_img(ac[:oh*ow].reshape(oh, ow), "Layer {} ({})".format(i + 1, layer.name))
def draw_conv_series(self, x, shape=None): for xx in x: VisUtil.show_img(VisUtil.trans_img(xx, shape), "Original") activations = self._get_activations(np.array([xx]), predict=True) for i, (layer, ac) in enumerate(zip(self._layers, activations)): if len(ac.shape) == 4: for n in ac: _n, height, width = n.shape a = int(ceil(sqrt(_n))) g = np.ones((a * height + a, a * width + a), n.dtype) g *= np.min(n) _i = 0 for y in range(a): for x in range(a): if _i < _n: g[y * height + y:(y + 1) * height + y, x * width + x:(x + 1) * width + x] = n[ _i, :, :] _i += 1 # normalize to [0,1] max_g = g.max() min_g = g.min() g = (g - min_g) / (max_g - min_g) VisUtil.show_img(g, "Layer {} ({})".format(i + 1, layer.name)) else: ac = ac[0] length = sqrt(np.prod(ac.shape)) if length < 10: continue (height, width) = xx.shape[1:] if shape is None else shape[1:] sqrt_shape = sqrt(height * width) oh, ow = int(length * height / sqrt_shape), int(length * width / sqrt_shape) VisUtil.show_img(ac[:oh*ow].reshape(oh, ow), "Layer {} ({})".format(i + 1, layer.name))