read_tfrecord.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:tensorflow-yys 作者: ystyle 项目源码 文件源码
def read_and_decode(filename, batch_size):
    # ???????????
    filename_queue = tf.train.string_input_producer([filename])
    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)  # ????????
    features = tf.parse_single_example(
        serialized_example,
        features={
            'label': tf.FixedLenFeature([], tf.int64),
            'img_raw': tf.FixedLenFeature([], tf.string),
        }
    )
    img = tf.decode_raw(features['img_raw'], tf.uint8)
    print('xxxx: ', img.get_shape())
    img = tf.reshape(img, [512, 144, 3])
    img = tf.cast(img, tf.float32) * (1. / 255) - 0.5
    label = tf.cast(features['label'], tf.int32)
    image_batch, label_batch = tf.train.batch([img, label],
                                              batch_size=batch_size,
                                              num_threads=64,
                                              capacity=2000)
    return image_batch, tf.reshape(label_batch, [batch_size])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号