MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / build_graph

Method build_graph

examples/basics/svhn-digit-convnet.py:25–53  ·  view source on GitHub ↗
(self, image, label)

Source from the content-addressed store, hash-verified

23 tf.TensorSpec([None], tf.int32, 'label')]
24
25 def build_graph(self, image, label):
26 image = image / 128.0 - 1
27
28 with argscope(Conv2D, activation=BNReLU, use_bias=False):
29 logits = (LinearWrap(image)
30 .Conv2D('conv1', 24, 5, padding='VALID')
31 .MaxPooling('pool1', 2, padding='SAME')
32 .Conv2D('conv2', 32, 3, padding='VALID')
33 .Conv2D('conv3', 32, 3, padding='VALID')
34 .MaxPooling('pool2', 2, padding='SAME')
35 .Conv2D('conv4', 64, 3, padding='VALID')
36 .Dropout('drop', rate=0.5)
37 .FullyConnected('fc0', 512,
38 bias_initializer=tf.constant_initializer(0.1),
39 activation=tf.nn.relu)
40 .FullyConnected('linear', units=10)())
41 tf.nn.softmax(logits, name='output')
42
43 accuracy = tf.cast(tf.nn.in_top_k(logits, label, 1), tf.float32)
44 add_moving_summary(tf.reduce_mean(accuracy, name='accuracy'))
45
46 cost = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=label)
47 cost = tf.reduce_mean(cost, name='cross_entropy_loss')
48
49 wd_cost = regularize_cost('fc.*/W', l2_regularizer(0.00001))
50 add_moving_summary(cost, wd_cost)
51
52 add_param_summary(('.*/W', ['histogram', 'rms'])) # monitor W
53 return tf.add_n([cost, wd_cost], name='cost')
54
55 def optimizer(self):
56 lr = tf.train.exponential_decay(

Callers

nothing calls this directly

Calls 5

argscopeFunction · 0.85
LinearWrapClass · 0.85
add_moving_summaryFunction · 0.85
regularize_costFunction · 0.85
add_param_summaryFunction · 0.85

Tested by

no test coverage detected