Skip to content

Commit e7aecdb

Browse files
committed
release code
0 parents  commit e7aecdb

File tree

95 files changed

+12400
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+12400
-0
lines changed

Diff for: .DS_Store

8 KB
Binary file not shown.

Diff for: .gitignore

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
downloads/
14+
eggs/
15+
.eggs/
16+
lib64/
17+
parts/
18+
sdist/
19+
var/
20+
wheels/
21+
share/python-wheels/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
MANIFEST
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.nox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
*.py,cover
48+
.hypothesis/
49+
.pytest_cache/
50+
cover/
51+
52+
# Translations
53+
*.mo
54+
*.pot
55+
56+
# Django stuff:
57+
*.log
58+
local_settings.py
59+
db.sqlite3
60+
db.sqlite3-journal
61+
62+
# Flask stuff:
63+
instance/
64+
.webassets-cache
65+
66+
# Scrapy stuff:
67+
.scrapy
68+
69+
# Sphinx documentation
70+
docs/_build/
71+
72+
# PyBuilder
73+
.pybuilder/
74+
target/
75+
76+
# Jupyter Notebook
77+
.ipynb_checkpoints
78+
79+
# IPython
80+
profile_default/
81+
ipython_config.py
82+
83+
# pyenv
84+
# For a library or package, you might want to ignore these files since the code is
85+
# intended to run in multiple environments; otherwise, check them in:
86+
# .python-version
87+
88+
# pipenv
89+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
91+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
92+
# install all needed dependencies.
93+
#Pipfile.lock
94+
95+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
96+
__pypackages__/
97+
98+
# Celery stuff
99+
celerybeat-schedule
100+
celerybeat.pid
101+
102+
# SageMath parsed files
103+
*.sage.py
104+
105+
# Environments
106+
.env
107+
.venv
108+
env/
109+
venv/
110+
ENV/
111+
env.bak/
112+
venv.bak/
113+
114+
# Spyder project settings
115+
.spyderproject
116+
.spyproject
117+
118+
# Rope project settings
119+
.ropeproject
120+
121+
# mkdocs documentation
122+
/site
123+
124+
# mypy
125+
.mypy_cache/
126+
.dmypy.json
127+
dmypy.json
128+
129+
# Pyre type checker
130+
.pyre/
131+
132+
# pytype static type analyzer
133+
.pytype/
134+
135+
# Cython debug symbols
136+
cython_debug/
137+
138+
exps_*
139+
target_fn/
140+
.vscode/
141+
log.txt
142+
datasets
143+
tv.txt
144+
*.png
145+
plot/
146+
data/
147+
target_fn/
148+
flow/mobiusflow_nref.py
149+
temp.md
150+
151+
ip.py
152+
target_fn_bak/
153+
name/
154+
*.npy
155+
/output
156+
/run
157+
/nflows
158+
*.txt
159+
temp*
160+
result/
161+
Public_prob_orientaion_ePublic_prob_orientation_estimation_with_matrix_fisher_distributions/
162+
tmp/
163+
164+
plot/
165+
*.pth
166+
167+
data/
168+
Matrixfisher/storage
169+
.ssh/
170+
*.pkl
171+
baseline/
172+
cluster/

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 雨霖霖
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: Matrixfisher/ModelNetSo3/ModelNetSo3.py

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import lmdb
2+
import os
3+
import io
4+
import pickle
5+
from PIL import Image
6+
from geometric_utils import numpy_euler_to_rotation, numpy_quaternion_to_rot_mat, numpy_aet_to_rot
7+
import numpy as np
8+
import matplotlib.pyplot as plt
9+
from enum import IntEnum
10+
11+
dataset_dir = 'dataset' # change to where you store datasets
12+
13+
test_name = 'test_20V.Rawjpg.lmdb'
14+
train_name = 'train_100V.Rawjpg.lmdb'
15+
16+
class ModelNetSo3():
17+
def __init__(self, path=dataset_dir):
18+
self.modelnet_dir = os.path.join(path, 'ModelNet10-SO3')
19+
20+
def get_train(self):
21+
full = ModelNetSo3Subset(os.path.join(self.modelnet_dir, train_name)) # split TODO
22+
return full
23+
24+
def get_eval(self):
25+
return ModelNetSo3Subset(os.path.join(self.modelnet_dir, test_name))
26+
27+
def get_cad(self, class_idx, cad_idx):
28+
return np.array([[0.0,0,0], [1,0,0], [0,1,0], [0,0,1]]), None
29+
30+
class ModelNetSo3Classes(IntEnum):
31+
BATHTUB=0
32+
BED=1
33+
CHAIR=2
34+
DESK=3
35+
DRESSER=4
36+
MONITOR=5
37+
NIGHT_STAND=6
38+
SOFA=7
39+
TABLE=8
40+
TOILET=9
41+
42+
def __str__(self):
43+
return self.name.lower()
44+
45+
46+
modelnetso3_str_enum_map = {}
47+
for v in ModelNetSo3Classes:
48+
modelnetso3_str_enum_map[str(v)] = v
49+
50+
class ModelNetSo3Subset():
51+
def __init__(self, path, imsize=224):
52+
self.path = path
53+
lmdb_db = lmdb.open(path)
54+
quaternions_path = os.path.join(path, 'viewID2quat.pkl')
55+
euler_path = os.path.join(path, 'viewID2euler.pkl')
56+
with open(quaternions_path, 'rb') as f:
57+
quaterions = pickle.load(f, encoding='latin1')
58+
with open(euler_path, 'rb') as f:
59+
euler = pickle.load(f, encoding='latin1')
60+
if os.path.exists(self.key_path()):
61+
with open(self.key_path(), 'r') as f:
62+
keys = [x.strip() for x in f.readlines()]
63+
else:
64+
with lmdb_db.begin() as txn:
65+
keys = [key.decode('utf-8') for key, _ in txn.cursor()]
66+
with open(self.key_path(), 'w') as f:
67+
f.write('\n'.join(keys))
68+
69+
self.imsize = imsize
70+
self.lmdb = lmdb_db
71+
self.keys = keys
72+
self.quaterions = quaterions
73+
self.euler = euler
74+
75+
def key_path(self):
76+
return os.path.join(self.path, 'keys.txt')
77+
78+
def __len__(self):
79+
return len(self.keys)
80+
81+
def __getitem__(self, idx):
82+
key = self.keys[idx]
83+
cad_id, view_id = key.split('.')
84+
class_str = cad_id[:cad_id.rfind('_')]
85+
86+
class_idx = modelnetso3_str_enum_map[class_str]
87+
with self.lmdb.begin() as txn:
88+
bits = txn.get(key.encode('utf8'))
89+
f = io.BytesIO(bits)
90+
image = Image.open(f)
91+
image = image.resize((self.imsize, self.imsize), Image.ANTIALIAS)
92+
image = np.array(image.getdata()).reshape(self.imsize, self.imsize, 1).repeat(3,2)
93+
image = image.astype(np.float32) / 255
94+
image = image.transpose(2,0,1)
95+
q = self.quaterions[key]
96+
qx = np.array([q[1], -q[2], q[3], q[0]])
97+
R = numpy_quaternion_to_rot_mat(qx)
98+
extrinsic = np.eye(4)
99+
extrinsic[:3,:3] = R
100+
extrinsic[:3,3] = np.array([0,0,5])
101+
intrinsic = np.array([[self.imsize/2, 0, self.imsize/2],
102+
[0, self.imsize/2, self.imsize/2],
103+
[0,0,1]])
104+
extrinsic=extrinsic.astype(np.float32)
105+
return image, extrinsic, class_idx, 0, intrinsic, 0
106+
107+
108+
109+
110+
def main():
111+
dataset = ModelNetSo3()
112+
tr = dataset.get_train()
113+
print(len(tr))
114+
exit(0)
115+
for i in range(50000):
116+
image, extrinsic, class_idx, hard, intrinsic, cad_idx = tr[i]
117+
nodes, _ = dataset.get_cad(class_idx, cad_idx)
118+
nodes_homo = np.ones((4, len(nodes)))
119+
nodes_homo[:3, :] = nodes.transpose()
120+
model = np.matmul(extrinsic, nodes_homo)
121+
model = model[:3, :]
122+
model /= model[2].reshape(1, -1)
123+
mod_proj = np.matmul(intrinsic, model)
124+
plt.imshow(image.transpose(1,2,0))
125+
for i,c in enumerate(['r','g','b']):
126+
x = [mod_proj[0,0], mod_proj[0, i+1]]
127+
y = [mod_proj[1,0], mod_proj[1, i+1]]
128+
plt.plot(x, y, c)
129+
plt.show()
130+
131+
if __name__ == '__main__':
132+
main()

Diff for: Matrixfisher/ModelNetSo3/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)