The data read method TensorFlow

Tensorflow provided a total of three kinds of ways to read data:
first approach personal feeling is too much trouble: at every step TensorFlow running, let Python code to supply data, such as data PIL and numpy treatment, and then input to the neural network .
The second method: reading data from a file, the starting TensorFlow FIG, allowing an input data line read from the file: string_input_producer () and slice_input_producer ().

They can be simply understood as the difference between the two: string_input_producer takes out a file name. slice_input_producer can either be released at the same time file name and its corresponding label, you can only release a file name. The only way to read the file is not the same in the actual application code, the other about the same.

string_input_producer method of loading data:

reader = tf.FixedLengthReader(record_bytes=record_bytes)

key, value = reader.read (filename_queue), which is the key file name, value is the byte stream binary file types, generally need to be decoded (decode) it can become an array, and then reshape operations.

path_queue queue file, the file generating method of the queue:

filenames = [os.path.join (data_dir, 'data_32_QP% d.dat'% i) for i in range (1,4)] ## data_dir is path data, data_32_QP% d.dat is a data file

for f in filenames:

  if not gfile.Exists (f): ## to determine whether there is a file or directory, filename can be a path to the directory with a file name or path, there is the directory returns True, otherwise False.

    raise ValueError('Failed to find file:'  + f )

Queue filename_queue = tf.train.string_input_producer (filenames) ## outputs a string with

reader = tf.FixedLengthReader (record_bytes = record_bytes) ## record_bytes character length is read each time the advantage is read, then the next reading is read here, does not re-read from the file header

key, then the processing required value = reader.read (filename_queue) ## reads data about: record_bytes = tf.decode_raw (value, tf.uint8)

Value record_bytes = tf.decode_raw (value, tf.uint8) ## This function is mainly used for data type conversion, the original data does not change the shape of the well

slice_input_producer loaded picture reader using tf.read_file (filename) read directly. Remember the need to decode and resize pictures into an array, it can be placed in memory queue file_queue waiting call.

Guess you like

Origin www.cnblogs.com/Mydream6/p/11333952.html