TensorFlow01: File Read

File reading process: configuration file name queue ---> read and decode ---> Batch

 

 

 Queue configuration file name:

Need to read the file name into the file name of the queue: 
tf.train.string_input_producer (string_tensor, shuffle = True) 
string_tensor: containing file name + first order tensor path 
num_epochs: too few data, default data had infinite 
return file queue

Reading and decoding:

Read the contents from the queue, and the decoding operation, the reader only reads the default each time a sample 
reading the contents of the file: text files by default once read a line, a picture, a specified number of bytes of binary 
tf.TextLinerReader: Reading take a text file comma separated value (csv format), the default line by line reading, the reader returns instance 
tf.WholeFileReader: for reading the image file, the reader returns instance 
tf.FixedLengthRecordReader (record_bytes): binary 
tf.TFRecordReader: read take TFRecords file 
their common method of reading: reader.read (file_queue), and returns a tuple Tensors (key, value); key file name, value a sample 
default will only read a sample, tf.train.batch or tf.tain.shuffle_batch batch operations. 
Content decoding: 
tf.decode_csv: decoded text file contents 
tf.image.decode_jpeg (contents): jpeg decoding the encoded image is unint8, the shape of [H, W, channels] 
tf.image.decode_png (contenst): The encoded png the image decoding is unint8, the shape of [H, W, channels] 
tf.decode_raw (): tf.FixedLengthRecordReader decoded binary file contents with the use of the type of reading unit8 
if required after conversion can be used to specify the type tf.cast () corresponding change

Batch:

 

After decoding, a sample can directly get the default content, to obtain a plurality of samples, such as the need to add a new batch queue 
tf.train.batch (Tensor, the batch_size, NUM_THREADS =. 1, Capacity = 32, name = None)   # + bATCH tf.train.shuffle 
     tensors: tensor can list the contents of a batch into the list among 
batch_size: batch size is read from the queue 
num_threads: enter the queue threads 
capcity: integer, formerly the largest in the queue number of 
return : tensors

 

 

 

Threaded operation:

 

tf.train.QueueRunner ()    # Create a queue formation 
tf.train.start_queue_runners (sess = None, coord = None) # start his run queue thread operations 
tf.train.Coordinator ()    # thread coordinator of the thread management and coordination 
request_stop (): request to stop 
should_stop (): asked whether the end of 
the Join (threads = None, stop_grace_period_secs = 120): collection threads

 

 

 

Reads the data:

 

Single picture: [h, w, channel] a plurality of images: [batch, h, w, channel] 
size of the picture needs to be consistent: tf.image.resize_images (Images, size) # [BATCH, H, W, C], new_h, new_w 
configuration file name read queue --- --- binary data decoding processing image retreat i.e. shape data type, batch --- open a session thread runs 
tf.transpose (depth_major, [ 1,2,0]) .eval ()     # [C, H, W] conversion [h, w, c]

 

 

 

 

 

 

Read from the queue, and the decoding operation, the reader reads only one sample per default

Read the contents of the file : text files by default once read a line, a picture, a specified number of bytes of binary

tf.TextLinerReader: reading a text comma separated value file ( CSV format), the default line by line reading, the reader returns instance

tf.WholeFileReader: used to read image files, returns the reader examples

tf.FixedLengthRecordReader (record_bytes): binary file

tf.TFRecordReader: reading TFRecords file

Together they read methods: reader.Read (file_queue), and returns a Tensors tuple ( Key, value ); Key file name, value a sample

The default will only read a sample, tf.train.batch or tf.tain.shuffle_batch batch operations.

Content decoding :

tf.decode_csv: decoding the contents of a text file

tf.image.decode_jpeg (contents): the jpeg picture decoding encoded as unint8, shape [h, w, channels]

tf.image.decode_png (contenst) : The png image decoding encoded as unint8, shape [h, w, channels]

tf.decode_raw (): decoding binary file contents tf.FixedLengthRecordReader with the use of reading unit8 type

If required, after conversion can be used to specify the type tf.cast () corresponding conversion

Guess you like

Origin www.cnblogs.com/jumpkin1122/p/11521029.html