Tensorflow中的多标签分类器

gue*_*ues 4 python classification machine-learning multilabel-classification tensorflow

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

  • label-1类:灯光下雨,下雨,局部下雨,没有下雨
  • 标签-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)
Run Code Online (Sandbox Code Playgroud)

但是我认为多标签培训在这种情况下会更好用.

  • 我的功能将是[n_samples,n_features]
  • 我的标签是[n_samples,n_classes,2]

[x1,x2,x3,x4 ...]#个特征的n_samples

[[0,0,0,1],[0,0,1,0]]的n_samples#没有下雨和阴天

如何制作具有张量流的softmax概率分布预测器.有没有像这样的多标签问题的工作示例.我的损失将如何变得如此?

Ste*_*ven 5

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

网络 - >预测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
Run Code Online (Sandbox Code Playgroud)