Tensorflow TFDV不适用于图像



我正在尝试让TFDV使用RGB图像作为特征输入,从TFRecords文件中读取。我可以很好地将图像数据读/写到TFRecord文件中。以下是用于编写的相关代码片段,其中img是一个numpy[32,32,3]数组:

feature = {'train/label': _int64_feature(y_train[i]),
'train/image': _bytes_feature(tf.compat.as_bytes(img.tostring()))
}

并读回:

read_features = {'train/label': tf.FixedLenFeature([], tf.int64),
'train/image': tf.FixedLenFeature([], tf.string)}

然后,我可以使用frombruffer和整形来恢复我的图像。

问题是,当我使用TFRecords文件运行tfdv.generate_statistics_from_tfrecord((时。它抛出一个错误:

ValueError: 'xff ...... x87' has type str, but isn't valid UTF-8 encoding. Non-UTF-8 strings must be converted to unicode objects before being added. [while running 'GenerateStatistics/RunStatsGenerators/TopKStatsGenerator/TopK_ConvertToSingleFeatureStats']

我尝试过使用astype(unicode(等各种不同的方式来编写图像,但我可以;Don’我不能把它搞起来。

有什么想法吗?

谢谢,Paul

尝试以下操作:

image_string = open(image_location, 'rb').read()
feature = {'train/label': _int64_feature(y_train[i]),
'train/image': _bytes_feature(image_string)
}

参考官方教程

相关内容

最新更新