Esempio n. 1
0
def showRandomImages(data, targets, predictions=None, classes=None, count=20, muSigmaPair=None):
    randImages = Utility.pickRandomElements(data, count)
    images = data[randImages]

    if (muSigmaPair is not None):
        images = Utility.unnormalize(images, muSigmaPair[0], muSigmaPair[1])

    images = images.permute(0, 2, 3, 1)

    targets = __getLabels(targets, randImages, classes)
    if predictions is not None:
        predictions = __getLabels(predictions, randImages, classes)

    showImages(images.numpy(), targets, predictions, cols=5)
Esempio n. 2
0
    def visualize(self,
                  data,
                  data_targets,
                  classes,
                  count=5,
                  muSigPair=None,
                  figSize=(15, 15)):

        heatmaps, cam_pred = self.gradCam(data)
        randIndices = Utility.pickRandomElements(data, count)

        rand_data, rand_targets, rand_cam_pred = data[
            randIndices], data_targets[randIndices], cam_pred[randIndices]
        rand_superImposedImages = {}
        for layer in heatmaps:
            rand_superImposedImages[layer] = self.superImpose(
                rand_data, heatmaps[layer], muSigPair)

        self.plot(Utility.toImages(rand_data, muSigPair), rand_targets,
                  rand_cam_pred, rand_superImposedImages, classes, figSize)
Esempio n. 3
0
def showLoaderImages(loader, classes=None, count=20, muSigmaPair=None):
    """

    Takes random images from the loader and shows the images.
    Optionally Mean and Sigma pair can be passed to unnormalize data before showing the image.

    :param muSigmaPair: Default is (0, 1)
    """
    d, l = iter(loader).next()

    randImages = Utility.pickRandomElements(d, count)
    images = d[randImages]

    if (muSigmaPair is not None):
        images = Utility.unnormalize(images, muSigmaPair[0], muSigmaPair[1])

    # Loader has the channel at 1 index. But the show images need channel at the end.
    images = images.permute(0, 2, 3, 1)
    labels = __getLabels(l, randImages, classes)
    showImages(images.numpy(), labels, cols=5)