MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / build_graph

Method build_graph

examples/basics/mnist-visualizations.py:71–105  ·  view source on GitHub ↗
(self, image, label)

Source from the content-addressed store, hash-verified

69 tf.TensorSpec((None,), tf.int32, 'label')]
70
71 def build_graph(self, image, label):
72 image = tf.expand_dims(image * 2 - 1, 3)
73
74 with argscope(Conv2D, kernel_shape=3, nl=tf.nn.relu, out_channel=32):
75 c0 = Conv2D('conv0', image)
76 p0 = MaxPooling('pool0', c0, 2)
77 c1 = Conv2D('conv1', p0)
78 c2 = Conv2D('conv2', c1)
79 p1 = MaxPooling('pool1', c2, 2)
80 c3 = Conv2D('conv3', p1)
81 fc1 = FullyConnected('fc0', c3, 512, nl=tf.nn.relu)
82 fc1 = Dropout('dropout', fc1, 0.5)
83 logits = FullyConnected('fc1', fc1, out_dim=10, nl=tf.identity)
84
85 with tf.name_scope('visualizations'):
86 visualize_conv_weights(c0.variables.W, 'conv0')
87 visualize_conv_activations(c0, 'conv0')
88 visualize_conv_weights(c1.variables.W, 'conv1')
89 visualize_conv_activations(c1, 'conv1')
90 visualize_conv_weights(c2.variables.W, 'conv2')
91 visualize_conv_activations(c2, 'conv2')
92 visualize_conv_weights(c3.variables.W, 'conv3')
93 visualize_conv_activations(c3, 'conv3')
94
95 tf.summary.image('input', (image + 1.0) * 128., 3)
96
97 cost = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=label)
98 cost = tf.reduce_mean(cost, name='cross_entropy_loss')
99
100 tf.reduce_mean(tf.cast(tf.nn.in_top_k(logits, label, 1), tf.float32), name='accuracy')
101
102 wd_cost = tf.multiply(1e-5,
103 regularize_cost('fc.*/W', tf.nn.l2_loss),
104 name='regularize_loss')
105 return tf.add_n([wd_cost, cost], name='total_cost')
106
107 def optimizer(self):
108 lr = tf.train.exponential_decay(

Callers

nothing calls this directly

Calls 8

argscopeFunction · 0.85
Conv2DFunction · 0.85
MaxPoolingFunction · 0.85
FullyConnectedFunction · 0.85
DropoutFunction · 0.85
visualize_conv_weightsFunction · 0.85
regularize_costFunction · 0.85

Tested by

no test coverage detected