python中的神经网络感受野可视化
我有一个包含300个隐藏层的神经网络,我想将其可视化(全部) 在python中,最好的方法是什么 我已经试过使用python中的神经网络感受野可视化,python,matplotlib,neural-network,visualization,data-visualization,Python,Matplotlib,Neural Network,Visualization,Data Visualization,我有一个包含300个隐藏层的神经网络,我想将其可视化(全部) 在python中,最好的方法是什么 我已经试过使用子图了,但是感受野彼此太远,我几乎看不到它们 编辑: 所以在输出上,我只有28*28 我想要可视化的权重(图像) 这是我当前的代码: # Plot receptive fields f, axarr = pyplot.subplots(30, 10) for weight_numb in xrange(300): currnt_sub_handler = axarr[wei
子图了,但是感受野彼此太远,我几乎看不到它们
编辑:
所以在输出上,我只有28*28
我想要可视化的权重(图像)
这是我当前的代码:
# Plot receptive fields
f, axarr = pyplot.subplots(30, 10)
for weight_numb in xrange(300):
currnt_sub_handler = axarr[weight_numb / 10, weight_numb % 10]
weight = main.model_params[:, weight_numb].reshape(28, 28)
currnt_sub_handler.axis('off')
currnt_sub_handler.imshow(weight)
pyplot.show()
因此,重新表述问题:
如何使图像尽可能靠近彼此
我必须使用什么颜色的地图
为什么不制作一个大图像(矩阵),也就是说,(10x28)x(30x28),然后将每个28x28过滤器放入该矩阵的一部分,然后立即绘制整个图像。有点像这样:
# assuming your filters are stored in a list called all_filters
all_filter_image = zeros(10*28, 30*28)
for filter_num in range(300):
# calculate start_x and start_y based on the size of your "large filter"
# and the filter index
all_filter_image[start_x:start_x + 28, start_y: start_y + 28] = all_filters[filter_num]
这样您就不必处理子地块。这就是我提出的解决方案。谢谢@mprat的帮助
我发现,spectrum
colormap最适合这种任务,而且
我还添加了可以指定的边框
from matplotlib import pyplot
import numpy as np
border = 2
images_amount = 300
row_amount = 10
col_amount = 30
image_height = 28
image_width = 28
all_filter_image = np.zeros((row_amount*image_height + border*row_amount,
col_amount*image_width + border*col_amount))
for filter_num in range(images_amount):
start_row = image_height*(filter_num / col_amount) +\
(filter_num / col_amount + 1)*border
end_row = start_row + image_height
start_col = image_width*(filter_num % col_amount) +\
(filter_num % col_amount + 1)*border
end_col = start_col + image_width
all_filter_image[start_row:end_row, start_col:end_col] = \
all_filters[filter_num]
print start_row, end_row, start_col, end_col
pyplot.imshow(all_filter_image)
pyplot.axis('off')
pyplot.set_cmap('spectral')
pyplot.colorbar()
pyplot.savefig('repflds1.png')
以下是一些用法示例:
不太训练有素的网络:
非常好的培训网络:
正如您所看到的那样,边框使得区分一个过滤器(权重)和另一个过滤器(权重)变得非常容易。您能详细说明您想要哪种可视化吗?通常,最好的方法是在您用来进行训练/特征提取的任何框架内工作。@mprat我有28*28张图像,总共300张。我只是想用一种很好的方法把它们放在一张图片中,这样人们就能清楚地看到每一张图片。所以你的问题是如何将300张图片并排画出来?@mprat,基本上是的。我想把它们放得尽可能近。但我也猜有一些颜色贴图非常适合这个任务。