| 14 | return pc |
| 15 | |
| 16 | class PartNormalDataset(Dataset): |
| 17 | def __init__(self,root = './data/shapenetcore_partanno_segmentation_benchmark_v0_normal', npoints=2500, split='train', class_choice=None, normal_channel=False): |
| 18 | self.npoints = npoints |
| 19 | self.root = root |
| 20 | self.catfile = os.path.join(self.root, 'synsetoffset2category.txt') |
| 21 | self.cat = {} |
| 22 | self.normal_channel = normal_channel |
| 23 | |
| 24 | |
| 25 | with open(self.catfile, 'r') as f: |
| 26 | for line in f: |
| 27 | ls = line.strip().split() |
| 28 | self.cat[ls[0]] = ls[1] |
| 29 | self.cat = {k: v for k, v in self.cat.items()} |
| 30 | self.classes_original = dict(zip(self.cat, range(len(self.cat)))) |
| 31 | |
| 32 | if not class_choice is None: |
| 33 | self.cat = {k:v for k,v in self.cat.items() if k in class_choice} |
| 34 | # print(self.cat) |
| 35 | |
| 36 | self.meta = {} |
| 37 | with open(os.path.join(self.root, 'train_test_split', 'shuffled_train_file_list.json'), 'r') as f: |
| 38 | train_ids = set([str(d.split('/')[2]) for d in json.load(f)]) |
| 39 | with open(os.path.join(self.root, 'train_test_split', 'shuffled_val_file_list.json'), 'r') as f: |
| 40 | val_ids = set([str(d.split('/')[2]) for d in json.load(f)]) |
| 41 | with open(os.path.join(self.root, 'train_test_split', 'shuffled_test_file_list.json'), 'r') as f: |
| 42 | test_ids = set([str(d.split('/')[2]) for d in json.load(f)]) |
| 43 | for item in self.cat: |
| 44 | # print('category', item) |
| 45 | self.meta[item] = [] |
| 46 | dir_point = os.path.join(self.root, self.cat[item]) |
| 47 | fns = sorted(os.listdir(dir_point)) |
| 48 | # print(fns[0][0:-4]) |
| 49 | if split == 'trainval': |
| 50 | fns = [fn for fn in fns if ((fn[0:-4] in train_ids) or (fn[0:-4] in val_ids))] |
| 51 | elif split == 'train': |
| 52 | fns = [fn for fn in fns if fn[0:-4] in train_ids] |
| 53 | elif split == 'val': |
| 54 | fns = [fn for fn in fns if fn[0:-4] in val_ids] |
| 55 | elif split == 'test': |
| 56 | fns = [fn for fn in fns if fn[0:-4] in test_ids] |
| 57 | else: |
| 58 | print('Unknown split: %s. Exiting..' % (split)) |
| 59 | exit(-1) |
| 60 | |
| 61 | # print(os.path.basename(fns)) |
| 62 | for fn in fns: |
| 63 | token = (os.path.splitext(os.path.basename(fn))[0]) |
| 64 | self.meta[item].append(os.path.join(dir_point, token + '.txt')) |
| 65 | |
| 66 | self.datapath = [] |
| 67 | for item in self.cat: |
| 68 | for fn in self.meta[item]: |
| 69 | self.datapath.append((item, fn)) |
| 70 | |
| 71 | self.classes = {} |
| 72 | for i in self.cat.keys(): |
| 73 | self.classes[i] = self.classes_original[i] |