# In[19]: print("Class Likelihood Bad: {} Good: {}".format(logit[0, 0], logit[0, 1])) # ### Visualize It # Take the images and create a nice tiled image to look at. This will created a tiled image of: # # (1) The input image. # (2) The saliency map. # (3) The saliency map overlaid on the input image. # (4) The raw image enhanced with the most salient locations. # (5) The top 10% most salient locations. # In[20]: images = misc.TileOutput(raw_tensor, cam_map, getMask) # We now put all the images into a nice grid for display. # In[21]: images = make_grid(torch.cat(images, 0), nrow=5) # ... save and look at it. # In[22]: output_name = "{}.FASTCAM.jpg".format(save_prefix) output_path = os.path.join(output_dir, output_name) save_image(images, output_path)
# Get Forward sal map csmap,smaps,_ = get_salmap(in_tensor) # Let's get our original input image back. We will just use this one for visualization. raw_tensor = misc.LoadImageToTensor(load_image_name, device, norm=False) raw_tensor = F.interpolate(raw_tensor, size=(in_height, in_width), mode='bilinear', align_corners=False) # We create an object to get back the mask of the saliency map getMask = mask.SaliencyMaskDropout(keep_percent = 0.1, scale_map=False) # Now we will create illustrations of the combined saliency map. images = [] images = misc.TileOutput(raw_tensor,csmap,getMask,images) # Let's double check and make sure it's picking the correct class too_logit = logit.max(1) print("Network Class Output: {} : Value {} ".format(too_logit[1][0],too_logit[0][0])) # Now visualize the results images = misc.TileOutput(raw_tensor, cam_map.squeeze(0), getMask, images) # ### Combined CAM and SMOE Scale Maps # Now we combine the Grad-CAM map and the SMOE Scale saliency maps in the same way we would combine Grad-CAM with Guided Backprop. fastcam_map = csmap*cam_map