Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesq34 committed May 14, 2018
2 parents 857c3e1 + c0dcd46 commit 37f7b75
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 49 deletions.
12 changes: 9 additions & 3 deletions kitti/kitti_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Charles R. Qi
Date: September 2017
'''
from __future__ import print_function

import os
import sys
Expand All @@ -14,6 +15,11 @@
sys.path.append(os.path.join(ROOT_DIR, 'mayavi'))
import kitti_util as utils

try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3


class kitti_object(object):
'''Load and parse object data into a usable format.'''
Expand Down Expand Up @@ -149,13 +155,13 @@ def show_lidar_with_boxes(pc_velo, objects, calib,
if 'mlab' not in sys.modules: import mayavi.mlab as mlab
from viz_util import draw_lidar_simple, draw_lidar, draw_gt_boxes3d

print('All point num: ', pc_velo.shape[0])
print(('All point num: ', pc_velo.shape[0]))
fig = mlab.figure(figure=None, bgcolor=(0,0,0),
fgcolor=None, engine=None, size=(1000, 500))
if img_fov:
pc_velo = get_lidar_in_image_fov(pc_velo, calib, 0, 0,
img_width, img_height)
print('FOV point num: ', pc_velo.shape[0])
print(('FOV point num: ', pc_velo.shape[0]))
draw_lidar(pc_velo, fig=fig)

for obj in objects:
Expand Down Expand Up @@ -203,7 +209,7 @@ def dataset_viz():
img = dataset.get_image(data_idx)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_height, img_width, img_channel = img.shape
print('Image shape: ', img.shape)
print(('Image shape: ', img.shape))
pc_velo = dataset.get_lidar(data_idx)[:,0:3]
calib = dataset.get_calibration(data_idx)

Expand Down
3 changes: 2 additions & 1 deletion kitti/kitti_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Charles R. Qi
Date: September 2017
"""
from __future__ import print_function

import numpy as np
import cv2
Expand Down Expand Up @@ -287,7 +288,7 @@ def project_to_image(pts_3d, P):
'''
n = pts_3d.shape[0]
pts_3d_extend = np.hstack((pts_3d, np.ones((n,1))))
print('pts_3d_extend shape: ', pts_3d_extend.shape)
print(('pts_3d_extend shape: ', pts_3d_extend.shape))
pts_2d = np.dot(pts_3d_extend, np.transpose(P)) # nx3
pts_2d[:,0] /= pts_2d[:,2]
pts_2d[:,1] /= pts_2d[:,2]
Expand Down
15 changes: 8 additions & 7 deletions kitti/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Charles R. Qi
Date: September 2017
'''
from __future__ import print_function

import os
import sys
Expand Down Expand Up @@ -52,7 +53,7 @@ def demo():
img = dataset.get_image(data_idx)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_height, img_width, img_channel = img.shape
print('Image shape: ', img.shape)
print(('Image shape: ', img.shape))
pc_velo = dataset.get_lidar(data_idx)[:,0:3]
calib = dataset.get_calibration(data_idx)

Expand Down Expand Up @@ -84,7 +85,7 @@ def demo():
box3d_pts_2d, box3d_pts_3d = utils.compute_box_3d(objects[0], calib.P)
box3d_pts_3d_velo = calib.project_rect_to_velo(box3d_pts_3d)
box3droi_pc_velo, _ = extract_pc_in_box3d(pc_velo, box3d_pts_3d_velo)
print('Number of points in 3d box: ', box3droi_pc_velo.shape[0])
print(('Number of points in 3d box: ', box3droi_pc_velo.shape[0]))

fig = mlab.figure(figure=None, bgcolor=(0,0,0),
fgcolor=None, engine=None, size=(1000, 500))
Expand Down Expand Up @@ -120,7 +121,7 @@ def demo():
objects[0].xmin, objects[0].ymin, objects[0].xmax, objects[0].ymax
boxfov_pc_velo = \
get_lidar_in_image_fov(pc_velo, calib, xmin, ymin, xmax, ymax)
print('2d box FOV point num: ', boxfov_pc_velo.shape[0])
print(('2d box FOV point num: ', boxfov_pc_velo.shape[0]))

fig = mlab.figure(figure=None, bgcolor=(0,0,0),
fgcolor=None, engine=None, size=(1000, 500))
Expand Down Expand Up @@ -179,7 +180,7 @@ def extract_frustum_data(idx_filename, split, output_filename, viz=False,
pos_cnt = 0
all_cnt = 0
for data_idx in data_idx_list:
print '------------- ', data_idx
print('------------- ', data_idx)
calib = dataset.get_calibration(data_idx) # 3 by 4 matrix
objects = dataset.get_label_objects(data_idx)
pc_velo = dataset.get_lidar(data_idx)
Expand All @@ -200,8 +201,8 @@ def extract_frustum_data(idx_filename, split, output_filename, viz=False,
# Augment data by box2d perturbation
if perturb_box2d:
xmin,ymin,xmax,ymax = random_shift_box2d(box2d)
print box2d
print xmin,ymin,xmax,ymax
print(box2d)
print(xmin,ymin,xmax,ymax)
else:
xmin,ymin,xmax,ymax = box2d
box_fov_inds = (pc_image_coord[:,0]<xmax) & \
Expand Down Expand Up @@ -284,7 +285,7 @@ def get_box3d_dim_statistics(idx_filename):
ry_list = []
data_idx_list = [int(line.rstrip()) for line in open(idx_filename)]
for data_idx in data_idx_list:
print '------------- ', data_idx
print('------------- ', data_idx)
calib = dataset.get_calibration(data_idx) # 3 by 4 matrix
objects = dataset.get_label_objects(data_idx)
for obj_idx in range(len(objects)):
Expand Down
6 changes: 6 additions & 0 deletions mayavi/viz_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import numpy as np
import mayavi.mlab as mlab

try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3


def draw_lidar_simple(pc, color=None):
''' Draw lidar points. simplest set up. '''
fig = mlab.figure(figure=None, bgcolor=(0,0,0), fgcolor=None, engine=None, size=(1600, 1000))
Expand Down
3 changes: 2 additions & 1 deletion models/frustum_pointnets_v1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
''' Frsutum PointNets v1 Model.
'''
from __future__ import print_function

import sys
import os
Expand Down Expand Up @@ -189,7 +190,7 @@ def get_model(point_cloud, one_hot_vec, is_training, bn_decay=None):
inputs = tf.zeros((32,1024,4))
outputs = get_model(inputs, tf.ones((32,3)), tf.constant(True))
for key in outputs:
print(key, outputs[key])
print((key, outputs[key]))
loss = get_loss(tf.zeros((32,1024),dtype=tf.int32),
tf.zeros((32,3)), tf.zeros((32,),dtype=tf.int32),
tf.zeros((32,)), tf.zeros((32,),dtype=tf.int32),
Expand Down
3 changes: 2 additions & 1 deletion models/frustum_pointnets_v2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
''' Frustum PointNets v2 Model.
'''
from __future__ import print_function

import sys
import os
Expand Down Expand Up @@ -173,7 +174,7 @@ def get_model(point_cloud, one_hot_vec, is_training, bn_decay=None):
inputs = tf.zeros((32,1024,4))
outputs = get_model(inputs, tf.ones((32,3)), tf.constant(True))
for key in outputs:
print(key, outputs[key])
print((key, outputs[key]))
loss = get_loss(tf.zeros((32,1024),dtype=tf.int32),
tf.zeros((32,3)), tf.zeros((32,),dtype=tf.int32),
tf.zeros((32,)), tf.zeros((32,),dtype=tf.int32),
Expand Down
5 changes: 3 additions & 2 deletions models/tf_ops/3d_interpolation/tf_interpolate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import tensorflow as tf
from tensorflow.python.framework import ops
import sys
Expand Down Expand Up @@ -51,8 +52,8 @@ def _three_interpolate_grad(op, grad_out):
now = time.time()
for _ in range(100):
ret = sess.run(interpolated_points)
print time.time() - now
print ret.shape, ret.dtype
print(time.time() - now)
print(ret.shape, ret.dtype)
#print ret


Expand Down
7 changes: 4 additions & 3 deletions models/tf_ops/3d_interpolation/tf_interpolate_op_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import tensorflow as tf
import numpy as np
from tf_interpolate import three_nn, three_interpolate
Expand All @@ -9,15 +10,15 @@ def test(self):
def test_grad(self):
with self.test_session():
points = tf.constant(np.random.random((1,8,16)).astype('float32'))
print points
print(points)
xyz1 = tf.constant(np.random.random((1,128,3)).astype('float32'))
xyz2 = tf.constant(np.random.random((1,8,3)).astype('float32'))
dist, idx = three_nn(xyz1, xyz2)
weight = tf.ones_like(dist)/3.0
interpolated_points = three_interpolate(points, idx, weight)
print interpolated_points
print(interpolated_points)
err = tf.test.compute_gradient_error(points, (1,8,16), interpolated_points, (1,128,16))
print err
print(err)
self.assertLess(err, 1e-4)

if __name__=='__main__':
Expand Down
3 changes: 2 additions & 1 deletion models/tf_ops/3d_interpolation/visu_interpolation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
''' Visualize part segmentation '''
from __future__ import print_function
import os
import sys
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -23,7 +24,7 @@ def fun(xyz1,xyz2,pts2):
dist = tf.maximum(dist, 1e-10)
norm = tf.reduce_sum((1.0/dist),axis=2,keep_dims=True)
norm = tf.tile(norm, [1,1,3])
print norm
print(norm)
weight = (1.0/dist) / norm
interpolated_points = three_interpolate(points, idx, weight)
with tf.Session('') as sess:
Expand Down
25 changes: 13 additions & 12 deletions models/tf_ops/grouping/test_knn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import tensorflow as tf
import numpy as np

Expand All @@ -7,34 +8,34 @@
a_val = np.random.random((2,5,3))
b_val = np.random.random((2,2,3))
for b in range(2):
print '--- ', b
print('--- ', b)
t1 = a_val[b,:,:]
t2 = b_val[b,:,:]
for i in range(2): #npoint in b
print '-- point b: ', i
print('-- point b: ', i)
for j in range(5): # npoint in a
d = np.sum((t2[i,:]-t1[j,:])**2)
print d
print(d)



a = tf.constant(a_val)
b = tf.constant(b_val)
print a.get_shape()
print(a.get_shape())
k = 3

a = tf.tile(tf.reshape(a, (2,1,5,3)), [1,2,1,1])
b = tf.tile(tf.reshape(b, (2,2,1,3)), [1,1,5,1])

dist = -tf.reduce_sum((a-b)**2, -1)
print dist
print(dist)

val, idx = tf.nn.top_k(dist, k=k)
print val, idx
print(val, idx)
sess = tf.Session()
print sess.run(a)
print sess.run(b)
print sess.run(dist)
print sess.run(val)
print sess.run(idx)
print sess.run(idx).shape
print(sess.run(a))
print(sess.run(b))
print(sess.run(dist))
print(sess.run(val))
print(sess.run(idx))
print(sess.run(idx).shape)
7 changes: 4 additions & 3 deletions models/tf_ops/grouping/tf_grouping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import tensorflow as tf
from tensorflow.python.framework import ops
import sys
Expand Down Expand Up @@ -98,8 +99,8 @@ def knn_point(k, xyz1, xyz2):
now = time.time()
for _ in range(100):
ret = sess.run(grouped_points)
print time.time() - now
print ret.shape, ret.dtype
print ret
print(time.time() - now)
print(ret.shape, ret.dtype)
print(ret)


9 changes: 5 additions & 4 deletions models/tf_ops/grouping/tf_grouping_op_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import tensorflow as tf
import numpy as np
from tf_grouping import query_ball_point, group_point
Expand All @@ -9,19 +10,19 @@ def test(self):
def test_grad(self):
with tf.device('/gpu:0'):
points = tf.constant(np.random.random((1,128,16)).astype('float32'))
print points
print(points)
xyz1 = tf.constant(np.random.random((1,128,3)).astype('float32'))
xyz2 = tf.constant(np.random.random((1,8,3)).astype('float32'))
radius = 0.3
nsample = 32
idx, pts_cnt = query_ball_point(radius, nsample, xyz1, xyz2)
grouped_points = group_point(points, idx)
print grouped_points
print(grouped_points)

with self.test_session():
print "---- Going to compute gradient error"
print("---- Going to compute gradient error")
err = tf.test.compute_gradient_error(points, (1,128,16), grouped_points, (1,8,32,16))
print err
print(err)
self.assertLess(err, 1e-4)

if __name__=='__main__':
Expand Down
7 changes: 4 additions & 3 deletions models/tf_ops/sampling/tf_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Modified by Charles R. Qi
All Rights Reserved. 2017.
'''
from __future__ import print_function
import tensorflow as tf
from tensorflow.python.framework import ops
import sys
Expand Down Expand Up @@ -79,11 +80,11 @@ def farthest_point_sample(npoint,inp):
us=(uplusv+uminusv)*0.5
vs=(uplusv-uminusv)*0.5
pt_sample=tria_sample+(trib_sample-tria_sample)*tf.expand_dims(us,-1)+(tric_sample-tria_sample)*tf.expand_dims(vs,-1)
print 'pt_sample: ', pt_sample
print('pt_sample: ', pt_sample)
reduced_sample=gather_point(pt_sample,farthest_point_sample(1024,pt_sample))
print reduced_sample
print(reduced_sample)
with tf.Session('') as sess:
ret=sess.run(reduced_sample)
print ret.shape,ret.dtype
print(ret.shape,ret.dtype)
import cPickle as pickle
pickle.dump(ret,open('1.pkl','wb'),-1)
7 changes: 4 additions & 3 deletions train/box_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Collected by Charles R. Qi
Date: September 2017
"""
from __future__ import print_function

import numpy as np
from scipy.spatial import ConvexHull
Expand Down Expand Up @@ -198,7 +199,7 @@ def plot_polys(plist,scale=500.0):
points = np.random.rand(30, 2) # 30 random points in 2-D
hull = ConvexHull(points)
# **In 2D "volume" is is area, "area" is perimeter
print('Hull area: ', hull.volume)
print(('Hull area: ', hull.volume))
for simplex in hull.simplices:
print(simplex)

Expand All @@ -213,7 +214,7 @@ def plot_polys(plist,scale=500.0):
rect2 = [(150,150),(300,300),(150,450),(0,300)]
plot_polys([rect1, rect2])
inter, area = convex_hull_intersection(rect1, rect2)
print(inter, area)
print((inter, area))
if inter is not None:
print(poly_area(np.array(inter)[:,0], np.array(inter)[:,1]))

Expand All @@ -230,4 +231,4 @@ def plot_polys(plist,scale=500.0):
rect2 = [rect2[0], rect2[3], rect2[2], rect2[1]]
plot_polys([rect1, rect2])
inter, area = convex_hull_intersection(rect1, rect2)
print(inter, area)
print((inter, area))
Loading

0 comments on commit 37f7b75

Please sign in to comment.