def _get_cost(self, input_vars, is_training):
        image, label = input_vars
        keep_prob = tf.constant(0.5 if is_training else 1.0)

        image = 1 - image / 128.0

        l = Conv2D('conv1', image, 24, 5, padding='VALID')
        l = MaxPooling('pool1', l, 2, padding='SAME')
        l = Conv2D('conv2', l, 32, 3, padding='VALID')
        l = Conv2D('conv3', l, 32, 3, padding='VALID')
        l = MaxPooling('pool2', l, 2, padding='SAME')
        l = Conv2D('conv4', l, 64, 3, padding='VALID')

        l = tf.nn.dropout(l, keep_prob)
        l = FullyConnected('fc0', l, 512,
                           b_init=tf.constant_initializer(0.1))
        # fc will have activation summary by default. disable for the output layer
        logits = FullyConnected('linear', l, out_dim=10, nl=tf.identity)
        prob = tf.nn.softmax(logits, name='output')

        cost = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, label)
        cost = tf.reduce_mean(cost, name='cross_entropy_loss')
        tf.add_to_collection(MOVING_SUMMARY_VARS_KEY, cost)

        # compute the number of failed samples, for ClassificationError to use at test time
        wrong = prediction_incorrect(logits, label)
        nr_wrong = tf.reduce_sum(wrong, name='wrong')
        # monitor training error
        tf.add_to_collection(
            MOVING_SUMMARY_VARS_KEY, tf.reduce_mean(wrong, name='train_error'))

        # weight decay on all W of fc layers
        wd_cost = regularize_cost('fc.*/W', l2_regularizer(0.00001))
        tf.add_to_collection(MOVING_SUMMARY_VARS_KEY, wd_cost)

        add_param_summary([('.*/W', ['histogram', 'sparsity'])])   # monitor W
        return tf.add_n([cost, wd_cost], name='cost')
dataset/ETHPy150Open ppwwyyxx/tensorpack/examples/svhn-digit-convnet.py/Model._get_cost/swapped operands of `-`