MCPcopy Index your code
hub / github.com/tensorlayer/TensorLayer / test_STN

Method test_STN

tests/layers/test_layernode.py:195–231  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

193 self.assertEqual(net.all_layers[1].model.all_layers[0]._nodes_fixed, True)
194
195 def test_STN(self):
196 print('-' * 20, 'test STN', '-' * 20)
197
198 def get_model(inputs_shape):
199 ni = Input(inputs_shape)
200
201 ## 1. Localisation network
202 # use MLP as the localisation net
203 nn = Flatten()(ni)
204 nn = Dense(n_units=20, act=tf.nn.tanh)(nn)
205 nn = Dropout(keep=0.8)(nn)
206 # you can also use CNN instead for MLP as the localisation net
207
208 ## 2. Spatial transformer module (sampler)
209 stn = SpatialTransformer2dAffine(out_size=(40, 40), in_channels=20)
210 # s = stn((nn, ni))
211 nn = stn((nn, ni))
212 s = nn
213
214 ## 3. Classifier
215 nn = Conv2d(16, (3, 3), (2, 2), act=tf.nn.relu, padding='SAME')(nn)
216 nn = Conv2d(16, (3, 3), (2, 2), act=tf.nn.relu, padding='SAME')(nn)
217 nn = Flatten()(nn)
218 nn = Dense(n_units=1024, act=tf.nn.relu)(nn)
219 nn = Dense(n_units=10, act=tf.identity)(nn)
220
221 M = Model(inputs=ni, outputs=[nn, s])
222 return M
223
224 net = get_model([None, 40, 40, 1])
225
226 inputs = np.random.randn(2, 40, 40, 1).astype(np.float32)
227 o1, o2 = net(inputs, is_train=True)
228 self.assertEqual(o1.shape, (2, 10))
229 self.assertEqual(o2.shape, (2, 40, 40, 1))
230
231 self.assertEqual(len(net._node_by_depth), 10)
232
233
234if __name__ == '__main__':

Callers

nothing calls this directly

Calls 1

get_modelFunction · 0.50

Tested by

no test coverage detected