| 2 | import numpy |
| 3 | |
| 4 | def plot_tensor_images(data, **kwargs): |
| 5 | data = ((data + 1) / 2 * 255).permute(0, 2, 3, 1).byte().cpu().numpy() |
| 6 | width = int(numpy.ceil(numpy.sqrt(data.shape[0]))) |
| 7 | height = int(numpy.ceil(data.shape[0] / float(width))) |
| 8 | kwargs = dict(kwargs) |
| 9 | margin = 0.01 |
| 10 | if 'figsize' not in kwargs: |
| 11 | # Size figure to one display pixel per data pixel |
| 12 | dpi = plt.rcParams['figure.dpi'] |
| 13 | kwargs['figsize'] = ( |
| 14 | (1 + margin) * (width * data.shape[2] / dpi), |
| 15 | (1 + margin) * (height * data.shape[1] / dpi)) |
| 16 | f, axarr = plt.subplots(height, width, **kwargs) |
| 17 | if len(numpy.shape(axarr)) == 0: |
| 18 | axarr = numpy.array([[axarr]]) |
| 19 | if len(numpy.shape(axarr)) == 1: |
| 20 | axarr = axarr[None,:] |
| 21 | for i, im in enumerate(data): |
| 22 | ax = axarr[i // width, i % width] |
| 23 | ax.imshow(data[i]) |
| 24 | ax.axis('off') |
| 25 | for i in range(i, width * height): |
| 26 | ax = axarr[i // width, i % width] |
| 27 | ax.axis('off') |
| 28 | plt.subplots_adjust(wspace=margin, hspace=margin, |
| 29 | left=0, right=1, bottom=0, top=1) |
| 30 | plt.show() |
| 31 | |
| 32 | def plot_max_heatmap(data, shape=None, **kwargs): |
| 33 | if shape is None: |