我仍在尝试使用自己的图像数据运行 Tensorflow。 我能够使用此示例中的 conevert_to() 函数创建 .tfrecords 文件 link
现在我想用那个例子中的代码训练网络 link .
但它在 read_and_decode() 函数中失败了。我对该功能的更改是:
label = tf.decode_raw(features['label'], tf.string)
错误是:
TypeError: DataType string for attr 'out_type' not in list of allowed values: float32, float64, int32, uint8, int16, int8, int64
那么如何 1) 读取和 2) 使用字符串标签在 tensorflow 中进行训练。
最佳答案
convert_to_records.py
脚本创建一个 .tfrecords
文件,其中每条记录都是 Example
Protocol Buffer 。该 Protocol Buffer 使用 bytes_list
kind 支持字符串功能.
tf.decode_raw
op用于将二进制字符串解析为图像数据;它不是为解析字符串(文本)标签而设计的。假设 features['label']
是一个 tf.string
张量,您可以使用 tf.string_to_number
op 将其转换为数字。 TensorFlow 程序中对字符串处理的其他支持有限,因此如果您需要执行一些更复杂的函数将字符串标签转换为整数,您应该在 convert_to_tensor.py 的修改版本中用 Python 执行此转换
。
关于python - 在 Tensorflow 中使用字符串标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34084050/