def filter_and_revise_example(serialized_example, samples_metadata):
"""Filter and revise a collection of existing TensorFlow examples.
Args:
serialized_example: the example to be revised and/or filtered
samples_metadata: dictionary of metadata for all samples
Returns:
A list containing the revised example or the empty list if the
example should be removed from the collection.
"""
example = tf.train.Example.FromString(serialized_example)
sample_name = example.features.feature[
encoder.SAMPLE_NAME_FEATURE].bytes_list.value[0]
logging.info('Checking ' + sample_name)
if sample_name not in samples_metadata:
logging.info('Omitting ' + sample_name)
return []
revised_features = {}
# Initialize with current example features.
revised_features.update(example.features.feature)
# Overwrite metadata features.
revised_features.update(
metadata_encoder.metadata_to_ancestry_features(
samples_metadata[sample_name]))
return [
tf.train.Example(features=tf.train.Features(feature=revised_features))
]
revise_preprocessed_data.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录