コード例 #1
0
 def __init__(self, filename, schema, internal=False):
     with tf.name_scope("AvroIOTensor") as scope:
         metadata = ["schema: %s" % schema]
         resource, columns = core_ops.avro_readable_init(
             filename,
             metadata=metadata,
             container=scope,
             shared_name="%s/%s" % (filename, uuid.uuid4().hex))
         columns = [column.decode() for column in columns.numpy().tolist()]
         elements = []
         for column in columns:
             shape, dtype = core_ops.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.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(AvroIOTensor, self).__init__(spec,
                                            columns,
                                            elements,
                                            internal=internal)
コード例 #2
0
 def __init__(self, filename, internal=False):
     with tf.name_scope("FeatherIOTensor") as scope:
         resource, columns = core_ops.io_feather_readable_init(
             filename,
             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_feather_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_feather_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)