def _validate_shape(input_shape, data_shape, orientation=0, in_channels=1,
    levels=4):
    """
    Validates an input for propagation through a U-Net by taking into account the following:
        - Sampling along different orientations
        - Sampling multiple adjacent slices as channels
        - Maximum size that can be sampled from the data

    :param input_shape: original shape of the sample (Z, Y, X)
    :param data_shape: shape of the data to sample from (Z, Y, X)
    :param orientation: orientation to sample along
    :param in_channels: sample multiple adjacent slices as channels
    :param levels: amount of pooling layers in the network
    :return: the validated input shape
    """
    input_shape = list(input_shape)
    is2d = input_shape[0] == 1
    if is2d and in_channels > 1:
        input_shape[0] = in_channels
    if orientation == 1:
        input_shape = [input_shape[1], input_shape[0], input_shape[2]]
    elif orientation == 2:
        input_shape = [input_shape[2], input_shape[1], input_shape[0]]
    for d in range(3):
        if not (is2d and d == orientation) and input_shape[d] > data_shape[d]:
            input_shape[d] = int(data_shape[d] // 2 ** levels * 2 ** levels)
    return tuple(input_shape)
