Skip to main content
 首页 » 编程设计

python之在 TensorFlow 中读取 jpeg 图像列表并将其转换为 TFRecords 的最快方法是什么

2025年04月02日23grandyang

我在 txt 文件中有一个图像和标签列表,格式如下:

文件1.jpg 1

文件2.jpg 0

文件3.jpg 1

文件4.jpg 1

标签是二进制的。

如何将图像数据转换为 TFRecord 文件而不将我的图像分配到标签的子目录(用于初始模型数据准备),并通过简单地读取 jpg 图像?我看过 tensorflow 的 TFRecords 教程,但似乎图像已经全部以张量形式构建。

我尝试了以下解决方案: How do I convert a directory of jpeg images to TFRecords file in tensorflow?

但是好像没有用。

请您参考如下方法:

按照以下链接中的代码解决您的问题。我完全按照你的要求做了。 (将一组 png 或 jpeg 图像转换为 TfRecords(二进制图像)。我提供了读取 tfrecords 的方法。此外,在我的例子中,我有一组存储在字符串中的特征,并且我将它们存储在 tfrecords 中。

Creating TfRecords from a list of strings and feeding a Graph in tensorflow after decoding

希望这段代码能帮到你。