Skip to content

Commit 702a29b

Browse files
authored
dataset script and files (#1)
1 parent d726e96 commit 702a29b

File tree

6 files changed

+150
-3
lines changed

6 files changed

+150
-3
lines changed

appimage/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
set( appdir "${CMAKE_CURRENT_BINARY_DIR}/AppDir" )
33
file( GLOB_RECURSE asr_model_files ${PROJECT_SOURCE_DIR}/models/v*/model*.pt )
4+
file( GLOB_RECURSE dataset_attribution_files ${PROJECT_SOURCE_DIR}/datasets/*/*_attribution.txt )
45
list( APPEND asr_model_files dummy_resource_file )
56

67
find_program(linuxdeploy_binary linuxdeploy-x86_64.AppImage )
@@ -9,9 +10,11 @@ message( FATAL_ERROR "Building the appimage requires 'linuxdeploy-x86_64.AppImag
910
endif()
1011

1112
add_custom_target( appimage
13+
COMMAND ${CMAKE_COMMAND} -E rm -r "${appdir}"
1214
COMMAND ${CMAKE_COMMAND} -E touch dummy_resource_file
1315
COMMAND ${CMAKE_COMMAND} -E make_directory "${appdir}/usr/lib/asr_resources"
1416
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${asr_model_files} "${appdir}/usr/lib/asr_resources"
17+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dataset_attribution_files} "${appdir}/usr/lib/asr_resources"
1518
COMMAND LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../_deps/libtorch-src/lib VERSION=${PROJECT_VERSION} ${linuxdeploy_binary} --create-desktop-file --appdir "${appdir}" -e $<TARGET_FILE:asrtool> -i ${CMAKE_CURRENT_SOURCE_DIR}/asrtool.png -o appimage
1619
DEPENDS asrtool
1720
)

cmake/external_deps.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ endif()
6363

6464
FetchContent_Declare(
6565
libtorch
66-
URL https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.8.1%2Bcpu.zip
66+
URL https://download.pytorch.org/libtorch/lts/1.8/cpu/libtorch-shared-with-deps-1.8.2%2Bcpu.zip
6767
)
6868
FetchContent_GetProperties(libtorch)
6969
if(NOT libtorch_POPULATED)
@@ -78,7 +78,7 @@ ExternalProject_Add(
7878
ext_open3d
7979
PREFIX open3d
8080
GIT_REPOSITORY https://github.com/isl-org/Open3D.git
81-
GIT_TAG master
81+
GIT_TAG v0.14.1
8282
GIT_SHALLOW YES
8383
UPDATE_COMMAND ""
8484
CMAKE_ARGS

datasets/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def write_compressed_msgpack(data, output_path):
2424

2525
compressor = zstd.ZstdCompressor(level=22)
2626
with open(output_path, 'wb') as f:
27-
print('writing', outfilepath)
27+
print('writing', output_path)
2828
f.write(compressor.compress(msgpack.packb(data, use_bin_type=True)))
2929
```
3030

datasets/create_t10k_msgpacks.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
5+
import open3d as o3d
6+
import numpy as np
7+
from glob import glob
8+
import argparse
9+
import zstandard as zstd
10+
import msgpack
11+
import msgpack_numpy
12+
msgpack_numpy.patch()
13+
14+
from multiprocessing import Pool
15+
16+
def write_compressed_msgpack(data, path, level=22, threads=0):
17+
compressor = zstd.ZstdCompressor(level=level, threads=threads)
18+
with open(path, 'wb') as f:
19+
print('writing', path)
20+
f.write(compressor.compress(msgpack.packb(data, use_bin_type=True)))
21+
22+
23+
def read_compressed_msgpack(path, decompressor=None):
24+
if decompressor is None:
25+
decompressor = zstd.ZstdDecompressor()
26+
with open(path, 'rb') as f:
27+
data = msgpack.unpackb(decompressor.decompress(f.read()), raw=False)
28+
return data
29+
30+
31+
def select_good_meshes(info_dict, data_dir):
32+
# select only good meshes
33+
raw_meshes_dir = os.path.join(data_dir,'raw_meshes')
34+
selected_meshes = []
35+
attribution = []
36+
selection = {
37+
'Closed': 'TRUE',
38+
'Single Component': 'TRUE',
39+
'No duplicated faces': 'TRUE',
40+
'No degenerate faces': 'TRUE',
41+
'Vertex manifold': 'TRUE',
42+
'oriented': '1',
43+
'solid': '1',
44+
}
45+
licenses = (
46+
'Creative Commons - Attribution - Share Alike',
47+
'Creative Commons - Attribution',
48+
'Creative Commons - Public Domain Dedication',
49+
'Public Domain'
50+
)
51+
52+
keys = sorted(info_dict.keys())
53+
# remove bad file ids
54+
for bas_id in ('112965',):
55+
keys.remove(bas_id)
56+
57+
for key in keys:
58+
info = info_dict[key]
59+
selected = True
60+
for sel_key, sel_val in selection.items():
61+
if info[sel_key] != sel_val:
62+
selected = False
63+
break;
64+
if selected and info['License'] in licenses:
65+
attribution.append('"{}"({}) by {} is licensed under {}'.format(info['title'].strip(), info['Thing ID'], info['author'], info['License']))
66+
selected_meshes.append(glob(os.path.join(raw_meshes_dir,key+'.*'))[0])
67+
68+
return selected_meshes, attribution
69+
70+
71+
def create_data(mesh_paths, output_path):
72+
data = []
73+
for path in mesh_paths:
74+
try:
75+
mesh = o3d.io.read_triangle_mesh( path )
76+
vertices = np.asarray(mesh.vertices)
77+
triangles = np.asarray(mesh.triangles)
78+
79+
mesh_id = os.path.basename(path)
80+
81+
hull = mesh.compute_convex_hull()[0]
82+
hull_vertices = np.asarray(hull.vertices)
83+
84+
85+
scale = np.max(np.linalg.norm(hull_vertices - hull_vertices[0], axis=1))
86+
87+
vertices /= scale
88+
center = 0.5*(vertices.max(axis=0)+vertices.min(axis=0))
89+
vertices -= center
90+
91+
feat_dict = {
92+
'mesh_id': mesh_id,
93+
'vertices': vertices.astype(np.float32),
94+
'triangles': triangles.astype(np.int32),
95+
}
96+
97+
data.append(feat_dict)
98+
except Exception as err:
99+
print("Failed to generate data for", path)
100+
101+
write_compressed_msgpack(data, output_path)
102+
103+
104+
105+
def main():
106+
parser = argparse.ArgumentParser(description="Create data files for training",
107+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
108+
parser.add_argument("--data_dir", type=str, required=True, help="The path to the Thingi10k dataset root.")
109+
parser.add_argument("--output_dir", type=str, default=os.path.join(os.path.dirname(__file__), 't10k'), help="The path to the output dir")
110+
parser.add_argument("--attribution_file_only", action="store_true", help="Create only the attribution file")
111+
112+
args = parser.parse_args()
113+
114+
info_dict = read_compressed_msgpack(os.path.join(os.path.dirname(__file__),'thingi10k_info.msgpack.zst'))
115+
116+
meshes, attributions = select_good_meshes(info_dict, args.data_dir)
117+
118+
os.makedirs(args.output_dir, exist_ok=True)
119+
valid_output_dir = os.path.join(args.output_dir, 'valid')
120+
os.makedirs(valid_output_dir, exist_ok=True)
121+
train_output_dir = os.path.join(args.output_dir, 'train')
122+
os.makedirs(train_output_dir, exist_ok=True)
123+
124+
attribution_file = "{}_attribution.txt".format(os.path.basename(args.output_dir))
125+
with open(os.path.join(args.output_dir,attribution_file), 'w') as f:
126+
f.write("\n".join(attributions))
127+
128+
if args.attribution_file_only:
129+
return
130+
131+
meshes_sublists = [ [str(ii) for ii in i] for i in np.array_split(meshes, 100) ]
132+
print('objects per record', len(meshes_sublists[0]))
133+
output_paths = [ os.path.join(valid_output_dir if i < 5 else train_output_dir,'thingi10k_{0:03d}.msgpack.zst'.format(i)) for i in range(len(meshes_sublists)) ]
134+
135+
arguments = list(zip(meshes_sublists, output_paths))
136+
137+
with Pool(16) as pool:
138+
pool.starmap(create_data, arguments)
139+
140+
141+
if __name__ == '__main__':
142+
main()

datasets/thingi10k_info.msgpack.zst

1.83 MB
Binary file not shown.

python/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
set( python_package_out_dir "${CMAKE_CURRENT_BINARY_DIR}/python_package" )
33
file( GLOB_RECURSE asr_model_files ${PROJECT_SOURCE_DIR}/models/v*/model*.pt )
4+
file( GLOB_RECURSE dataset_attribution_files ${PROJECT_SOURCE_DIR}/datasets/*/*_attribution.txt )
45
list( APPEND asr_model_files dummy_resource_file )
56

67

@@ -12,6 +13,7 @@ add_custom_target( python_wheel
1213
COMMAND ${CMAKE_COMMAND} -E make_directory "${python_package_out_dir}/adaptivesurfacereconstruction/asr_resources"
1314
COMMAND ${CMAKE_COMMAND} -E touch dummy_resource_file
1415
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${asr_model_files} "${python_package_out_dir}/adaptivesurfacereconstruction/asr_resources"
16+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dataset_attribution_files} "${python_package_out_dir}/adaptivesurfacereconstruction/asr_resources"
1517
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/setup.py" "${python_package_out_dir}"
1618
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.in" "${python_package_out_dir}"
1719
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:asrpybind> "${python_package_out_dir}/adaptivesurfacereconstruction/"

0 commit comments

Comments
 (0)