def volume2subvolumes(volume, subvolume_size, stride_size):
    """Converts 3D volumes into 3D subvolumes; works with PyTorch tensors."""
    subvolumes = []
    assert volume.ndim == 3

    for x in range(0, (volume.shape[0] - subvolume_size[0]) + 1, stride_size[0]):
        for y in range(0, (volume.shape[1] - subvolume_size[1]) + 1, stride_size[1]):
            for z in range(0, (volume.shape[2] - subvolume_size[2]) + 1, stride_size[2]):
                subvolume = volume[x: x + subvolume_size[0],
                                   y: y + subvolume_size[1],
                                   z: z + subvolume_size[2]]
                subvolumes.append(subvolume)

    return subvolumes