我尝试使用tf.data.Dataset.from_tensor_slices
获取数据集,但我得到:
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float).
with tf.device('/cpu:0'):
train_data = tf.data.Dataset.from_tensor_slices((train['email'].values, train['label'].values))
valid_data = tf.data.Dataset.from_tensor_slices((validation['email'].values, validation['label'].values))
,train['email'].values
是一个字符串数组
看起来你可能在你的输入数据集中混合了数据类型,如字符串和浮点值
工作样例代码
import tensorflow as tf
x_train = ['abc@gmail.com','xyz@gmail.com','aaa@gmail.com','abd@gmail.com']
y_train = ['0','1','0','1']
dataset = tf.data.Dataset.from_tensor_slices([x_train,y_train])
for element in dataset:
print(element)
tf.Tensor([b'abc@gmail.com' b'xyz@gmail.com' b'aaa@gmail.com' b'abd@gmail.com'], shape=(4,), dtype=string)
tf.Tensor([b'0' b'1' b'0' b'1'], shape=(4,), dtype=string)