<p>To visualize your conceptional error: If you are trained to recognize images of cats, and every time you correctly shout "cat" during training time you get a cookie, what would you say if you suddenly see an image of a dog? <br/>
 - Exactly, say "cat", since you still get the cookie. </p>

<p>More specifically, there is no way for your network to learn what "right" or "wrong" means, without having examples for both cases during training time.
Without a negative example, your training won't work in the classical sense, as it will always be "beneficial" for the network to say whatever you're showing it is the single class it knows.</p>

<p>The research area of single-class classification exists (see <a href="https://arxiv.org/pdf/1802.06360.pdf" rel="nofollow noreferrer">this</a> and <a href="https://arxiv.org/pdf/1801.05365.pdf" rel="nofollow noreferrer">this</a> paper, for example), but so far I would say that it would make much more sense to use some negative examples to get a decent performance, especially if you have an abundance of readily available training data at hand (namely, the non-zero images in MNIST).</p>
How to classify one-class data using tensorflow?
<p>I have a deep winding code written with TensorFlow. This code is for several classes. I want to change the code to a class so that I can teach the zero class and identify any data that is not like zero class data as non-zero. I use the sigmoid function and a neuron in the last layer. My model training is easy, but at the time of testing it only recognizes the same class for any other type of data.
I put the code below.
How do I change it to recognize non-class?</p>

<pre><code>    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')
</code></pre>

<p>This line needs to be changed, but I do not know how.
<strong>self.predictions = tf.argmax(predictions, 1, name='predictions')</strong>
can you guide me?</p>