Exemple #1
0
def mask_image(zs, segmentation, image, background=None):
    if background is None:
        background = image.mean((0,1))
    out = np.zeros((zs.shape[0], image.shape[0], image.shape[1], image.shape[2]))
    for i in range(zs.shape[0]):
        out[i,:,:,:] = image
        for j in range(zs.shape[1]):
            if zs[i,j] == 0:
                out[i][segmentation == j,:] = background
    return out
Exemple #2
0
def mask_image(zs, segmentation, image, background = None): # auxiliary function, applies a mask to the given image
    
    if(background is None):
        background = image.mean((0, 1))
    
    out = np.zeros((zs.shape[0], image.shape[0], image.shape[1], image.shape[2]))
    
    for i in range(zs.shape[0]):
        out[i, :, :, :] = image
        
        for j in range(zs.shape[1]):
            if zs[i, j] == 0:
                out[i][segmentation == j, :] = background
    
    return(out)
Exemple #3
0
images_per_row = 16

# Processing the layer outputs
for layer_name, layer_activation in zip(
        layer_names,
        activations):  #getting the layer_names and their activations
    n_features = layer_activation.shape[-1]  #features in the layer
    size = layer_activation.shape[1]  #shape of the feature map
    n_cols = n_features // images_per_row  #number of images per row
    display_grid = np.zeros(
        (size * n_cols, images_per_row * size))  #size of the display grid
    for col in range(n_cols):  #organizing the columns...
        for row in range(images_per_row):  #...and rows to display
            image = layer_activation[0, :, :, col * images_per_row +
                                     row]  #retrieving the image...
            image -= image.mean()  #...and processing it in the...
            if (image.std() > 0):  #...following lines to display it
                image /= image.std()
                image *= 64
                image += 128
                image = np.clip(image, 0, 255).astype('uint8')
                display_grid[col * size:(col + 1) * size,
                             row * size:(row + 1) * size] = image

#displaying the layer names and processed grids
    print("Displaying layer:", layer_name)
    scale = 1. / size
    plt.figure(figsize=(scale * display_grid.shape[1],
                        scale * display_grid.shape[0]))
    plt.title(layer_name)
    plt.grid(False)