Skip to content

Commit 05f2da9

Browse files
committed
Delete unused code and re-format.
1 parent f6eeca1 commit 05f2da9

File tree

7 files changed

+216
-215
lines changed

7 files changed

+216
-215
lines changed

datasets.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
from __future__ import print_function
22
import torch.utils.data as data
3-
from PIL import Image
43
import os
54
import os.path
6-
import errno
75
import torch
8-
import json
9-
import codecs
106
import numpy as np
11-
import sys
12-
import torchvision.transforms as transforms
13-
import argparse
14-
import json
15-
167

178
class PartDataset(data.Dataset):
18-
def __init__(self, root, npoints = 2500, classification = False, class_choice = None, train = True):
9+
def __init__(self,
10+
root,
11+
npoints=2500,
12+
classification=False,
13+
class_choice=None,
14+
train=True):
1915
self.npoints = npoints
2016
self.root = root
2117
self.catfile = os.path.join(self.root, 'synsetoffset2category.txt')
@@ -28,8 +24,8 @@ def __init__(self, root, npoints = 2500, classification = False, class_choice =
2824
ls = line.strip().split()
2925
self.cat[ls[0]] = ls[1]
3026
#print(self.cat)
31-
if not class_choice is None:
32-
self.cat = {k:v for k,v in self.cat.items() if k in class_choice}
27+
if not class_choice is None:
28+
self.cat = {k: v for k, v in self.cat.items() if k in class_choice}
3329

3430
self.meta = {}
3531
for item in self.cat:
@@ -59,7 +55,7 @@ def __init__(self, root, npoints = 2500, classification = False, class_choice =
5955
print(self.classes)
6056
self.num_seg_classes = 0
6157
if not self.classification:
62-
for i in range(len(self.datapath)//50):
58+
for i in range(len(self.datapath) // 50):
6359
l = len(np.unique(np.loadtxt(self.datapath[i][-1]).astype(np.uint8)))
6460
if l > self.num_seg_classes:
6561
self.num_seg_classes = l

pointnet.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
from __future__ import print_function
2-
import argparse
3-
import os
4-
import random
52
import torch
63
import torch.nn as nn
74
import torch.nn.parallel
8-
import torch.backends.cudnn as cudnn
9-
import torch.optim as optim
105
import torch.utils.data
11-
import torchvision.transforms as transforms
12-
import torchvision.utils as vutils
136
from torch.autograd import Variable
14-
from PIL import Image
157
import numpy as np
16-
import matplotlib.pyplot as plt
17-
import pdb
188
import torch.nn.functional as F
199

2010

@@ -67,13 +57,14 @@ def __init__(self, global_feat = True):
6757
self.bn2 = nn.BatchNorm1d(128)
6858
self.bn3 = nn.BatchNorm1d(1024)
6959
self.global_feat = global_feat
60+
61+
7062
def forward(self, x):
71-
batchsize = x.size()[0]
7263
n_pts = x.size()[2]
7364
trans = self.stn(x)
74-
x = x.transpose(2,1)
65+
x = x.transpose(2, 1)
7566
x = torch.bmm(x, trans)
76-
x = x.transpose(2,1)
67+
x = x.transpose(2, 1)
7768
x = F.relu(self.bn1(self.conv1(x)))
7869
pointfeat = x
7970
x = F.relu(self.bn2(self.conv2(x)))
@@ -96,6 +87,7 @@ def __init__(self, k = 2):
9687
self.bn1 = nn.BatchNorm1d(512)
9788
self.bn2 = nn.BatchNorm1d(256)
9889
self.relu = nn.ReLU()
90+
9991
def forward(self, x):
10092
x, trans = self.feat(x)
10193
x = F.relu(self.bn1(self.fc1(x)))

show3d_balls.py

Lines changed: 100 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,142 +2,148 @@
22
import ctypes as ct
33
import cv2
44
import sys
5-
showsz=800
6-
mousex,mousey=0.5,0.5
7-
zoom=1.0
8-
changed=True
5+
showsz = 800
6+
mousex, mousey = 0.5, 0.5
7+
zoom = 1.0
8+
changed = True
9+
910
def onmouse(*args):
10-
global mousex,mousey,changed
11-
y=args[1]
12-
x=args[2]
13-
mousex=x/float(showsz)
14-
mousey=y/float(showsz)
15-
changed=True
11+
global mousex, mousey, changed
12+
y = args[1]
13+
x = args[2]
14+
mousex = x / float(showsz)
15+
mousey = y / float(showsz)
16+
changed = True
17+
1618
cv2.namedWindow('show3d')
17-
cv2.moveWindow('show3d',0,0)
18-
cv2.setMouseCallback('show3d',onmouse)
19+
cv2.moveWindow('show3d', 0, 0)
20+
cv2.setMouseCallback('show3d', onmouse)
1921

20-
dll=np.ctypeslib.load_library('render_balls_so','.')
22+
dll = np.ctypeslib.load_library('render_balls_so', '.')
2123

22-
def showpoints(xyz,c_gt=None, c_pred = None ,waittime=0,showrot=False,magnifyBlue=0,freezerot=False,background=(0,0,0),normalizecolor=True,ballradius=10):
23-
global showsz,mousex,mousey,zoom,changed
24+
def showpoints(xyz,c_gt=None, c_pred = None, waittime=0,
25+
showrot=False, magnifyBlue=0, freezerot=False, background=(0,0,0),
26+
normalizecolor=True, ballradius=10):
27+
global showsz, mousex, mousey, zoom, changed
2428
xyz=xyz-xyz.mean(axis=0)
2529
radius=((xyz**2).sum(axis=-1)**0.5).max()
2630
xyz/=(radius*2.2)/showsz
2731
if c_gt is None:
28-
c0=np.zeros((len(xyz),),dtype='float32')+255
29-
c1=np.zeros((len(xyz),),dtype='float32')+255
30-
c2=np.zeros((len(xyz),),dtype='float32')+255
32+
c0 = np.zeros((len(xyz), ), dtype='float32') + 255
33+
c1 = np.zeros((len(xyz), ), dtype='float32') + 255
34+
c2 = np.zeros((len(xyz), ), dtype='float32') + 255
3135
else:
32-
c0=c_gt[:,0]
33-
c1=c_gt[:,1]
34-
c2=c_gt[:,2]
36+
c0 = c_gt[:, 0]
37+
c1 = c_gt[:, 1]
38+
c2 = c_gt[:, 2]
3539

3640

3741
if normalizecolor:
38-
c0/=(c0.max()+1e-14)/255.0
39-
c1/=(c1.max()+1e-14)/255.0
40-
c2/=(c2.max()+1e-14)/255.0
42+
c0 /= (c0.max() + 1e-14) / 255.0
43+
c1 /= (c1.max() + 1e-14) / 255.0
44+
c2 /= (c2.max() + 1e-14) / 255.0
4145

4246

43-
c0=np.require(c0,'float32','C')
44-
c1=np.require(c1,'float32','C')
45-
c2=np.require(c2,'float32','C')
47+
c0 = np.require(c0, 'float32', 'C')
48+
c1 = np.require(c1, 'float32', 'C')
49+
c2 = np.require(c2, 'float32', 'C')
4650

47-
show=np.zeros((showsz,showsz,3),dtype='uint8')
51+
show = np.zeros((showsz, showsz, 3), dtype='uint8')
4852
def render():
4953
rotmat=np.eye(3)
5054
if not freezerot:
5155
xangle=(mousey-0.5)*np.pi*1.2
5256
else:
5357
xangle=0
54-
rotmat=rotmat.dot(np.array([
55-
[1.0,0.0,0.0],
56-
[0.0,np.cos(xangle),-np.sin(xangle)],
57-
[0.0,np.sin(xangle),np.cos(xangle)],
58+
rotmat = rotmat.dot(
59+
np.array([
60+
[1.0, 0.0, 0.0],
61+
[0.0, np.cos(xangle), -np.sin(xangle)],
62+
[0.0, np.sin(xangle), np.cos(xangle)],
5863
]))
5964
if not freezerot:
60-
yangle=(mousex-0.5)*np.pi*1.2
65+
yangle = (mousex - 0.5) * np.pi * 1.2
6166
else:
62-
yangle=0
63-
rotmat=rotmat.dot(np.array([
64-
[np.cos(yangle),0.0,-np.sin(yangle)],
65-
[0.0,1.0,0.0],
66-
[np.sin(yangle),0.0,np.cos(yangle)],
67+
yangle = 0
68+
rotmat = rotmat.dot(
69+
np.array([
70+
[np.cos(yangle), 0.0, -np.sin(yangle)],
71+
[0.0, 1.0, 0.0],
72+
[np.sin(yangle), 0.0, np.cos(yangle)],
6773
]))
68-
rotmat*=zoom
69-
nxyz=xyz.dot(rotmat)+[showsz/2,showsz/2,0]
74+
rotmat *= zoom
75+
nxyz = xyz.dot(rotmat) + [showsz / 2, showsz / 2, 0]
7076

71-
ixyz=nxyz.astype('int32')
72-
show[:]=background
77+
ixyz = nxyz.astype('int32')
78+
show[:] = background
7379
dll.render_ball(
74-
ct.c_int(show.shape[0]),
75-
ct.c_int(show.shape[1]),
76-
show.ctypes.data_as(ct.c_void_p),
77-
ct.c_int(ixyz.shape[0]),
78-
ixyz.ctypes.data_as(ct.c_void_p),
79-
c0.ctypes.data_as(ct.c_void_p),
80-
c1.ctypes.data_as(ct.c_void_p),
81-
c2.ctypes.data_as(ct.c_void_p),
82-
ct.c_int(ballradius)
83-
)
80+
ct.c_int(show.shape[0]), ct.c_int(show.shape[1]),
81+
show.ctypes.data_as(ct.c_void_p), ct.c_int(ixyz.shape[0]),
82+
ixyz.ctypes.data_as(ct.c_void_p), c0.ctypes.data_as(ct.c_void_p),
83+
c1.ctypes.data_as(ct.c_void_p), c2.ctypes.data_as(ct.c_void_p),
84+
ct.c_int(ballradius))
8485

85-
if magnifyBlue>0:
86-
show[:,:,0]=np.maximum(show[:,:,0],np.roll(show[:,:,0],1,axis=0))
87-
if magnifyBlue>=2:
88-
show[:,:,0]=np.maximum(show[:,:,0],np.roll(show[:,:,0],-1,axis=0))
89-
show[:,:,0]=np.maximum(show[:,:,0],np.roll(show[:,:,0],1,axis=1))
90-
if magnifyBlue>=2:
91-
show[:,:,0]=np.maximum(show[:,:,0],np.roll(show[:,:,0],-1,axis=1))
86+
if magnifyBlue > 0:
87+
show[:, :, 0] = np.maximum(show[:, :, 0], np.roll(
88+
show[:, :, 0], 1, axis=0))
89+
if magnifyBlue >= 2:
90+
show[:, :, 0] = np.maximum(show[:, :, 0],
91+
np.roll(show[:, :, 0], -1, axis=0))
92+
show[:, :, 0] = np.maximum(show[:, :, 0], np.roll(
93+
show[:, :, 0], 1, axis=1))
94+
if magnifyBlue >= 2:
95+
show[:, :, 0] = np.maximum(show[:, :, 0],
96+
np.roll(show[:, :, 0], -1, axis=1))
9297
if showrot:
93-
cv2.putText(show,'xangle %d'%(int(xangle/np.pi*180)),(30,showsz-30),0,0.5,cv2.cv.CV_RGB(255,0,0))
94-
cv2.putText(show,'yangle %d'%(int(yangle/np.pi*180)),(30,showsz-50),0,0.5,cv2.cv.CV_RGB(255,0,0))
95-
cv2.putText(show,'zoom %d%%'%(int(zoom*100)),(30,showsz-70),0,0.5,cv2.cv.CV_RGB(255,0,0))
96-
changed=True
98+
cv2.putText(show, 'xangle %d' % (int(xangle / np.pi * 180)),
99+
(30, showsz - 30), 0, 0.5, cv2.cv.CV_RGB(255, 0, 0))
100+
cv2.putText(show, 'yangle %d' % (int(yangle / np.pi * 180)),
101+
(30, showsz - 50), 0, 0.5, cv2.cv.CV_RGB(255, 0, 0))
102+
cv2.putText(show, 'zoom %d%%' % (int(zoom * 100)), (30, showsz - 70), 0,
103+
0.5, cv2.cv.CV_RGB(255, 0, 0))
104+
changed = True
97105
while True:
98106
if changed:
99107
render()
100-
changed=False
101-
cv2.imshow('show3d',show)
102-
if waittime==0:
103-
cmd=cv2.waitKey(10)%256
108+
changed = False
109+
cv2.imshow('show3d', show)
110+
if waittime == 0:
111+
cmd = cv2.waitKey(10) % 256
104112
else:
105-
cmd=cv2.waitKey(waittime)%256
106-
if cmd==ord('q'):
113+
cmd = cv2.waitKey(waittime) % 256
114+
if cmd == ord('q'):
107115
break
108-
elif cmd==ord('Q'):
116+
elif cmd == ord('Q'):
109117
sys.exit(0)
110118

111-
if cmd==ord('t') or cmd == ord('p'):
119+
if cmd == ord('t') or cmd == ord('p'):
112120
if cmd == ord('t'):
113121
if c_gt is None:
114-
c0=np.zeros((len(xyz),),dtype='float32')+255
115-
c1=np.zeros((len(xyz),),dtype='float32')+255
116-
c2=np.zeros((len(xyz),),dtype='float32')+255
122+
c0 = np.zeros((len(xyz), ), dtype='float32') + 255
123+
c1 = np.zeros((len(xyz), ), dtype='float32') + 255
124+
c2 = np.zeros((len(xyz), ), dtype='float32') + 255
117125
else:
118-
c0=c_gt[:,0]
119-
c1=c_gt[:,1]
120-
c2=c_gt[:,2]
126+
c0 = c_gt[:, 0]
127+
c1 = c_gt[:, 1]
128+
c2 = c_gt[:, 2]
121129
else:
122130
if c_pred is None:
123-
c0=np.zeros((len(xyz),),dtype='float32')+255
124-
c1=np.zeros((len(xyz),),dtype='float32')+255
125-
c2=np.zeros((len(xyz),),dtype='float32')+255
131+
c0 = np.zeros((len(xyz), ), dtype='float32') + 255
132+
c1 = np.zeros((len(xyz), ), dtype='float32') + 255
133+
c2 = np.zeros((len(xyz), ), dtype='float32') + 255
126134
else:
127-
c0=c_pred[:,0]
128-
c1=c_pred[:,1]
129-
c2=c_pred[:,2]
135+
c0 = c_pred[:, 0]
136+
c1 = c_pred[:, 1]
137+
c2 = c_pred[:, 2]
130138
if normalizecolor:
131-
c0/=(c0.max()+1e-14)/255.0
132-
c1/=(c1.max()+1e-14)/255.0
133-
c2/=(c2.max()+1e-14)/255.0
134-
c0=np.require(c0,'float32','C')
135-
c1=np.require(c1,'float32','C')
136-
c2=np.require(c2,'float32','C')
139+
c0 /= (c0.max() + 1e-14) / 255.0
140+
c1 /= (c1.max() + 1e-14) / 255.0
141+
c2 /= (c2.max() + 1e-14) / 255.0
142+
c0 = np.require(c0, 'float32', 'C')
143+
c1 = np.require(c1, 'float32', 'C')
144+
c2 = np.require(c2, 'float32', 'C')
137145
changed = True
138146

139-
140-
141147
if cmd==ord('n'):
142148
zoom*=1.1
143149
changed=True
@@ -152,7 +158,7 @@ def render():
152158
if waittime!=0:
153159
break
154160
return cmd
155-
if __name__=='__main__':
156-
np.random.seed(100)
157-
showpoints(np.random.randn(2500,3))
158161

162+
if __name__ == '__main__':
163+
np.random.seed(100)
164+
showpoints(np.random.randn(2500, 3))

show_cls.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
from __future__ import print_function
22
import argparse
3-
import os
4-
import random
5-
import numpy as np
63
import torch
7-
import torch.nn as nn
84
import torch.nn.parallel
9-
import torch.backends.cudnn as cudnn
10-
import torch.optim as optim
115
import torch.utils.data
12-
import torchvision.datasets as dset
13-
import torchvision.transforms as transforms
14-
import torchvision.utils as vutils
156
from torch.autograd import Variable
167
from datasets import PartDataset
178
from pointnet import PointNetCls
189
import torch.nn.functional as F
19-
import matplotlib.pyplot as plt
2010

2111

2212
#showpoints(np.random.randn(2500,3), c1 = np.random.uniform(0,1,size = (2500)))
@@ -28,11 +18,16 @@
2818

2919

3020
opt = parser.parse_args()
31-
print (opt)
21+
print(opt)
3222

33-
test_dataset = PartDataset(root = 'shapenetcore_partanno_segmentation_benchmark_v0' , train = False, classification = True, npoints = opt.num_points)
23+
test_dataset = PartDataset(
24+
root='shapenetcore_partanno_segmentation_benchmark_v0',
25+
train=False,
26+
classification=True,
27+
npoints=opt.num_points)
3428

35-
testdataloader = torch.utils.data.DataLoader(test_dataset, batch_size=32, shuffle = True)
29+
testdataloader = torch.utils.data.DataLoader(
30+
test_dataset, batch_size=32, shuffle=True)
3631

3732
classifier = PointNetCls(k=len(test_dataset.classes))
3833
classifier.cuda()

0 commit comments

Comments
 (0)