import math
import torch


def construct_scale_pyramid(image, scale_factor=0.75, N=4, method='bicubic'):
    """
    Constructs the scale pyramid

    :param image: normed image tensor with shape (N, C, H, W)
    :param scale_factor: float that indicates scale factor
    :param N: int that indicates the number of needed scaled image
    :param method: interpolation method while downscaling the image
    :return: Scale pyramid, list of normed image tensors
    """
    pyramid = [image]

    for i in range(N):
        scale = scale_factor ** (i+1)
        scale_shape = (image.shape[2] * scale, image.shape[3]*scale)
        scale_shape = tuple(map(math.ceil, scale_shape))
        downsampled_img = torch.nn.functional.interpolate(image, size=scale_shape, mode=method, align_corners=False)

        pyramid.append(downsampled_img)

    return pyramid