python - 在 Tensorflow 中使用字符串标签

标签 python label tensorflow

我仍在尝试使用自己的图像数据运行 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/

相关文章:

python - 如何验证 Flask 应用程序中的 URL 参数?

java - 标签的舞台叠加 - 标签很大,设置范围对于缩放来说毫无用处

css - 何时应在 html 形式的 span/dev 标签上使用 label 标签?

css - Shiny 的 selectInput 旁边的标签

python - 安装后 Anaconda 提示损坏

python - 3D SparseTensor 矩阵乘以 2D Tensor :InvalidArgumentError: Tensor 'a_shape' must have 2 elements [Op:SparseTensorDenseMatMul]

python - 如何创建一个脚本来获取用户输入并在使用 python 3.6 的终端命令中使用它?

python - 为什么 len() 没有为队列实现?

python - TensorFlow - 密集向量到独热

python - 基于 bool 值列表返回数据帧子集