我正在使用生成器(即tf.train.dataset
)生成一些from_generator()
,然后我对其进行序列化并将其存储在文件中,当我再次加载并通过parse_example对其进行解析时,它可以工作,但是如果我关闭了Jupiter服务器,然后读取了TFRecord
文件,它失败了,我不明白为什么。有人看到此错误了吗?:
InvalidArgumentError: Key: wing4. Can't parse serialized Example.
[[{{node ParseSingleExample/ParseSingleExample}}]]
[[IteratorGetNext]]
During handling of the above exception, another exception occurred:
我抱怨钥匙不存在,看起来像它无法解析序列化的样本。
这是我的一些功能:
def create_example(row):
features = {
'wing1': _float_feature(values=row['wing1']),
'wing2': _float_feature(values=row['wing2']),
'wing3': _float_feature(values=row['wing3']),
'wing4': _float_feature(values=row['wing4']),
}
return tf.train.Example(features=tf.train.Features(feature=features))
def create_records(gene, annotations, lds, record_path, train=True):
with tf.python_io.TFRecordWriter(record_path) as writer:
generator = data_generator(gene, annotations, lds, train)()
for row in generator:
example = create_example(row)
writer.write(example.SerializeToString())
def parse_function(example_proto):
features = {
'wing1': tf.FixedLenFeature([num_features], tf.float32),
'wing2': tf.FixedLenFeature([num_features], tf.float32),
'wing3': tf.FixedLenFeature([num_features], tf.float32),
'wing4': tf.FixedLenFeature([num_features], tf.float32),
}
return tf.parse_single_example(example_proto, features)