def check_datasets_compatible(dataset1, dataset2):
    """
    Used for cross-corpus datasets that are combined
    from two datasets.
    Checks if two datasets have the same class names
    and original shape.
    The first entry of the original shape is ignored,
    since the number of samples does not matter.

    Returns: class_names, original_shape
    Raises: Exception if datasets are not compatible
    """
    # check class names
    class_names1 = dataset1['class_names']
    class_names2 = dataset2['class_names']

    msg = f'Class names are not equal: {class_names1}, {class_names2}'
    e = Exception(f'Datasets are not compatible!\n{msg}')
    if len(class_names1) != len(class_names2):
        raise e
    for i in range(len(class_names1)):
        if class_names1[i] != class_names2[i]:
            raise e

    # check if both have a shape or not
    has_shape1 = has_shape2 = False
    if 'specs' in dataset1 and 'original_shape' in dataset1['specs']:
        has_shape1 = True
    if 'specs' in dataset2 and 'original_shape' in dataset2['specs']:
        has_shape2 = True
    if has_shape1 and not has_shape2:
        raise Exception(
            'Dataset 1 has a original_shape but dataset 2 does not!')
    if has_shape2 and not has_shape1:
        raise Exception(
            'Dataset 2 has a original_shape but dataset 1 does not!')

    #  check shapes
    original_shape = None
    if has_shape1 and has_shape2:
        shape1 = dataset1['specs']['original_shape']
        shape2 = dataset2['specs']['original_shape']
        msg = f'Shapes are not equal: {shape1}, {shape2}'
        e = Exception(f'Datasets are not compatible!\n{msg}')
        if len(shape1) != len(shape2):
            raise e
        for i in range(1, len(shape1)):
            if shape1[i] != shape2[i]:
                raise e
        original_shape = shape1

    return class_names1, original_shape