def extract_crops(image, size, stride=1):
    """Extract crops of size size from image using stride. Careful! This function only works for a batch_size = 1.

    Args:
        image:  torch tensor, dtype = torch.float32.
                expected dimensions: C X W X H,
                                     e.g. torch.Size([3, 224, 224])
        size:   size of the returned crops
        stride: number of pixels moved until next crop is extracted.
                Here: 1 (Even though, by default, BagNet-33 was trained with stride 8 and uses stride 8 when used to predict classes.)

    Returns:
        crops:  tensor of size number_of_crops x n_channels x crop_size x crop_size,
                e.g. torch.Size([36864, 3, 33, 33])
                type = torch.float32
    """
    image_permuted = image.permute(1, 2, 0)
    crops_unfolded = image_permuted.unfold(
        0, size, stride).unfold(
        1, size, stride)
    crops = crops_unfolded.contiguous().view((-1, 3, size, size))

    return crops