-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataset_modelnet.py
64 lines (51 loc) · 2.38 KB
/
dataset_modelnet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import numpy as np
from tqdm import tqdm
import pickle
from torch.utils.data import Dataset
from utils.utils_data import normalize_pc, random_scale_pc, translate_pc, so3_rotate, z_rotate
class ModelNet40(Dataset):
def __init__(self, train, use_normal=False, normalize=False, transforms=False, rotate='so3', angle=None):
super().__init__()
self.train = train
self.transforms = transforms
self.normalize = normalize
self.rotate = rotate
self.angle = angle
if train:
self.points = np.load('data/ModelNet40_normal_1024_train_points.npy')
self.labels = np.load('data/ModelNet40_normal_1024_train_label.npy')
else:
self.points = np.load('data/ModelNet40_normal_1024_test_points.npy')
self.labels = np.load('data/ModelNet40_normal_1024_test_label.npy')
if not use_normal:
self.points = self.points[:, :, :3]
print('Successfully load ModelNet40 with', self.points.shape[0], 'instances')
def __getitem__(self, idx):
pt_idxs = np.arange(0, self.points.shape[1]) # 1024
if self.train:
np.random.shuffle(pt_idxs)
current_points = self.points[idx, pt_idxs].copy()
if self.normalize:
current_points[:, :3] = normalize_pc(current_points[:, :3])
if self.train:
if self.rotate == 'so3':
current_points[:, :3] = so3_rotate(current_points[:, :3], self.angle)
elif self.rotate == 'z':
current_points[:, :3] = z_rotate(current_points[:, :3], self.angle)
if self.transforms:
current_points[:, :3] = random_scale_pc(current_points[:, :3])
current_points[:, :3] = translate_pc(current_points[:, :3])
else:
if self.rotate == 'so3':
current_points[:, :3] = so3_rotate(current_points[:, :3], self.angle)
elif self.rotate == 'z':
current_points[:, :3] = z_rotate(current_points[:, :3], self.angle)
if self.transforms:
current_points[:, :3] = random_scale_pc(current_points[:, :3])
current_points[:, :3] = translate_pc(current_points[:, :3])
normal = current_points[:, :3]
label = self.labels[idx]
return current_points, normal, label
def __len__(self):
return self.points.shape[0]