-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_loader.py
More file actions
37 lines (31 loc) · 928 Bytes
/
data_loader.py
File metadata and controls
37 lines (31 loc) · 928 Bytes
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
"""
Data loader is used to load data file into memory
with `numpy.array` format.
"""
import numpy as np
import os
import sys
import traceback
def arrays_from_file(filename):
"""
Get numpy arrays from file. Raise ValueError if file is
set in wrong format.
Args:
filename: string. Location of data file.
Returns:
Tuple of numpy.array: (point cloud coordinates, colors).
"""
try:
arrs, colors = [], []
with open(filename) as f:
for line in f:
if '#' in line:
continue
raw_items = line.split()
x, y, z, R, G, B = [x.strip(',') for x in raw_items]
arrs.append([float(x), float(y), float(z)])
colors.append([int(R), int(G), int(B)])
return (np.array(arrs, dtype=np.float32), np.array(colors, dtype=np.int32))
except:
raise ValueError('Failed load array from file. Please check'
' file: {}'.format(filename))