gpt4 book ai didi

python - 将 TFRecords 转换回 JPEG 图像

转载 作者:太空宇宙 更新时间:2023-11-04 08:32:59 25 4
gpt4 key购买 nike

我有一个包含数百个 TFRecords 的文件。每个 TFRecord 文件包含 1,024 条记录。每条记录包含以下信息:

The Example proto contains the following fields:

image/height: integer, image height in pixels
image/width: integer, image width in pixels
image/colorspace: string, specifying the colorspace, always 'RGB'
image/channels: integer, specifying the number of channels, always 3
image/class/label: integer, specifying the index in a normalized classification layer
image/class/raw: integer, specifying the index in the raw (original) classification layer
image/class/source: integer, specifying the index of the source (creator of the image)
image/class/text: string, specifying the human-readable version of the normalized label
image/format: string, specifying the format, always 'JPEG'
image/filename: string containing the basename of the image file
image/id: integer, specifying the unique id for the image
image/encoded: string, containing JPEG encoded image in RGB colorspace

我将这些 TFRecords 中的每一个都存储在目录路径/Data/train 中。 python 中是否有一种不太复杂的方法将 TFRecord 中的这些图像转换回 JPEG 格式并将它们保存到另一个目录/data/image.jpeg 中?我看过看起来很痛苦的 TensorFlow 文档,还有这个 script它将 TFRecord 转换为数组,但我遇到了问题。任何帮助、更正或反馈将不胜感激!谢谢。

我正在处理的数据是 MARCO 图像数据:

https://marco.ccr.buffalo.edu/download

最佳答案

这应该有效:

record_iterator = tf.python_io.tf_record_iterator(path_to_tfrecords_file)

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

image = example.features.feature["encoded"].bytes_list.value[0]

# save image to file
# ...

关于python - 将 TFRecords 转换回 JPEG 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51409906/

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