def decode_tiff_info(contents, name=None): """ Decode a TIFF-encoded image meta data. Args: contents: A `Tensor` of type `string`. 0-D. The TIFF-encoded image. name: A name for the operation (optional). Returns: A `Tensor` of type `uint8` and shape of `[height, width, 4]` (RGBA). """ shape, dtype = core_ops.io_decode_tiff_info(contents, name=name) return shape, dtype
def __init__(self, filename, internal=False): with tf.name_scope("TIFFIOTensor"): # TIFF can fit into memory so load TIFF first data = tf.io.read_file(filename) info = core_ops.io_decode_tiff_info(data) spec = tuple([ tf.TensorSpec(tf.TensorShape( e.numpy().tolist() + [4]), tf.uint8) for e in info]) columns = [i for i, _ in enumerate(spec)] elements = [ io_tensor_ops.TensorIOTensor( core_ops.io_decode_tiff(data, i), internal=internal) for i in columns] super(TIFFIOTensor, self).__init__( spec, columns, elements, internal=internal)
def __init__(self, filename, internal=True): if not internal: raise ValueError( "TIFFIODataset constructor is private; please use one " "of the factory methods instead (e.g., " "IODataset.from_pcap())") with tf.name_scope("TIFFIODataset"): content = tf.io.read_file(filename) _, dtype = core_ops.io_decode_tiff_info(content) # use dtype's rank to find out the number of elements dataset = tf.data.Dataset.range( tf.cast(tf.shape(dtype)[0], tf.int64)) dataset = dataset.map( lambda index: core_ops.io_decode_tiff(content, index)) self._dataset = dataset self._content = content super(TIFFIODataset, self).__init__(self._dataset._variant_tensor) # pylint: disable=protected-access
def __init__(self, filename, internal=False): with tf.name_scope("TIFFIOTensor"): # TIFF can fit into memory so load TIFF first data = tf.io.read_file(filename) shapes, dtypes = core_ops.io_decode_tiff_info(data) # NOTE: While shapes returned correctly handles 3 or 4 channels # we can only handle RGBA so fix shape as 4 for now, # until decode_tiff is updated. spec = tuple([ tf.TensorSpec(tf.TensorShape(shape.tolist()[0:2] + [4]), dtype) for (shape, dtype) in zip(shapes.numpy(), dtypes.numpy()) ]) columns = [i for i, _ in enumerate(spec)] elements = [ io_tensor_ops.TensorIOTensor(core_ops.io_decode_tiff(data, i), internal=internal) for i in columns ] super().__init__(spec, columns, elements, internal=internal)