def visualize_weights(net, layer, zoom = 2):
"""
Visualize weights in a fully conencted layer.
:param net: caffe network
:type net: caffe.Net
:param layer: layer name
:type layer: string
:param zoom: the number of pixels (in width and height) per weight
:type zoom: int
:return: image visualizing the kernels in a grid
:rtype: numpy.ndarray
"""
assert layer in get_layers(net), "layer %s not found" % layer
weights = net.params[layer][0].data
weights = (weights - numpy.min(weights))/(numpy.max(weights) - numpy.min(weights))
return cv2.resize(weights, (weights.shape[0]*zoom, weights.shape[1]*zoom), weights, 0, 0, cv2.INTER_NEAREST)
评论列表
文章目录