-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset.py
65 lines (56 loc) · 1.94 KB
/
dataset.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
65
import torch
from torch.utils.data import Dataset
class Data(Dataset):
def __init__(self, data, scene, obj, start, stop):
self.num = stop-start
self.scene_pc = self.load(f'data/{data}/scene_pc/{scene}_pc.txt')
self.pos = []
self.label = []
for i in range(start, stop):
self.pos.append(self.load_pos(f'data/{data}/pos/pos_{i}.txt'))
self.label.append(self.load_gt(f'data/{data}/gt/gt_{i}.txt'))
self.scene_pc = torch.Tensor(self.scene_pc)
self.pos = torch.Tensor(self.pos)
self.label = torch.Tensor(self.label)
# self.obj_pc = self.load(f'data/{data}/obj_pc/{obj}_pc.txt')
# self.obj_pc = torch.Tensor(self.obj_pc)
self.obj_pc = []
for i in range(start, stop):
self.obj_pc.append(
self.load(f'data/{data}/obj_pc/moved/{obj}_pc_{i}.txt'))
self.obj_pc = torch.Tensor(self.obj_pc)
def __getitem__(self, index):
data = [self.scene_pc, self.obj_pc[index], self.pos[index]]
# data = [self.scene_pc, self.obj_pc, self.pos[index]]
return data, self.label[index]
def __len__(self):
return self.num
def load(self, file):
data = []
f = open(file, 'r')
line = f.readline()
while line:
x, y = line.strip('\n').split(' ')
x, y = float(x), float(y)
data.append([x, y])
line = f.readline()
f.close()
return data
def load_pos(self, file):
f = open(file, 'r')
line = f.readline()
x, y = line.strip('\n').split(' ')
x, y = float(x), float(y)
data = [x, y]
f.close()
return data
def load_gt(self, file):
data = []
f = open(file, 'r')
line = f.readline()
while line:
gt = float(line.strip('\n'))
data.append(gt)
line = f.readline()
f.close()
return data