calculate correlation between feature map "f1" and "f2". See "FlowNet: Learning Optical Flow with Convolutional Networks" for details. Args: f1: a 4-D tensor with shape [B, H, W, C] f2: a 4-D tensor with shape [B, H, W, C] patch: an integer or a list like [k1, k2], window si
(f1, f2, patch, max_displacement, stride1=1, stride2=1)
| 371 | |
| 372 | |
| 373 | def correlation(f1, f2, patch, max_displacement, stride1=1, stride2=1): |
| 374 | """calculate correlation between feature map "f1" and "f2". |
| 375 | See "FlowNet: Learning Optical Flow with Convolutional Networks" for |
| 376 | details. |
| 377 | |
| 378 | Args: |
| 379 | f1: a 4-D tensor with shape [B, H, W, C] |
| 380 | f2: a 4-D tensor with shape [B, H, W, C] |
| 381 | patch: an integer or a list like [k1, k2], window size for comparison |
| 382 | max_displacement: an integer, representing the max searching distance |
| 383 | stride1: stride for patch |
| 384 | stride2: stride for displacement |
| 385 | |
| 386 | Returns: |
| 387 | a 4-D correlation tensor with shape [B, H, W, d*d] |
| 388 | """ |
| 389 | channel = f1.shape[-1] |
| 390 | norm = np.prod(to_list(patch, 2) + [channel]) |
| 391 | v1 = _make_vector(f1, patch, stride1) |
| 392 | v1 = tf.expand_dims(v1, -2) |
| 393 | v2 = _make_displacement(f2, patch, max_displacement, stride1, stride2) |
| 394 | corr = tf.matmul(v1, v2) / tf.to_float(norm) |
| 395 | return tf.squeeze(corr, axis=-2) |
| 396 | |
| 397 | |
| 398 | def pad_if_divide(x, value=16, mode='CONSTANT'): |