Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f450bdb

Browse files
author
Clément Pinard
committed
train on EPE sum instead of mean EPE
1 parent 52ff740 commit f450bdb

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

multiscaleloss.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import torch.nn as nn
33

44

5-
def EPE(input_flow, target_flow, sparse=False):
5+
def EPE(input_flow, target_flow, sparse=False, mean=True):
66
EPE_map = torch.norm(target_flow-input_flow,2,1)
77
if sparse:
8-
return EPE_map[target_flow == 0].mean()
9-
else:
8+
EPE_map = EPE_map[target_flow == 0]
9+
if mean:
1010
return EPE_map.mean()
11+
else:
12+
return EPE_map.sum()
1113

1214

1315
def multiscaleEPE(network_output, target_flow, weights=None, sparse=False):
@@ -19,7 +21,7 @@ def one_scale(output, target, sparse):
1921
target_scaled = nn.functional.adaptive_max_pool2d(target, (h, w))
2022
else:
2123
target_scaled = nn.functional.adaptive_avg_pool2d(target, (h, w))
22-
return EPE(output, target_scaled, sparse)
24+
return EPE(output, target_scaled, sparse, mean=False)
2325

2426
if type(network_output) not in [tuple, list]:
2527
network_output = [network_output]
@@ -36,4 +38,4 @@ def one_scale(output, target, sparse):
3638
def realEPE(output, target, sparse=False):
3739
b, _, h, w = target.size()
3840
upsampled_output = nn.functional.upsample(output, size=(h,w), mode='bilinear')
39-
return EPE(upsampled_output, target, sparse)
41+
return EPE(upsampled_output, target, sparse, mean=True)

0 commit comments

Comments
 (0)