https://tools.ietf.org/html/rfc4180
#Relevant import
import numpy as np
import tensorflow as tf
To read text files in comma-separated value (CSV) format, use a tf.TextLineReader with the tf.decode_csv operation.
TensorFlow data reading: https://www.tensorflow.org/programmers_guide/reading_data
Sample code:
# Initialize
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
filename_queue = tf.train.string_input_producer(["X_IN_Y_TARGET.txt"])
reader=tf.TextLineReader()
key,value=reader.read(filename_queue)
record_defaults=[[1.000000],[1.000000],[1.000000]]
# Default values, in case of empty columns. Also specifies the type of the decoded result.
col1,col2, col3=tf.decode_csv(value, record_defaults=record_defaults) # Read each column. In this example, col 1 and 2 are inputs and col 3 is the actual output.
xin=tf.stack([col1,col2]) # Stack two columns into one tensor as the input.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord,sess=sess)
example= sess.run([xin,col3]) #Read one instance (one line of data only). "example" is an array.
batch_x=np.array([example[0]], np.float32) #Convert the first element of the array (xin) into nparray.
batch_y=np.array([example[1]], np.float32)
# Load 3995 more lines of data into batch_x and y.
for i in range(3995):
# Retrieve a single instance:
example= sess.run([xin,col3])
batch_x = np.vstack((batch_x, [example[0]])) # Add row to the input array.
batch_y = np.vstack((batch_y, [example[1]]))
#Now batch_x and y are nparray and can be used for TensorFlow neural network training.