Tensorflow 2 字符串标签到 one_hot
Tensorflow 2 string labels to one_hot
我正在尝试用 ["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
并根据
使用 os.environ["CUDA_VISIBLE_DEVICES"]="2"
定义我的设备
如果有必要,我会 post 更多我的代码。
1- 是否可以直接使用 tensorflow 2 将这些类型的标签转换为 hot,或者输入应该是 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.
我正在尝试用 ["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
并根据
os.environ["CUDA_VISIBLE_DEVICES"]="2"
定义我的设备
如果有必要,我会 post 更多我的代码。
1- 是否可以直接使用 tensorflow 2 将这些类型的标签转换为 hot,或者输入应该是 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.