f2073333b710a340403843763ba60eb1e6699916,examples/data_process/tutorial_tfrecord.py,,read_and_decode,#Any#,74
Before Change
// generate a queue with a given file name
filename_queue = tf.train.string_input_producer([filename])
reader = tf.TFRecordReader()
_ , serialized_example = reader.read(filename_queue) // return the file and the name of file
features = tf.parse_single_example(
serialized_example, // see parse_single_sequence_example for sequence example
features={
After Change
// use shuffle and batch
def read_and_decode(filename):
// generate a queue with a given file name
raw_dataset = tf .data.TFRecordDataset([filename]).shuffle(1000 ).batch(4)
for serialized_example in raw_dataset:
features = tf.io.parse_example(
serialized_example,
features={
"label": tf.io.FixedLenFeature([], tf.int64),
"img_raw": tf.io.FixedLenFeature([], tf.string),
}
)
// You can do more image distortion here for training data
img_batch = tf.io.decode_raw(features["img_raw"], tf.uint8)
img_batch = tf.reshape(img_batch, [4, 224, 224, 3])
// img = tf.cast(img, tf.float32) * (1. / 255) - 0.5
label_batch = tf.cast(features["label"], tf.int32)
yield img_batch, label_batch
img_batch, label_batch = next(read_and_decode("train.tfrecords"))
print("img_batch : %s" % img_batch.shape)
print("label_batch : %s" % label_batch.shape)
tl.visualize.images2d(img_batch, second=1, saveable=False, name="batch", dtype=None, fig_idx=2020121)
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 3
Instances Project Name: tensorlayer/tensorlayer
Commit Name: f2073333b710a340403843763ba60eb1e6699916
Time: 2019-04-11
Author: rundi_wu@pku.edu.cn
File Name: examples/data_process/tutorial_tfrecord.py
Class Name:
Method Name: read_and_decode
Project Name: tensorlayer/tensorlayer
Commit Name: f2073333b710a340403843763ba60eb1e6699916
Time: 2019-04-11
Author: rundi_wu@pku.edu.cn
File Name: examples/data_process/tutorial_tfrecord2.py
Class Name:
Method Name: read_and_decode
Project Name: hanxiao/bert-as-service
Commit Name: d97188ee62bc0627235578485c5df7d3245fa1ed
Time: 2018-12-02
Author: hanhxiao@tencent.com
File Name: example6.py
Class Name:
Method Name: