tf 解析tfrecord

对于获取的一个tfrecord,若未知对应的key,则可参考tf.train.Example.FromString解析tfrecord

 

现在给出例子解析cifar10,下载链接:https://download.csdn.net/download/u014426939/13619698

从上面链接,得出cifar10键值:

{'label': 'tf.FixedLenFeature([1], tf.int64, default_value=0', 
'id': "tf.FixedLenFeature([], tf.string, default_value=''", 
'image': "tf.FixedLenFeature([], tf.string, default_value=''"}

解析cifar10:利用

tf.io.parse_example和tf.io.parse_single_example分别解析
import tensorflow as tf
import glob
tf.enable_eager_execution()

path='cifar/cifar10*.tfrecord*'

files=glob.glob(path)

keys_to_features = {
        "id": tf.FixedLenFeature([], tf.string, default_value=''),
        "image":tf.FixedLenFeature([],tf.string,default_value=''),
        "label":tf.FixedLenFeature([1],tf.int64,default_value=0),
    }

'''
def _parse_record(example):
    features = tf.io.parse_single_example(
       example,
       features=keys_to_features)
    id=features['id']
    image=features['image']
    label=features['label']
    image=tf.image.decode_image(image)
    #tf.image.resize(image)
    return id,image,label
'''
data = tf.data.TFRecordDataset(files)

data2 = data.map(lambda x : tf.io.parse_example(tf.reshape(x,[1]), features = keys_to_features))
iter2=data2.__iter__()
iter2.next()
#
#
data3 = data.map(lambda x : tf.io.parse_single_example(x, features = keys_to_features))
iter3=data3.__iter__()
iter3.next()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值