Exemple #1
0
 def __init__(self, filename, schema, internal=False):
     with tf.name_scope("AvroIOTensor") as scope:
         metadata = ["schema: %s" % schema]
         resource, columns = core_ops.io_avro_readable_init(
             filename,
             metadata=metadata,
             container=scope,
             shared_name=f"{filename}/{uuid.uuid4().hex}",
         )
         columns = [column.decode() for column in columns.numpy().tolist()]
         elements = []
         for column in columns:
             shape, dtype = core_ops.io_avro_readable_spec(resource, column)
             shape = tf.TensorShape(shape.numpy())
             dtype = tf.as_dtype(dtype.numpy())
             spec = tf.TensorSpec(shape, dtype, column)
             function = io_tensor_ops._IOTensorComponentFunction(  # pylint: disable=protected-access
                 core_ops.io_avro_readable_read, resource, column, shape,
                 dtype)
             elements.append(
                 io_tensor_ops.BaseIOTensor(spec,
                                            function,
                                            internal=internal))
         spec = tuple(e.spec for e in elements)
         super().__init__(spec, columns, elements, internal=internal)
Exemple #2
0
 def __init__(self, filename, mode=None, internal=False):
     with tf.name_scope("JSONIOTensor") as scope:
         metadata = [] if mode is None else ["mode: %s" % mode]
         resource, columns = core_ops.io_json_readable_init(
             filename,
             metadata=metadata,
             container=scope,
             shared_name="{}/{}".format(filename,
                                        uuid.uuid4().hex),
         )
         columns = [column.decode() for column in columns.numpy().tolist()]
         elements = []
         for column in columns:
             shape, dtype = core_ops.io_json_readable_spec(resource, column)
             shape = tf.TensorShape(shape.numpy())
             dtype = tf.as_dtype(dtype.numpy())
             spec = tf.TensorSpec(shape, dtype, column)
             function = io_tensor_ops._IOTensorComponentFunction(  # pylint: disable=protected-access
                 core_ops.io_json_readable_read, resource, column, shape,
                 dtype)
             elements.append(
                 io_tensor_ops.BaseIOTensor(spec,
                                            function,
                                            internal=internal))
         spec = tuple([e.spec for e in elements])
         super().__init__(spec, columns, elements, internal=internal)