def patchify_tensor(features, patch_size, overlap=10):
    (batch_size, channels, height, width) = features.size()
    effective_patch_size = (patch_size - overlap)
    n_patches_height = (height // effective_patch_size)
    n_patches_width = (width // effective_patch_size)
    if ((n_patches_height * effective_patch_size) < height):
        n_patches_height += 1
    if ((n_patches_width * effective_patch_size) < width):
        n_patches_width += 1
    patches = []
    for b in range(batch_size):
        for h in range(n_patches_height):
            for w in range(n_patches_width):
                patch_start_height = min((h * effective_patch_size), (height - patch_size))
                patch_start_width = min((w * effective_patch_size), (width - patch_size))
                patches.append(features[b:(b + 1), :, patch_start_height:(patch_start_height + patch_size), patch_start_width:(patch_start_width + patch_size)])
    return torch.cat(patches, 0)
def patchify_tensor(features, patch_size, overlap=10):
    (batch_size, channels, height, width) = features.size()
    effective_patch_size = (patch_size - overlap)
    n_patches_height = (height // effective_patch_size)
    n_patches_width = (width // effective_patch_size)
    if ((n_patches_height * effective_patch_size) < height):
        n_patches_height += 1
    if ((n_patches_width * effective_patch_size) < width):
        n_patches_width += 1
    patches = []
    for b in range(batch_size):
        for h in range(n_patches_height):
            for w in range(n_patches_width):
                patch_start_height = min((h * effective_patch_size), (height - patch_size))
                patch_start_width = min((w * effective_patch_size), (width - patch_size))
                patches.append(features[b:(b + 1), :, patch_start_height:(patch_start_height + patch_size), patch_start_width:(patch_start_width + patch_size)])
    return torch.cat(patches, 0)