22import 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
1315def 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):
3638def 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