gpt4 book ai didi

python - 解析创建 eval.tfrecord 时使用的文件

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:53 24 4
gpt4 key购买 nike

我正在尝试获取用于创建 eval.tfrecord 的 .jpg 文件。

我在使用 python 打开文件并在文件上运行正则表达式来查找整个文件中随机列出的所有 .jpg 文件时遇到了麻烦。

现在我使用以下代码打开文件,并以结构化形式查看我需要的 .jpg 文件之一:

  feature {
key: "image/source_id"
value {
bytes_list {
value: "path/to/image.jpg"
}
}
}

下面是获得上述结果的代码:

#From the Tensorflow Docs:

from __future__ import absolute_import, division, print_function, unicode_literals

import tensorflow as tf
tf.enable_eager_execution()

import numpy as np
import IPython.display as display

record_iterator = tf.python_io.tf_record_iterator("eval.tfrecord")

for string_record in record_iterator:
example = tf.train.Example()
example.ParseFromString(string_record)

print(example)

# Exit after 1 iteration as this is purely demonstrative.
break

我只想获取使用的 .jpg,而不是文件中的所有数据。也许我可以通过某种方式使用 key: image/source_id 指定该功能来获取创建 tfrecord 时使用的所有 .jpg?

最佳答案

我将“print(example)”的输出重定向到一个文件中。然后能够读取该文件并使用正则表达式正常解析它以查找 .jpg 文件。

关于python - 解析创建 eval.tfrecord 时使用的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56978961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com