为了解析每个输入样本每一列数据,需要定义一个解析字典。tensorflow提供了三种方式:FixedLenFeature、VarLenFeature、FixedLenSequenceFeature,分别解析定长特征、变长特征、定长序列特征。
FixedLenFeature() 函数有三个参数:
(1)shape:输入数据的shape。
(2)dtype:输入的数据类型。
(3)default_value:如果示例缺少此功能,则使用该值。它必须与dtype和指定shape兼容。
示例如下:
keys_to_features = { 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.FixedLenFeature((), tf.string, default_value='jpg'), 'image/class/label': tf.FixedLenFeature([], tf.int64, default_value=tf.zeros([], dtype=tf.int64)), }