<jupyter_start><jupyter_text>Visualization of Blending FunctionsZero-padding at convolutional layers allow an output of the same size as the input, but the prediction is usually worse along the border of each input volume. Therefire we performe inference of overlopping volumes to alleviate the border artifacts. This demo visulizes the patterns of different blending functions/parameters.<jupyter_code>import numpy as np
from connectomics.data.utils import blend_gaussian, blend_bump

from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid

def show(image, cmap='gray', title='Test Title', interpolation=None):
    num_imgs = image.shape[0]
    fig = plt.figure(figsize=(20., 3.))
    fig.suptitle(title, fontsize=15)
    grid = ImageGrid(fig, 111,  # similar to subplot(111)
                     nrows_ncols=(1, num_imgs),  # creates 2x2 grid of axes
                     axes_pad=0.1,  # pad between axes in inch.
                     )
    image_list = np.split(image, num_imgs, 0)
    for ax, im in zip(grid, [np.squeeze(x) for x in image_list]):
        # Iterating over the grid returns the Axes.
        ax.imshow(im, cmap=cmap, interpolation=interpolation,
                  vmin=image.min(), vmax=image.max())
        # ax.imshow(im, cmap=cmap, interpolation=interpolation)
        ax.axis('off')

    plt.show()<jupyter_output><empty_output><jupyter_text>Visualization of the blending matrix<jupyter_code>sz = (6, 128, 128)
ww_g1 = blend_gaussian(sz, sigma=0.8)
ww_g2 = blend_gaussian(sz, sigma=0.4)
ww_g3 = blend_gaussian(sz, sigma=0.2)
ww_b = blend_bump(sz, t=1.5)
show(ww_g1, title='Gaussian Blending Function (sigma=0.8)')
show(ww_g2, title='Gaussian Blending Function (sigma=0.4)')
show(ww_g3, title='Gaussian Blending Function (sigma=0.2)')
show(ww_b, title='Bump Blending Function (t=1.5)')<jupyter_output><empty_output><jupyter_text>Visualization of the overlapping pattern<jupyter_code>def overlap_infenrece(vol, ww, size_factor):
    """Simulate inference with 50% overlap for x-y plane.
    """
    H, W = ww.shape[1:]
    stride = ww.shape[1] // 2
    for i in range(size_factor*2-1):
        for j in range(size_factor*2-1):
            vol[:, i*stride:i*stride+H, j*stride:j*stride+W] += ww
    return vol

size_factor = 3
vol_b = np.zeros((sz[0], sz[1]*size_factor, sz[2]*size_factor), dtype=np.float32)
vol_g1 = vol_b.copy()
vol_g2 = vol_b.copy()
vol_g3 = vol_b.copy()

vol_b = overlap_infenrece(vol_b, ww_b, size_factor)
vol_g1 = overlap_infenrece(vol_g1, ww_g1, size_factor)
vol_g2 = overlap_infenrece(vol_g2, ww_g2, size_factor)
vol_g3 = overlap_infenrece(vol_g3, ww_g3, size_factor)

show(vol_g1, title='Gaussian Blending Weight Map (sigma=0.8)')
show(vol_g2, title='Gaussian Blending Weight Map (sigma=0.4)')
show(vol_g3, title='Gaussian Blending Weight Map (sigma=0.2)')
show(vol_b, title='Bump Blending Weight Map (t=1.5)')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12006861063464837, 'fraction_numerical': 0.029502572898799314, 'mean_word_length': 4.491525423728813, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '487129', 'license': 'MIT', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1062, 'n_words': 259, 'path': 'notebooks/blending.ipynb', 'repo_name': 'smriti-joshi/pytorch_connectomics', 'size': '2915'}