Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change print foo to print(foo) --> python 3 works #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/pointnet2_cls_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_sa_module_msg
from __future__ import print_function

def placeholder_inputs(batch_size, num_point):
pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
Expand Down
1 change: 1 addition & 0 deletions models/pointnet2_cls_ssg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module
from __future__ import print_function

def placeholder_inputs(batch_size, num_point):
pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
Expand Down
1 change: 1 addition & 0 deletions models/pointnet2_part_seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_fp_module
from __future__ import print_function

def placeholder_inputs(batch_size, num_point):
pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 6))
Expand Down
1 change: 1 addition & 0 deletions models/pointnet2_sem_seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import tf_util
from pointnet_util import pointnet_sa_module, pointnet_fp_module
from __future__ import print_function

def placeholder_inputs(batch_size, num_point):
pointclouds_pl = tf.placeholder(tf.float32, shape=(batch_size, num_point, 3))
Expand Down
5 changes: 3 additions & 2 deletions tf_ops/3d_interpolation/tf_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from tensorflow.python.framework import ops
import sys
import os
from __future__ import print_function
BASE_DIR = os.path.dirname(__file__)
sys.path.append(BASE_DIR)
interpolate_module=tf.load_op_library(os.path.join(BASE_DIR, 'tf_interpolate_so.so'))
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite right. When you are printing multiple values separated by a comma then you must from __future__ import print_function at the top of the import statements to get identical output in Python 2.

$ python2 -c "print 'a', 'b' ; print('a', 'b')"

a b
('a', 'b')

#print ret


Expand Down
7 changes: 4 additions & 3 deletions tf_ops/3d_interpolation/tf_interpolate_op_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tensorflow as tf
import numpy as np
from tf_interpolate import three_nn, three_interpolate
from __future__ import print_function

class GroupPointTest(tf.test.TestCase):
def test(self):
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 tf_ops/3d_interpolation/visu_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
from tf_interpolate import three_nn, three_interpolate
import tensorflow as tf
from __future__ import print_function


pts2 = np.array([[0,0,1],[1,0,0],[0,1,0],[1,1,0]]).astype('float32')
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
26 changes: 13 additions & 13 deletions tf_ops/grouping/test_knn.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import tensorflow as tf
import numpy as np

from __future__ import print_function
np.random.seed(0)


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)
15 changes: 8 additions & 7 deletions tf_ops/grouping/tf_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from tensorflow.python.framework import ops
import sys
import os
from __future__ import print_function
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(BASE_DIR)
grouping_module=tf.load_op_library(os.path.join(BASE_DIR, 'tf_grouping_so.so'))
Expand Down Expand Up @@ -59,16 +60,16 @@ def knn_point(k, xyz1, xyz2):
n = xyz1.get_shape()[1].value
c = xyz1.get_shape()[2].value
m = xyz2.get_shape()[1].value
print b, n, c, m
print xyz1, (b,1,n,c)
print(b, n, c, m)
print(xyz1, (b,1,n,c))
xyz1 = tf.tile(tf.reshape(xyz1, (b,1,n,c)), [1,m,1,1])
xyz2 = tf.tile(tf.reshape(xyz2, (b,m,1,c)), [1,1,n,1])
dist = tf.reduce_sum((xyz1-xyz2)**2, -1)
print dist, k
print(dist, k)
outi, out = select_top_k(k, dist)
idx = tf.slice(outi, [0,0,0], [-1,-1,k])
val = tf.slice(out, [0,0,0], [-1,-1,k])
print idx, val
print(idx, val)
#val, idx = tf.nn.top_k(-dist, k=k) # ONLY SUPPORT CPU
return val, idx

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 tf_ops/grouping/tf_grouping_op_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tensorflow as tf
import numpy as np
from tf_grouping import query_ball_point, group_point
from __future__ import print_function

class GroupPointTest(tf.test.TestCase):
def test(self):
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 tf_ops/sampling/tf_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from tensorflow.python.framework import ops
import sys
import os
from __future__ import print_function
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(BASE_DIR)
sampling_module=tf.load_op_library(os.path.join(BASE_DIR, 'tf_sampling_so.so'))
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)