【问题标题】:Multi-Label Classifier in TensorflowTensorFlow 中的多标签分类器
【发布时间】:2017-01-08 02:47:11
【问题描述】:

我想用 TensorFlow 开发一个多标签分类器,我试图表示存在多个包含多个类的标签。为了说明你可以想象这样的情况:

  • label-1 类:lighting raining、raining、partial raining、no raining
  • label-2 类别:晴天、部分多云、多云、非常多云。

我想用神经网络对这两个标签进行分类。现在,我为每个 (label-1, label-2) 对类使用不同的类标签。这意味着我有 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]] # 没有下雨和多云

如何使用 tensorflow 制作 softmax 概率分布预测器。有没有像这样的多标签问题的工作示例。我的损失张量如何?

【问题讨论】:

    标签: python machine-learning tensorflow classification multilabel-classification


    【解决方案1】:

    为什么不让您的网络产生两种不同的输出?

    网络 -> 预测 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 2017-12-30
      • 2023-03-16
      • 2021-10-04
      • 2016-05-25
      • 2017-06-03
      相关资源
      最近更新 更多