import logging


def is_encoded_image_spec(tensor_spec):
  """Determines whether the passed tensor_spec speficies an encoded image."""
  if hasattr(tensor_spec, 'data_format'):
    # If tensor_spec is an ExtendedTensorSpec, use the data_format to check.
    return (tensor_spec.data_format is not None) and (
        tensor_spec.data_format.upper() in ['JPEG', 'PNG'])
  else:
    # Otherwise default to the old "name contains 'image'" logic.
    logging.warn('Using a deprecated tensor specification. '
                 'Use ExtendedTensorSpec.')
    return 'image' in tensor_spec.name