How to use the torchcam.helper.show_image function in torchcam

To help you get started, we’ve selected a few torchcam examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tramac / pytorch-cam / torchcam / saliency / saliency.py View on Github external
def get_image_saliency_plot(image_saliency_results, cols: int = 2, figsize: tuple = None, display=True, save_path=False):
    rows = math.ceil(len(image_saliency_results) / cols)
    figsize = figsize or (8, 3 * rows)
    figure = plt.figure(figsize=figsize)

    for i, r in enumerate(image_saliency_results):
        ax = figure.add_subplot(rows, cols, i + 1)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_title(r.title, fontdict={'fontsize': 18})

        saliency_upsampled = skimage.transform.resize(r.saliency,
                                                      (r.raw_image.height, r.raw_image.width),
                                                      mode='reflect')

        show_image(r.raw_image, img2=saliency_upsampled, alpha2=r.saliency_alpha, cmap2=r.saliency_cmap, ax=ax)

    if display:
        figure.show()
        figure.waitforbuttonpress()
    if save_path:
        figure.savefig(save_path)

    return figure

torchcam

Class activation maps for your PyTorch CNN models

Apache-2.0
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis

Similar packages