import torch


def draw_samples_from(gen, device, N=128, rescale=False):
    """
    Draws samples from the generator network.
    If normalize is True, image pixels are rescaled to [0, 255].
    """
    gen.eval()

    with torch.no_grad():
        noise = torch.randn(N, gen.z_dim, 1, 1, device=device)
        image = gen(noise)

    if rescale:
        image += 1.0
        image /= 2.0
        image *= 255.
        image = torch.clamp(image, 0., 255.).byte().cpu()

    return image