MCPcopy Create free account
hub / github.com/LoSealL/VideoSuperResolution / correlation

Function correlation

VSR/Util/Utility.py:373–395  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

371
372
373def 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
398def pad_if_divide(x, value=16, mode='CONSTANT'):

Callers 2

test_correlationFunction · 0.90
test_correlation_strideFunction · 0.90

Calls 3

to_listFunction · 0.85
_make_vectorFunction · 0.85
_make_displacementFunction · 0.85

Tested by 2

test_correlationFunction · 0.72
test_correlation_strideFunction · 0.72