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

Method flownet2_sd

examples/OpticalFlow/flownet_models.py:266–320  ·  view source on GitHub ↗

Architecture in Table 3 of FlowNet 2.0. Args: x: concatenation of two inputs, of shape [1, 2xC, H, W]

(self, x)

Source from the content-addressed store, hash-verified

264 return tf.identity(flow0, name='flow2')
265
266 def flownet2_sd(self, x):
267 """
268 Architecture in Table 3 of FlowNet 2.0.
269
270 Args:
271 x: concatenation of two inputs, of shape [1, 2xC, H, W]
272 """
273 with argscope([tf.layers.conv2d], activation=lambda x: tf.nn.leaky_relu(x, 0.1),
274 padding='valid', strides=2, kernel_size=3,
275 data_format='channels_first'), \
276 argscope([tf.layers.conv2d_transpose], padding='same', activation=tf.identity,
277 data_format='channels_first', strides=2, kernel_size=4):
278 x = tf.layers.conv2d(pad(x, 1), 64, name='conv0', strides=1)
279
280 x = tf.layers.conv2d(pad(x, 1), 64, name='conv1')
281 conv1 = tf.layers.conv2d(pad(x, 1), 128, name='conv1_1', strides=1)
282 x = tf.layers.conv2d(pad(conv1, 1), 128, name='conv2')
283 conv2 = tf.layers.conv2d(pad(x, 1), 128, name='conv2_1', strides=1)
284
285 x = tf.layers.conv2d(pad(conv2, 1), 256, name='conv3')
286 conv3 = tf.layers.conv2d(pad(x, 1), 256, name='conv3_1', strides=1)
287 x = tf.layers.conv2d(pad(conv3, 1), 512, name='conv4')
288 conv4 = tf.layers.conv2d(pad(x, 1), 512, name='conv4_1', strides=1)
289 x = tf.layers.conv2d(pad(conv4, 1), 512, name='conv5')
290 conv5 = tf.layers.conv2d(pad(x, 1), 512, name='conv5_1', strides=1)
291 x = tf.layers.conv2d(pad(conv5, 1), 1024, name='conv6')
292 conv6 = tf.layers.conv2d(pad(x, 1), 1024, name='conv6_1', strides=1)
293
294 flow6 = tf.layers.conv2d(pad(conv6, 1), 2, name='predict_flow6', strides=1, activation=tf.identity)
295 flow6_up = tf.layers.conv2d_transpose(flow6, 2, name='upsampled_flow6_to_5')
296 x = tf.layers.conv2d_transpose(conv6, 512, name='deconv5', activation=lambda x: tf.nn.leaky_relu(x, 0.1))
297
298 concat5 = tf.concat([conv5, x, flow6_up], axis=1, name='concat5')
299 interconv5 = tf.layers.conv2d(pad(concat5, 1), 512, strides=1, name='inter_conv5', activation=tf.identity)
300 flow5 = tf.layers.conv2d(pad(interconv5, 1), 2, name='predict_flow5', strides=1, activation=tf.identity)
301 flow5_up = tf.layers.conv2d_transpose(flow5, 2, name='upsampled_flow5_to_4')
302 x = tf.layers.conv2d_transpose(concat5, 256, name='deconv4', activation=lambda x: tf.nn.leaky_relu(x, 0.1))
303
304 concat4 = tf.concat([conv4, x, flow5_up], axis=1, name='concat4')
305 interconv4 = tf.layers.conv2d(pad(concat4, 1), 256, strides=1, name='inter_conv4', activation=tf.identity)
306 flow4 = tf.layers.conv2d(pad(interconv4, 1), 2, name='predict_flow4', strides=1, activation=tf.identity)
307 flow4_up = tf.layers.conv2d_transpose(flow4, 2, name='upsampled_flow4_to_3')
308 x = tf.layers.conv2d_transpose(concat4, 128, name='deconv3', activation=lambda x: tf.nn.leaky_relu(x, 0.1))
309
310 concat3 = tf.concat([conv3, x, flow4_up], axis=1, name='concat3')
311 interconv3 = tf.layers.conv2d(pad(concat3, 1), 128, strides=1, name='inter_conv3', activation=tf.identity)
312 flow3 = tf.layers.conv2d(pad(interconv3, 1), 2, name='predict_flow3', strides=1, activation=tf.identity)
313 flow3_up = tf.layers.conv2d_transpose(flow3, 2, name='upsampled_flow3_to_2')
314 x = tf.layers.conv2d_transpose(concat3, 64, name='deconv2', activation=lambda x: tf.nn.leaky_relu(x, 0.1))
315
316 concat2 = tf.concat([conv2, x, flow3_up], axis=1, name='concat2')
317 interconv2 = tf.layers.conv2d(pad(concat2, 1), 64, strides=1, name='inter_conv2', activation=tf.identity)
318 flow2 = tf.layers.conv2d(pad(interconv2, 1), 2, name='predict_flow2', strides=1, activation=tf.identity)
319
320 return resize(flow2 / DISP_SCALE, mode='nearest')
321
322
323class FlowNet2S(FlowNetBase):

Callers 1

graph_structureMethod · 0.95

Calls 3

argscopeFunction · 0.90
padFunction · 0.85
resizeFunction · 0.85

Tested by

no test coverage detected