gpt4 book ai didi

python - Tensorflow 2 字符串标签到 one_hot

转载 作者:行者123 更新时间:2023-12-05 05:03:57 26 4
gpt4 key购买 nike

我正在尝试使用 ["aa", "aa", "bb", "bb", "bb", "cc"] 形式的字符串标签拟合模型,并希望使用 tf.one_hot(labels, depth=3) 获取一个热向量,但出现错误:

NotFoundError: Could not find valid device for node.
Node:{{node OneHot}}
All kernels registered for op OneHot :
device='XLA_GPU'; TI in [DT_INT32, DT_UINT8, DT_INT64]; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, ..., DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64]
device='XLA_CPU'; TI in [DT_INT32, DT_UINT8, DT_INT64]; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, ..., DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64]

我的问题:

1- 是否可以直接使用 tensorflow 2 将这些类型的标签转换为一个热标签,或者输入应该是 INT

2-如果是什么可能导致这个问题

3-是否可以直接用字符串标签拟合模型?

额外信息:

我正在使用一个集群来训练和使用 GPU 并根据 this 使用 os.environ["CUDA_VISIBLE_DEVICES"]="2" 定义我的设备 |

如果有必要,我会发布更多我的代码。

最佳答案

1- 是否可以直接使用 tensorflow 2 将这些类型的标签转换为一个热标签,或者输入应该是 INT?

2-如果是什么可能导致这个问题

TensorFlow only supports numeric indices. If you look at the documentation for tf.one_hot, it is in fact an index you are passing as the labels. I found this info via this Github issue

3-是否可以直接用字符串标签拟合模型?

I don't see an easy way out for this. But if you can fit your data in-memory, I'd suggest using pandas/sklearn and convert these to onehot encoded. If it doesn't you might need to create a series of feature columns for your data. For example this feature column supports what you need to achieve.

关于python - Tensorflow 2 字符串标签到 one_hot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61384935/

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