From 83071aca0002cc0b18b1d138e26d066cead0d087 Mon Sep 17 00:00:00 2001 From: Timo F Date: Fri, 8 Sep 2017 14:17:47 +0200 Subject: [PATCH 1/2] change print foo to print(foo) --> python 3 works --- tf_ops/3d_interpolation/tf_interpolate.py | 4 ++-- tf_ops/3d_interpolation/tf_interpolate_op_test.py | 6 +++--- tf_ops/3d_interpolation/visu_interpolation.py | 2 +- tf_ops/grouping/tf_grouping.py | 14 +++++++------- tf_ops/grouping/tf_grouping_op_test.py | 8 ++++---- tf_ops/sampling/tf_sampling.py | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tf_ops/3d_interpolation/tf_interpolate.py b/tf_ops/3d_interpolation/tf_interpolate.py index 6f84da02..aa0b21f6 100644 --- a/tf_ops/3d_interpolation/tf_interpolate.py +++ b/tf_ops/3d_interpolation/tf_interpolate.py @@ -51,8 +51,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 diff --git a/tf_ops/3d_interpolation/tf_interpolate_op_test.py b/tf_ops/3d_interpolation/tf_interpolate_op_test.py index b1c244f8..1187c44f 100644 --- a/tf_ops/3d_interpolation/tf_interpolate_op_test.py +++ b/tf_ops/3d_interpolation/tf_interpolate_op_test.py @@ -9,15 +9,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__': diff --git a/tf_ops/3d_interpolation/visu_interpolation.py b/tf_ops/3d_interpolation/visu_interpolation.py index 5b5836e0..4bb25892 100644 --- a/tf_ops/3d_interpolation/visu_interpolation.py +++ b/tf_ops/3d_interpolation/visu_interpolation.py @@ -23,7 +23,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: diff --git a/tf_ops/grouping/tf_grouping.py b/tf_ops/grouping/tf_grouping.py index 5b59d7de..9bd039fe 100644 --- a/tf_ops/grouping/tf_grouping.py +++ b/tf_ops/grouping/tf_grouping.py @@ -59,16 +59,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 @@ -98,8 +98,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) diff --git a/tf_ops/grouping/tf_grouping_op_test.py b/tf_ops/grouping/tf_grouping_op_test.py index 4f30a3eb..6656d86c 100644 --- a/tf_ops/grouping/tf_grouping_op_test.py +++ b/tf_ops/grouping/tf_grouping_op_test.py @@ -9,19 +9,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__': diff --git a/tf_ops/sampling/tf_sampling.py b/tf_ops/sampling/tf_sampling.py index 9a429974..3d7dfad0 100644 --- a/tf_ops/sampling/tf_sampling.py +++ b/tf_ops/sampling/tf_sampling.py @@ -79,11 +79,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) From c10b48c89e9ca05d370183085013fce5e4efab40 Mon Sep 17 00:00:00 2001 From: Timo F Date: Fri, 2 Mar 2018 14:02:51 +0100 Subject: [PATCH 2/2] further 2+3 print function changes --- models/pointnet2_cls_msg.py | 1 + models/pointnet2_cls_ssg.py | 1 + models/pointnet2_part_seg.py | 1 + models/pointnet2_sem_seg.py | 1 + tf_ops/3d_interpolation/tf_interpolate.py | 1 + .../tf_interpolate_op_test.py | 1 + tf_ops/3d_interpolation/visu_interpolation.py | 1 + tf_ops/grouping/test_knn.py | 26 +++++++++---------- tf_ops/grouping/tf_grouping.py | 1 + tf_ops/grouping/tf_grouping_op_test.py | 1 + tf_ops/sampling/tf_sampling.py | 1 + 11 files changed, 23 insertions(+), 13 deletions(-) diff --git a/models/pointnet2_cls_msg.py b/models/pointnet2_cls_msg.py index cc3630ae..e6c8404f 100644 --- a/models/pointnet2_cls_msg.py +++ b/models/pointnet2_cls_msg.py @@ -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)) diff --git a/models/pointnet2_cls_ssg.py b/models/pointnet2_cls_ssg.py index 01fd1730..f8b688a2 100644 --- a/models/pointnet2_cls_ssg.py +++ b/models/pointnet2_cls_ssg.py @@ -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)) diff --git a/models/pointnet2_part_seg.py b/models/pointnet2_part_seg.py index beb83180..912c6f7e 100644 --- a/models/pointnet2_part_seg.py +++ b/models/pointnet2_part_seg.py @@ -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)) diff --git a/models/pointnet2_sem_seg.py b/models/pointnet2_sem_seg.py index 3e363109..19a7a064 100644 --- a/models/pointnet2_sem_seg.py +++ b/models/pointnet2_sem_seg.py @@ -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)) diff --git a/tf_ops/3d_interpolation/tf_interpolate.py b/tf_ops/3d_interpolation/tf_interpolate.py index aa0b21f6..1883004d 100644 --- a/tf_ops/3d_interpolation/tf_interpolate.py +++ b/tf_ops/3d_interpolation/tf_interpolate.py @@ -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')) diff --git a/tf_ops/3d_interpolation/tf_interpolate_op_test.py b/tf_ops/3d_interpolation/tf_interpolate_op_test.py index 1187c44f..9ac54a3b 100644 --- a/tf_ops/3d_interpolation/tf_interpolate_op_test.py +++ b/tf_ops/3d_interpolation/tf_interpolate_op_test.py @@ -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): diff --git a/tf_ops/3d_interpolation/visu_interpolation.py b/tf_ops/3d_interpolation/visu_interpolation.py index 4bb25892..0d4c8f19 100644 --- a/tf_ops/3d_interpolation/visu_interpolation.py +++ b/tf_ops/3d_interpolation/visu_interpolation.py @@ -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') diff --git a/tf_ops/grouping/test_knn.py b/tf_ops/grouping/test_knn.py index 0a15e39c..e5286280 100644 --- a/tf_ops/grouping/test_knn.py +++ b/tf_ops/grouping/test_knn.py @@ -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) diff --git a/tf_ops/grouping/tf_grouping.py b/tf_ops/grouping/tf_grouping.py index 9bd039fe..a33188d7 100644 --- a/tf_ops/grouping/tf_grouping.py +++ b/tf_ops/grouping/tf_grouping.py @@ -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')) diff --git a/tf_ops/grouping/tf_grouping_op_test.py b/tf_ops/grouping/tf_grouping_op_test.py index 6656d86c..6880a8a7 100644 --- a/tf_ops/grouping/tf_grouping_op_test.py +++ b/tf_ops/grouping/tf_grouping_op_test.py @@ -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): diff --git a/tf_ops/sampling/tf_sampling.py b/tf_ops/sampling/tf_sampling.py index 3d7dfad0..e02b495b 100644 --- a/tf_ops/sampling/tf_sampling.py +++ b/tf_ops/sampling/tf_sampling.py @@ -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'))