def _infer_coreml_output_shape(tf_shape):
    """Infer CoreML output shape from TensorFlow shape.
  """
    shape = []
    if len(tf_shape) == 1:
        shape = [tf_shape[0], 1, 1]
    elif len(tf_shape) == 2:
        if tf_shape[0] == 1:
            shape = [tf_shape[1]]
        else:
            shape = None
    elif len(tf_shape) == 3:
        shape = None
    elif len(tf_shape) == 4:
        shape = [tf_shape[3], tf_shape[1], tf_shape[2]]
    elif len(tf_shape) == 0:
        shape = [1]
    else:
        raise ValueError('Unrecognized TensorFlow output shape ' + str(
            tf_shape))
    return shape
