def __init__(self, filename, internal=False): with tf.name_scope("EXRIOTensor"): data = tf.io.read_file(filename) shapes, dtypes, channels = core_ops.io_decode_exr_info(data) parts = [] index = 0 for (shape, dtypes, channels) in zip(shapes.numpy(), dtypes.numpy(), channels.numpy()): # Remove trailing 0 from dtypes while dtypes[-1] == 0: dtypes.pop() channels.pop() spec = tuple([ tf.TensorSpec(tf.TensorShape(shape), dtype) for dtype in dtypes ]) columns = [channel.decode() for channel in channels] elements = [ io_tensor_ops.TensorIOTensor(core_ops.io_decode_exr( data, index, channel, dtype=dtype), internal=internal) for (channel, dtype) in zip(columns, dtypes) ] parts.append( EXRPartIOTensor(spec, columns, elements, internal=internal)) index += 1 spec = tuple([part.spec for part in parts]) columns = [i for i, _ in enumerate(parts)] super(EXRIOTensor, self).__init__(spec, columns, parts, internal=internal)
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 from_tensor(cls, tensor, **kwargs): """Converts a `tf.Tensor` into a `IOTensor`. Examples: ```python ``` Args: tensor: The `Tensor` to convert. Returns: A `IOTensor`. Raises: ValueError: If tensor is not a `Tensor`. """ with tf.name_scope(kwargs.get("name", "IOFromTensor")): return io_tensor_ops.TensorIOTensor(tensor, internal=True)
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)