Tensorflow 中的多标签分类器
Multi-Label Classifier in Tensorflow
我想用 TensorFlow 开发一个多标签 classifier,我的意思是存在包含多个 classes 的多个标签。为了说明,您可以想象这样的情况:
- label-1 classes:闪电下雨,下雨,局部下雨,不下雨
- label-2 classes:晴天,多云,多云,多云。
我想class用神经网络对这两个标签进行验证。现在,我为每个(label-1,label-2)对 classes 使用了不同的 class 标签。这意味着我有 4 x 4 = 16 个不同的标签。
通过
训练我的模型
当前损失
cross_entropy = tf.reduce_mean(-tf.reduce_sum(ys * tf.log(prediction), reduction_indices=[1]))
# prediction is sofmaxed
loss = cross_entropy + regul * schema['regul_ratio'] # regul things is for regularization
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
不过我认为多标签训练在这种情况下效果会更好。
- 我的功能将是 [n_samples、n_features]
- 我的标签将是 [n_samples、n_classes、2]
n_samples of [x1, x2, x3, x4 ...] # 特征
n_samples of [[0, 0, 0, 1], [0, 0, 1, 0]] # 没有下雨和多云
如何使用张量流制作 softmax 概率分布预测器。是否有像这样的多标签问题的工作示例。我的损失张量会怎样?
为什么不让你的网络产生两个不同的输出?
网络 -> 预测 1 和预测 2
其中 prediction1 和 prediction2 都是 [#,#,#,#],但我在下面描述的内容即使大小不同也有效。
然后 运行
loss1 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction1, labels_1))
loss2 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction2, labels_2))
loss = loss1 + loss2
我想用 TensorFlow 开发一个多标签 classifier,我的意思是存在包含多个 classes 的多个标签。为了说明,您可以想象这样的情况:
- label-1 classes:闪电下雨,下雨,局部下雨,不下雨
- label-2 classes:晴天,多云,多云,多云。
我想class用神经网络对这两个标签进行验证。现在,我为每个(label-1,label-2)对 classes 使用了不同的 class 标签。这意味着我有 4 x 4 = 16 个不同的标签。
通过
训练我的模型当前损失
cross_entropy = tf.reduce_mean(-tf.reduce_sum(ys * tf.log(prediction), reduction_indices=[1]))
# prediction is sofmaxed
loss = cross_entropy + regul * schema['regul_ratio'] # regul things is for regularization
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
不过我认为多标签训练在这种情况下效果会更好。
- 我的功能将是 [n_samples、n_features]
- 我的标签将是 [n_samples、n_classes、2]
n_samples of [x1, x2, x3, x4 ...] # 特征
n_samples of [[0, 0, 0, 1], [0, 0, 1, 0]] # 没有下雨和多云
如何使用张量流制作 softmax 概率分布预测器。是否有像这样的多标签问题的工作示例。我的损失张量会怎样?
为什么不让你的网络产生两个不同的输出?
网络 -> 预测 1 和预测 2
其中 prediction1 和 prediction2 都是 [#,#,#,#],但我在下面描述的内容即使大小不同也有效。
然后 运行
loss1 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction1, labels_1))
loss2 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction2, labels_2))
loss = loss1 + loss2