def _build_graph(self, input_vars):
    (image, label) = input_vars

    def shortcut(l, n_in, n_out, stride):
        if (n_in != n_out):
            l = Conv2D('convshortcut', l, n_out, 1, stride=stride)
            return BatchNorm('bnshortcut', l)
        else:
            return l

    def bottleneck(l, ch_out, stride, preact):
        ch_in = l.get_shape().as_list()[(- 1)]
        input = l
        if (preact == 'both_preact'):
            l = tf.nn.relu(l, name='preact-relu')
            input = l
        l = Conv2D('conv1', l, ch_out, 1, stride=stride)
        l = BatchNorm('bn1', l)
        l = tf.nn.relu(l)
        l = Conv2D('conv2', l, ch_out, 3)
        l = BatchNorm('bn2', l)
        l = tf.nn.relu(l)
        l = Conv2D('conv3', l, (ch_out * 4), 1)
        l = BatchNorm('bn3', l)
        return (l + shortcut(input, ch_in, (ch_out * 4), stride))

    def layer(l, layername, features, count, stride, first=False):
        with tf.variable_scope(layername):
            with tf.variable_scope('block0'):
                l = bottleneck(l, features, stride, ('no_preact' if first else 'both_preact'))
            for i in range(1, count):
                with tf.variable_scope('block{}'.format(i)):
                    l = bottleneck(l, features, 1, 'both_preact')
            return l
    cfg = {50: [3, 4, 6, 3], 101: [3, 4, 23, 3], 152: [3, 8, 36, 3]}
    defs = cfg[MODEL_DEPTH]
    with argscope(Conv2D, nl=tf.identity, use_bias=False, W_init=variance_scaling_initializer(mode='FAN_OUT')):
        image = tf.pad(image, [[0, 0], [3, 3], [3, 3], [0, 0]])
        fc1000 = LinearWrap(image).Conv2D('conv0', 64, 7, stride=2, nl=BNReLU, padding='VALID').MaxPooling('pool0', shape=3, stride=2, padding='SAME').apply(layer, 'group0', 64, defs[0], 1, first=True).apply(layer, 'group1', 128, defs[1], 2).apply(layer, 'group2', 256, defs[2], 2).apply(layer, 'group3', 512, defs[3], 2).tf.nn.relu().GlobalAvgPooling('gap').FullyConnected('fc1000', 1000, nl=tf.identity)()
    prob = tf.nn.softmax(fc1000, name='prob')
    nr_wrong = prediction_incorrect(fc1000, label, name='wrong-top1')
    nr_wrong = prediction_incorrect(fc1000, label, 5, name='wrong-top5')
def _build_graph(self, input_vars):
    (image, label) = input_vars

    def shortcut(l, n_in, n_out, stride):
        if (n_in != n_out):
            l = Conv2D('convshortcut', l, n_out, 1, stride=stride)
            return BatchNorm('bnshortcut', l)
        else:
            return l

    def bottleneck(l, ch_out, stride, preact):
        ch_in = l.get_shape().as_list()[(- 1)]
        input = l
        if (preact == 'both_preact'):
            l = tf.nn.relu(l, name='preact-relu')
            input = l
        l = Conv2D('conv1', l, ch_out, 1, stride=stride)
        l = BatchNorm('bn1', l)
        l = tf.nn.relu(l)
        l = Conv2D('conv2', l, ch_out, 3)
        l = BatchNorm('bn2', l)
        l = tf.nn.relu(l)
        l = Conv2D('conv3', l, (ch_out * 4), 1)
        l = BatchNorm('bn3', l)
        return (l + shortcut(input, ch_in, (ch_out * 4), stride))

    def layer(l, layername, features, count, stride, first=False):
        with tf.variable_scope(layername):
            with tf.variable_scope('block0'):
                l = bottleneck(l, features, stride, ('no_preact' if first else 'both_preact'))
            for i in range(1, count):
                with tf.variable_scope('block{}'.format(i)):
                    l = bottleneck(l, features, 1, 'both_preact')
            return l
    cfg = {50: [3, 4, 6, 3], 101: [3, 4, 23, 3], 152: [3, 8, 36, 3]}
    defs = cfg[MODEL_DEPTH]
    with argscope(Conv2D, nl=tf.identity, use_bias=False, W_init=variance_scaling_initializer(mode='FAN_OUT')):
        image = tf.pad(image, [[0, 0], [3, 3], [3, 3], [0, 0]])
        fc1000 = LinearWrap(image).Conv2D('conv0', 64, 7, stride=2, nl=BNReLU, padding='VALID').MaxPooling('pool0', shape=3, stride=2, padding='SAME').apply(layer, 'group0', 64, defs[0], 1, first=True).apply(layer, 'group1', 128, defs[1], 2).apply(layer, 'group2', 256, defs[2], 2).apply(layer, 'group3', 512, defs[3], 2).tf.nn.relu().GlobalAvgPooling('gap').FullyConnected('fc1000', 1000, nl=tf.identity)()
    prob = tf.nn.softmax(fc1000, name='prob')
    nr_wrong = prediction_incorrect(fc1000, label, name='wrong-top1')
    nr_wrong = prediction_incorrect(fc1000, label, 5, name='wrong-top5')