【发布时间】:2017-07-22 12:11:38
【问题描述】:
我正在使用 Tensorflow DNN 模型进行一些分类。
我有一个数字 (float32) 数据输入,但 字符串类型输出。
x = tf.placeholder("float", [None, n_input])
y = tf.placeholder(tf.string, [None, n_classes])
当我尝试如下定义损失和优化器时:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))
我遇到了一个错误
TypeError: sigmoid_cross_entropy_with_logits() 出乎意料 关键字参数“标签”
我从here查了文档,上面写着
logits 和目标必须具有相同的类型和形状。
是否需要将类转换为浮点数(将字符串散列为数字)?
output_y = [["apple", "apple", "orange", "banana"]]
encoded_y = [[1], [1], [2], [3]]
【问题讨论】:
标签: python machine-learning tensorflow neural-network