MCPcopy Create free account
hub / github.com/d62lu/3DCTN / ModelNetDataLoader

Class ModelNetDataLoader

data_utils/ModelNetDataLoader.py:49–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48
49class ModelNetDataLoader(Dataset):
50 def __init__(self, root, args, split='train', process_data=False):
51 self.root = root
52 self.npoints = args.num_point
53 self.process_data = process_data
54 self.uniform = args.use_uniform_sample
55 self.use_normals = args.use_normals
56 self.num_category = args.num_category
57
58 if self.num_category == 10:
59 self.catfile = os.path.join(self.root, 'modelnet10_shape_names.txt')
60 else:
61 self.catfile = os.path.join(self.root, 'modelnet40_shape_names.txt')
62
63 self.cat = [line.rstrip() for line in open(self.catfile)]
64 self.classes = dict(zip(self.cat, range(len(self.cat))))
65
66 shape_ids = {}
67 if self.num_category == 10:
68 shape_ids['train'] = [line.rstrip() for line in open(os.path.join(self.root, 'modelnet10_train.txt'))]
69 shape_ids['test'] = [line.rstrip() for line in open(os.path.join(self.root, 'modelnet10_test.txt'))]
70 else:
71 shape_ids['train'] = [line.rstrip() for line in open(os.path.join(self.root, 'modelnet40_train.txt'))]
72 shape_ids['test'] = [line.rstrip() for line in open(os.path.join(self.root, 'modelnet40_test.txt'))]
73
74 assert (split == 'train' or split == 'test')
75 shape_names = ['_'.join(x.split('_')[0:-1]) for x in shape_ids[split]]
76 self.datapath = [(shape_names[i], os.path.join(self.root, shape_names[i], shape_ids[split][i]) + '.txt') for i
77 in range(len(shape_ids[split]))]
78 print('The size of %s data is %d' % (split, len(self.datapath)))
79
80 if self.uniform:
81 self.save_path = os.path.join(root, 'modelnet%d_%s_%dpts_fps.dat' % (self.num_category, split, self.npoints))
82 else:
83 self.save_path = os.path.join(root, 'modelnet%d_%s_%dpts.dat' % (self.num_category, split, self.npoints))
84
85 if self.process_data:
86 if not os.path.exists(self.save_path):
87 print('Processing data %s (only running in the first time)...' % self.save_path)
88 self.list_of_points = [None] * len(self.datapath)
89 self.list_of_labels = [None] * len(self.datapath)
90
91 for index in tqdm(range(len(self.datapath)), total=len(self.datapath)):
92 fn = self.datapath[index]
93 cls = self.classes[self.datapath[index][0]]
94 cls = np.array([cls]).astype(np.int32)
95 point_set = np.loadtxt(fn[1], delimiter=',').astype(np.float32)
96
97 if self.uniform:
98 point_set = farthest_point_sample(point_set, self.npoints)
99 else:
100 point_set = point_set[0:self.npoints, :]
101
102 self.list_of_points[index] = point_set
103 self.list_of_labels[index] = cls
104
105 with open(self.save_path, 'wb') as f:
106 pickle.dump([self.list_of_points, self.list_of_labels], f)

Callers 3

mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected