如何将特征映射保存到图像以便在终端中进行可视化?

时间:2016-10-09 05:08:04

标签: python terminal caffe

    import matplotlib.pyplot as plt
  7 def vis_square(data):
  8     """Take an array of shape (n, height, width) or (n, height, width, 3)
  9        and visualize each (height, width) thing in a grid of size approx. sqrt(n) by     sqrt(n)"""
 10     # normalize data for display
 11     data = (data - data.min()) / (data.max() - data.min())
 12
 13     # force the number of filters to be square
 14     n = int(np.ceil(np.sqrt(data.shape[0])))
 15     padding = (((0, n ** 2 - data.shape[0]),
 16                (0, 1), (0, 1))                 # add some space between filters
 17                + ((0, 0),) * (data.ndim - 3))  # don't pad the last dimension (if th    ere is one)
 18     data = np.pad(data, padding, mode='constant', constant_values=1)  # pad with one    s (white)
 19
 20     # tile the filters into an image
 21     data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(rang    e(4, data.ndim + 1)))
 22     data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])
 23     #plt.imshow(data);plt.axis('off') ### THIS LINE DOESNT WORK IN TERMINAL
        fig,ax = plt.imshow(data)
        fig.savefig('fig.png')

我在共享服务器上工作,因此没有提供gui。但是我想知道这个功能是什么样的?

行:23在终端无效。

如何将数据保存到图像?请告知。

我通过将数据文件保存到pickle来解决任务,然后在另一台计算机中绘制图片。但仍然对在虚拟图片中绘制图片并将图像保存在服务器上的方法感兴趣。

使用`后端'。请检查此doc

 import matplotlib
 matplotlib.use('Agg')
 import matplotlib.pyplot as plt

0 个答案:

没有答案