Skip to content

Commit 32458de

Browse files
author
Clément Pinard
committed
identify invalid flow with 0 instead of NaN
NaN triggered lots of differentation problems
1 parent e271d7a commit 32458de

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

datasets/KITTI.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def load_flow_from_png(png_path):
2121
invalid = (flo_file[:,:,0] == 0)
2222
flo_img = flo_img - 32768
2323
flo_img = flo_img / 64
24-
flo_img[invalid, :] = float('nan')
24+
flo_img[np.abs(flo_img) < 1e-10] = 1e-10
25+
flo_img[invalid, :] = 0
2526
return(flo_img)
2627

2728

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ def __repr__(self):
339339
def flow2rgb(flow_map, max_value):
340340
global args
341341
_, h, w = flow_map.shape
342+
flow_map[:,(flow_map[0] == 0) & (flow_map[1] == 0)] = float('nan')
342343
rgb_map = np.ones((h,w,3)).astype(np.float32)
343344
if max_value is not None:
344345
normalized_flow_map = flow_map / max_value

models/FlowNetS.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import torch
22
import torch.nn as nn
33
from torch.nn.init import kaiming_normal
4-
import math
54

65
__all__ = [
7-
'FlowNetS', 'flownets', 'flownets_bn'
6+
'flownets', 'flownets_bn'
87
]
98

109

multiscaleloss.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ def EPE(input_flow, target_flow, sparse=False, mean=True):
66
EPE_map = torch.norm(target_flow-input_flow,2,1)
77
batch_size = EPE_map.size(0)
88
if sparse:
9-
# invalid flow is defined with one of flow coordinate to be NaN
10-
mask = (target_flow[:,0] != target_flow[:,0]) | (target_flow[:,1] != target_flow[:,1])
9+
# invalid flow is defined with both flow coordinates to be exactly 0
10+
mask = (target_flow[:,0] == 0) & (target_flow[:,1] == 0)
1111

1212
EPE_map = EPE_map[~mask.data]
1313
if mean:
@@ -16,11 +16,9 @@ def EPE(input_flow, target_flow, sparse=False, mean=True):
1616
return EPE_map.sum()/batch_size
1717

1818

19-
def sparse_max_pool(target, size):
20-
input = target.clone()
21-
input[(target != target).data] = 0
22-
positive = (target > 0).float()
23-
negative = (target < 0).float()
19+
def sparse_max_pool(input, size):
20+
positive = (input > 0).float()
21+
negative = (input < 0).float()
2422
output = nn.functional.adaptive_max_pool2d(input * positive, size) - nn.functional.adaptive_max_pool2d(-input * negative, size)
2523
return output
2624

0 commit comments

Comments
 (0)