xingyul / flownet3d

FlowNet3D: Learning Scene Flow in 3D Point Clouds (CVPR 2019)
MIT License
363 stars 83 forks source link

Thank you very much ! what do you use when you generate the groundtruth of kitti? #21

Open anjingde opened 5 years ago

anjingde commented 5 years ago

disp_noc or disp_occ ?

anjingde commented 5 years ago

I have got the ground truth of kitti by my code. but it is different from yours. .the ground truth generated by optical flow is different from the frame2 and the ground truth you submit.I need your help,
the parameters: focal length=(721 or 718)cx and cy is from calib.

KevinYuk commented 4 years ago

Hi @anjingde ,

I have done this.

Origin kitti dataset looks like below:

gt
[[-6.50606757e-01 -7.71165091e-03 -3.62864930e-02]
 [-6.50809720e-01 -7.30375763e-03 -3.70871616e-02]
 [-6.50674281e-01 -7.18719799e-03 -3.67654337e-02]
 ...
 [-6.55581403e-01  8.44116230e-04 -3.59173445e-02]
 [-6.55385991e-01  5.79053468e-04 -3.66829281e-02]
 [-6.55479329e-01  7.85820204e-04 -3.61007760e-02]]
pos2
[[ 4.180698 -3.539728  0.444983]
 [ 4.307996 -3.632413  0.450001]
 [ 4.286587 -3.650779  0.447844]
 ...
 [ 4.354905 -3.593129 -1.096776]
 [ 4.336965 -3.593943 -1.093356]
 [ 4.329097 -3.59527  -1.091642]]
pos1
[[ 4.83130534 -3.532016    0.48126939]
 [ 4.95880602 -3.62510927  0.48708832]
 [ 4.93726086 -3.64359158  0.48460908]
 ...
 [ 5.03660353 -3.57625679 -1.10740632]
 [ 5.00526341 -3.59551057 -1.10095203]
 [ 4.956746   -3.60848824 -1.09762046]]

However, we could convert it to something like below :

points1
len:  8192
shape:  (8192, 3)
[[ 32.89994602 -21.54203147   0.56550137]
 [ 14.09534998  -4.2294481    0.35370887]
 [ 24.83187046   8.32069612  -0.17390744]
 ...
 [ 23.21345089  13.56470163   0.92837002]
 [ 14.26954007  -3.94390863   0.24294891]
 [ 14.2666964   -5.4370993   -0.36596146]]
color2
len:  8192
shape:  (8192, 3)
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 ...
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
flow
len:  8192
shape:  (8192, 3)
[[ 0.10617779  0.88679647 -0.03811332]
 [-0.44350357  0.79123925 -0.03079318]
 [-0.68674987  0.66008707 -0.03754272]
 ...
 [-0.8204942   0.61661119 -0.0367588 ]
 [-0.44902221  0.79157176 -0.03023025]
 [-0.41408755  0.79796613 -0.02728917]]
points2
len:  8192
shape:  (8192, 3)
[[ 14.03455843  -4.34205603   0.5828345 ]
 [ 13.89293276  -4.25363464   0.41936948]
 [ 22.52683529  14.04049128  -0.40132041]
 ...
 [ 31.62114953 -15.78595999   0.24209763]
 [  8.56035903  -6.42638545  -0.70365567]
 [ 26.94402805  -0.68263973   0.03776928]]
color1
len:  8192
shape:  (8192, 3)
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 ...
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
valid_mask1
len:  8192
shape:  (8192,)
[ True  True  True ...  True  True  True]

Trans code:

'''
    Provider for duck dataset from xingyu liu
'''

import os
import os.path
import json
import numpy as np
import sys
import pickle
import glob

class SceneflowDataset():
    def __init__(self, root='./', npoints=2048, train=True):
        self.npoints = npoints
        self.train = train
        self.root = root
        self.datapath = glob.glob(os.path.join(self.root, '*.npz'))
        self.cache = {}
        self.cache_size = 30000

        ###### deal with one bad datapoint with nan value
        #self.datapath = [d for d in self.datapath if 'TRAIN_C_0140_left_0006-0' not in d]
        ######

    def __getitem__(self, index):
        if index in self.cache:
            #pos1, pos2, color1, color2, flow, mask1 = self.cache[index]
            pos1, pos2, gt = self.cache[index]
        else:
            fn = self.datapath[index]
            with open(fn, 'rb') as fp:
                data = np.load(fp)
                pos1 = data['pos1']
                pos2 = data['pos2']
                color1 = np.zeros(pos1.shape)
                color2 = np.zeros(pos2.shape)
                flow = data['gt']
                mask1 = np.ones(len(pos1), dtype = bool)

            if len(self.cache) < self.cache_size:
                self.cache[index] = (pos1, pos2, color1, color2, flow, mask1)

            if self.train:
                n1 = pos1.shape[0]
                sample_idx1 = np.random.choice(n1, self.npoints, replace=False)
                n2 = pos2.shape[0]
                sample_idx2 = np.random.choice(n2, self.npoints, replace=False)

                pos1 = pos1[sample_idx1, :]
                pos2 = pos2[sample_idx2, :]
                color1 = color1[sample_idx1, :]
                color2 = color2[sample_idx2, :]
                flow = flow[sample_idx1, :]
                mask1 = mask1[sample_idx1]
            else:
                pos1 = pos1[:self.npoints, :]
                pos2 = pos2[:self.npoints, :]
                color1 = color1[:self.npoints, :]
                color2 = color2[:self.npoints, :]
                flow = flow[:self.npoints, :]
                mask1 = mask1[:self.npoints]

        return pos1, pos2, color1, color2, flow, mask1

    def __len__(self):
        return len(self.datapath)

if __name__ == '__main__':
    d = SceneflowDataset(npoints=2048*4)
    print('len of SceneflowDataset: ', len(d))
    import time
    tic = time.time()
    for i in range(len(d)):
        print('i: ', i)
        pc1, pc2, c1, c2, flow, m1 = d[i]

        npz_file = 'trans/trans_' + str(i) + '.npz'
        np.savez(npz_file, points1 = pc1, points2 = pc2, color1 = c1, color2 = c2, flow = flow, valid_mask1 = m1)
        print(npz_file + ' DONE!')