如何使用tensorflow对一类数据进行分类?

如何使用tensorflow对一类数据进行分类?,tensorflow,deep-learning,Tensorflow,Deep Learning,我有一个用TensorFlow编写的复杂代码。这段代码适用于几个类。我想把代码改成一个类,这样我就可以教授zero类,并将任何与zero类数据不同的数据识别为非零数据。我在最后一层使用了sigmoid函数和一个神经元。我的模型训练很简单,但在测试时,它只识别任何其他类型数据的同一类。 我把代码放在下面。 如何将其更改为识别非类 h_drop = tf.nn.dropout(h_pool_flat, keep_prob=self.keep_prob) # Softmax w

我有一个用TensorFlow编写的复杂代码。这段代码适用于几个类。我想把代码改成一个类,这样我就可以教授zero类,并将任何与zero类数据不同的数据识别为非零数据。我在最后一层使用了sigmoid函数和一个神经元。我的模型训练很简单,但在测试时,它只识别任何其他类型数据的同一类。 我把代码放在下面。 如何将其更改为识别非类

    h_drop = tf.nn.dropout(h_pool_flat, keep_prob=self.keep_prob)
    # Softmax
    with tf.name_scope('softmax'):
        softmax_w = tf.Variable(tf.truncated_normal([num_filters_total, self.num_classes], stddev=0.1), name='softmax_w')
        softmax_b = tf.Variable(tf.constant(0.1, shape=[self.num_classes]), name='softmax_b')

        # Add L2 regularization to output layer
        self.l2_loss += tf.nn.l2_loss(softmax_w)
        self.l2_loss += tf.nn.l2_loss(softmax_b)

        self.logits = tf.matmul(h_drop, softmax_w) + softmax_b
        predictions = tf.nn.sigmoid(self.logits)
        print(predictions)
        **self.predictions = tf.argmax(predictions, 1, name='predictions')**

    # Loss
    with tf.name_scope('loss'):
        losses = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=self.input_y, logits=self.logits)
        # Add L2 losses
        self.cost = tf.reduce_mean(losses) + self.l2_reg_lambda * self.l2_loss

    # Accuracy
    with tf.name_scope('accuracy'):
        correct_predictions = tf.equal(self.predictions, self.input_y)
        print(self.input_y)
        print(self.predictions)
        self.correct_num = tf.reduce_sum(tf.cast(correct_predictions, tf.float32))
        self.accuracy = tf.reduce_mean(tf.cast(correct_predictions, tf.float32), name='accuracy')
这条线路需要更改,但我不知道如何更改。 self.predictions=tf.argmax(预测,1,name='predictions')
你能指导我吗?

想象一下你的概念错误:如果你被训练识别猫的形象,并且每次你在训练期间正确地喊“猫”,你就会得到一块饼干,如果你突然看到狗的形象,你会说什么
-没错,说“猫”,因为你还可以得到饼干

更具体地说,如果在培训期间没有这两种情况的示例,您的人际网络就无法了解“对”或“错”的含义。 如果没有一个负面的例子,你的培训将不会在经典意义上起作用,因为网络总是“有益的”,无论你展示什么,它都是它知道的单一类


单类分类的研究领域是存在的(例如,见和论文),但到目前为止,我想说的是,使用一些负面示例来获得良好的性能会更有意义,特别是如果您手头有大量现成的训练数据(即MNIST中的非零图像).

这是否是因为您拥有的“其他数据”比“零数据”多得多?对于类不平衡,神经网络只将所有内容分类为“非零”可能是“最有效的”,因为它可能会为训练数据提供相当高的精度。你有没有尝试过分割训练数据,这样你就有了正确和错误数据点的平衡?我有一个类数据。10000个类为0的数据。我想创建一个模型,如果输入了非零类的数据,就可以检测到该模型。非零类有多少样本?没有。我没有。
num\u类
有哪个值?