LucasHuang0327 commited on
Commit
495e63f
·
verified ·
1 Parent(s): 443f920

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +90 -35
  2. .gitignore +149 -0
  3. .gradio/certificate.pem +31 -0
  4. CODE_OF_CONDUCT.md +80 -0
  5. CONTRIBUTING.md +31 -0
  6. LICENSE.txt +399 -0
  7. README.md +283 -7
  8. demo_colmap.py +330 -0
  9. demo_gradio.py +690 -0
  10. demo_viser.py +402 -0
  11. docs/package.md +45 -0
  12. examples/demo.py +20 -0
  13. examples/kitchen/images/00.png +3 -0
  14. examples/kitchen/images/01.png +3 -0
  15. examples/kitchen/images/02.png +3 -0
  16. examples/kitchen/images/03.png +3 -0
  17. examples/kitchen/images/04.png +3 -0
  18. examples/kitchen/images/05.png +3 -0
  19. examples/kitchen/images/06.png +3 -0
  20. examples/kitchen/images/07.png +3 -0
  21. examples/kitchen/images/08.png +3 -0
  22. examples/kitchen/images/09.png +3 -0
  23. examples/kitchen/images/10.png +3 -0
  24. examples/kitchen/images/11.png +3 -0
  25. examples/kitchen/images/12.png +3 -0
  26. examples/kitchen/images/13.png +3 -0
  27. examples/kitchen/images/14.png +3 -0
  28. examples/kitchen/images/15.png +3 -0
  29. examples/kitchen/images/16.png +3 -0
  30. examples/kitchen/images/17.png +3 -0
  31. examples/kitchen/images/18.png +3 -0
  32. examples/kitchen/images/19.png +3 -0
  33. examples/kitchen/images/20.png +3 -0
  34. examples/kitchen/images/21.png +3 -0
  35. examples/kitchen/images/22.png +3 -0
  36. examples/kitchen/images/23.png +3 -0
  37. examples/kitchen/images/24.png +3 -0
  38. examples/llff_fern/images/000.png +3 -0
  39. examples/llff_fern/images/001.png +3 -0
  40. examples/llff_fern/images/002.png +3 -0
  41. examples/llff_fern/images/003.png +3 -0
  42. examples/llff_fern/images/004.png +3 -0
  43. examples/llff_fern/images/005.png +3 -0
  44. examples/llff_fern/images/006.png +3 -0
  45. examples/llff_fern/images/007.png +3 -0
  46. examples/llff_fern/images/008.png +3 -0
  47. examples/llff_fern/images/009.png +3 -0
  48. examples/llff_fern/images/010.png +3 -0
  49. examples/llff_fern/images/011.png +3 -0
  50. examples/llff_fern/images/012.png +3 -0
.gitattributes CHANGED
@@ -1,35 +1,90 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SCM syntax highlighting & preventing 3-way merges
2
+ pixi.lock merge=binary linguist-language=YAML linguist-generated=true
3
+ examples/kitchen/images/00.png filter=lfs diff=lfs merge=lfs -text
4
+ examples/kitchen/images/01.png filter=lfs diff=lfs merge=lfs -text
5
+ examples/kitchen/images/02.png filter=lfs diff=lfs merge=lfs -text
6
+ examples/kitchen/images/03.png filter=lfs diff=lfs merge=lfs -text
7
+ examples/kitchen/images/04.png filter=lfs diff=lfs merge=lfs -text
8
+ examples/kitchen/images/05.png filter=lfs diff=lfs merge=lfs -text
9
+ examples/kitchen/images/06.png filter=lfs diff=lfs merge=lfs -text
10
+ examples/kitchen/images/07.png filter=lfs diff=lfs merge=lfs -text
11
+ examples/kitchen/images/08.png filter=lfs diff=lfs merge=lfs -text
12
+ examples/kitchen/images/09.png filter=lfs diff=lfs merge=lfs -text
13
+ examples/kitchen/images/10.png filter=lfs diff=lfs merge=lfs -text
14
+ examples/kitchen/images/11.png filter=lfs diff=lfs merge=lfs -text
15
+ examples/kitchen/images/12.png filter=lfs diff=lfs merge=lfs -text
16
+ examples/kitchen/images/13.png filter=lfs diff=lfs merge=lfs -text
17
+ examples/kitchen/images/14.png filter=lfs diff=lfs merge=lfs -text
18
+ examples/kitchen/images/15.png filter=lfs diff=lfs merge=lfs -text
19
+ examples/kitchen/images/16.png filter=lfs diff=lfs merge=lfs -text
20
+ examples/kitchen/images/17.png filter=lfs diff=lfs merge=lfs -text
21
+ examples/kitchen/images/18.png filter=lfs diff=lfs merge=lfs -text
22
+ examples/kitchen/images/19.png filter=lfs diff=lfs merge=lfs -text
23
+ examples/kitchen/images/20.png filter=lfs diff=lfs merge=lfs -text
24
+ examples/kitchen/images/21.png filter=lfs diff=lfs merge=lfs -text
25
+ examples/kitchen/images/22.png filter=lfs diff=lfs merge=lfs -text
26
+ examples/kitchen/images/23.png filter=lfs diff=lfs merge=lfs -text
27
+ examples/kitchen/images/24.png filter=lfs diff=lfs merge=lfs -text
28
+ examples/llff_fern/images/000.png filter=lfs diff=lfs merge=lfs -text
29
+ examples/llff_fern/images/001.png filter=lfs diff=lfs merge=lfs -text
30
+ examples/llff_fern/images/002.png filter=lfs diff=lfs merge=lfs -text
31
+ examples/llff_fern/images/003.png filter=lfs diff=lfs merge=lfs -text
32
+ examples/llff_fern/images/004.png filter=lfs diff=lfs merge=lfs -text
33
+ examples/llff_fern/images/005.png filter=lfs diff=lfs merge=lfs -text
34
+ examples/llff_fern/images/006.png filter=lfs diff=lfs merge=lfs -text
35
+ examples/llff_fern/images/007.png filter=lfs diff=lfs merge=lfs -text
36
+ examples/llff_fern/images/008.png filter=lfs diff=lfs merge=lfs -text
37
+ examples/llff_fern/images/009.png filter=lfs diff=lfs merge=lfs -text
38
+ examples/llff_fern/images/010.png filter=lfs diff=lfs merge=lfs -text
39
+ examples/llff_fern/images/011.png filter=lfs diff=lfs merge=lfs -text
40
+ examples/llff_fern/images/012.png filter=lfs diff=lfs merge=lfs -text
41
+ examples/llff_fern/images/013.png filter=lfs diff=lfs merge=lfs -text
42
+ examples/llff_fern/images/014.png filter=lfs diff=lfs merge=lfs -text
43
+ examples/llff_fern/images/015.png filter=lfs diff=lfs merge=lfs -text
44
+ examples/llff_fern/images/016.png filter=lfs diff=lfs merge=lfs -text
45
+ examples/llff_fern/images/017.png filter=lfs diff=lfs merge=lfs -text
46
+ examples/llff_fern/images/018.png filter=lfs diff=lfs merge=lfs -text
47
+ examples/llff_fern/images/019.png filter=lfs diff=lfs merge=lfs -text
48
+ examples/llff_flower/images/000.png filter=lfs diff=lfs merge=lfs -text
49
+ examples/llff_flower/images/001.png filter=lfs diff=lfs merge=lfs -text
50
+ examples/llff_flower/images/002.png filter=lfs diff=lfs merge=lfs -text
51
+ examples/llff_flower/images/003.png filter=lfs diff=lfs merge=lfs -text
52
+ examples/llff_flower/images/004.png filter=lfs diff=lfs merge=lfs -text
53
+ examples/llff_flower/images/005.png filter=lfs diff=lfs merge=lfs -text
54
+ examples/llff_flower/images/006.png filter=lfs diff=lfs merge=lfs -text
55
+ examples/llff_flower/images/007.png filter=lfs diff=lfs merge=lfs -text
56
+ examples/llff_flower/images/008.png filter=lfs diff=lfs merge=lfs -text
57
+ examples/llff_flower/images/009.png filter=lfs diff=lfs merge=lfs -text
58
+ examples/llff_flower/images/010.png filter=lfs diff=lfs merge=lfs -text
59
+ examples/llff_flower/images/011.png filter=lfs diff=lfs merge=lfs -text
60
+ examples/llff_flower/images/012.png filter=lfs diff=lfs merge=lfs -text
61
+ examples/llff_flower/images/013.png filter=lfs diff=lfs merge=lfs -text
62
+ examples/llff_flower/images/014.png filter=lfs diff=lfs merge=lfs -text
63
+ examples/llff_flower/images/015.png filter=lfs diff=lfs merge=lfs -text
64
+ examples/llff_flower/images/016.png filter=lfs diff=lfs merge=lfs -text
65
+ examples/llff_flower/images/017.png filter=lfs diff=lfs merge=lfs -text
66
+ examples/llff_flower/images/018.png filter=lfs diff=lfs merge=lfs -text
67
+ examples/llff_flower/images/019.png filter=lfs diff=lfs merge=lfs -text
68
+ examples/llff_flower/images/020.png filter=lfs diff=lfs merge=lfs -text
69
+ examples/llff_flower/images/021.png filter=lfs diff=lfs merge=lfs -text
70
+ examples/llff_flower/images/022.png filter=lfs diff=lfs merge=lfs -text
71
+ examples/llff_flower/images/023.png filter=lfs diff=lfs merge=lfs -text
72
+ examples/llff_flower/images/024.png filter=lfs diff=lfs merge=lfs -text
73
+ examples/room/images/no_overlap_1.png filter=lfs diff=lfs merge=lfs -text
74
+ examples/room/images/no_overlap_2.jpg filter=lfs diff=lfs merge=lfs -text
75
+ examples/room/images/no_overlap_3.jpg filter=lfs diff=lfs merge=lfs -text
76
+ examples/room/images/no_overlap_4.jpg filter=lfs diff=lfs merge=lfs -text
77
+ examples/room/images/no_overlap_5.jpg filter=lfs diff=lfs merge=lfs -text
78
+ examples/room/images/no_overlap_6.jpg filter=lfs diff=lfs merge=lfs -text
79
+ examples/room/images/no_overlap_7.jpg filter=lfs diff=lfs merge=lfs -text
80
+ examples/room/images/no_overlap_8.jpg filter=lfs diff=lfs merge=lfs -text
81
+ examples/single_cartoon/images/model_was_never_trained_on_single_image_or_cartoon.jpg filter=lfs diff=lfs merge=lfs -text
82
+ examples/single_oil_painting/images/model_was_never_trained_on_single_image_or_oil_painting.png filter=lfs diff=lfs merge=lfs -text
83
+ examples/videos/Colosseum.mp4 filter=lfs diff=lfs merge=lfs -text
84
+ examples/videos/fern.mp4 filter=lfs diff=lfs merge=lfs -text
85
+ examples/videos/great_wall.mp4 filter=lfs diff=lfs merge=lfs -text
86
+ examples/videos/kitchen.mp4 filter=lfs diff=lfs merge=lfs -text
87
+ examples/videos/pyramid.mp4 filter=lfs diff=lfs merge=lfs -text
88
+ examples/videos/room.mp4 filter=lfs diff=lfs merge=lfs -text
89
+ examples/videos/single_cartoon.mp4 filter=lfs diff=lfs merge=lfs -text
90
+ examples/videos/single_oil_painting.mp4 filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .hydra/
2
+ output/
3
+ ckpt/
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ **/__pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+
10
+ # C extensions
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ pip-wheel-metadata/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # pyenv
90
+ .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
100
+ __pypackages__/
101
+
102
+ # Celery stuff
103
+ celerybeat-schedule
104
+ celerybeat.pid
105
+
106
+ # SageMath parsed files
107
+ *.sage.py
108
+
109
+ # Environments
110
+ .env
111
+ .venv
112
+ env/
113
+ venv/
114
+ ENV/
115
+ env.bak/
116
+ venv.bak/
117
+
118
+ # Spyder project settings
119
+ .spyderproject
120
+ .spyproject
121
+
122
+ # Rope project settings
123
+ .ropeproject
124
+
125
+ # mkdocs documentation
126
+ /site
127
+
128
+ # mypy
129
+ .mypy_cache/
130
+ .dmypy.json
131
+ dmypy.json
132
+
133
+ # Pyre type checker
134
+ .pyre/
135
+
136
+ # pytype static type analyzer
137
+ .pytype/
138
+
139
+ # Profiling data
140
+ .prof
141
+
142
+ # Folder specific to your needs
143
+ **/tmp/
144
+ **/outputs/skyseg.onnx
145
+ skyseg.onnx
146
+
147
+ # pixi environments
148
+ .pixi
149
+ *.egg-info
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3
+ TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4
+ cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5
+ WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6
+ ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7
+ MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8
+ h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9
+ 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10
+ A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11
+ T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12
+ B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13
+ B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
14
+ KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn
15
+ OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn
16
+ jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw
17
+ qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI
18
+ rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
19
+ HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
20
+ hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
21
+ ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
22
+ 3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
23
+ NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
24
+ ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
25
+ TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
26
+ jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
27
+ oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
28
+ 4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
29
+ mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
30
+ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all project spaces, and it also applies when
49
+ an individual is representing the project or its community in public spaces.
50
+ Examples of representing a project or community include using an official
51
+ project e-mail address, posting via an official social media account, or acting
52
+ as an appointed representative at an online or offline event. Representation of
53
+ a project may be further defined and clarified by project maintainers.
54
+
55
+ This Code of Conduct also applies outside the project spaces when there is a
56
+ reasonable belief that an individual's behavior may have a negative impact on
57
+ the project or its community.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported by contacting the project team at <opensource-conduct@meta.com>. All
63
+ complaints will be reviewed and investigated and will result in a response that
64
+ is deemed necessary and appropriate to the circumstances. The project team is
65
+ obligated to maintain confidentiality with regard to the reporter of an incident.
66
+ Further details of specific enforcement policies may be posted separately.
67
+
68
+ Project maintainers who do not follow or enforce the Code of Conduct in good
69
+ faith may face temporary or permanent repercussions as determined by other
70
+ members of the project's leadership.
71
+
72
+ ## Attribution
73
+
74
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
75
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
76
+
77
+ [homepage]: https://www.contributor-covenant.org
78
+
79
+ For answers to common questions about this code of conduct, see
80
+ https://www.contributor-covenant.org/faq
CONTRIBUTING.md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contributing to vggt
2
+ We want to make contributing to this project as easy and transparent as
3
+ possible.
4
+
5
+ ## Pull Requests
6
+ We actively welcome your pull requests.
7
+
8
+ 1. Fork the repo and create your branch from `main`.
9
+ 2. If you've added code that should be tested, add tests.
10
+ 3. If you've changed APIs, update the documentation.
11
+ 4. Ensure the test suite passes.
12
+ 5. Make sure your code lints.
13
+ 6. If you haven't already, complete the Contributor License Agreement ("CLA").
14
+
15
+ ## Contributor License Agreement ("CLA")
16
+ In order to accept your pull request, we need you to submit a CLA. You only need
17
+ to do this once to work on any of Facebook's open source projects.
18
+
19
+ Complete your CLA here: <https://code.facebook.com/cla>
20
+
21
+ ## Issues
22
+ We use GitHub issues to track public bugs. Please ensure your description is
23
+ clear and has sufficient instructions to be able to reproduce the issue.
24
+
25
+ Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
26
+ disclosure of security bugs. In those cases, please go through the process
27
+ outlined on that page and do not file a public issue.
28
+
29
+ ## License
30
+ By contributing to vggt, you agree that your contributions will be licensed
31
+ under the LICENSE file in the root directory of this source tree.
LICENSE.txt ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Attribution-NonCommercial 4.0 International
2
+
3
+ =======================================================================
4
+
5
+ Creative Commons Corporation ("Creative Commons") is not a law firm and
6
+ does not provide legal services or legal advice. Distribution of
7
+ Creative Commons public licenses does not create a lawyer-client or
8
+ other relationship. Creative Commons makes its licenses and related
9
+ information available on an "as-is" basis. Creative Commons gives no
10
+ warranties regarding its licenses, any material licensed under their
11
+ terms and conditions, or any related information. Creative Commons
12
+ disclaims all liability for damages resulting from their use to the
13
+ fullest extent possible.
14
+
15
+ Using Creative Commons Public Licenses
16
+
17
+ Creative Commons public licenses provide a standard set of terms and
18
+ conditions that creators and other rights holders may use to share
19
+ original works of authorship and other material subject to copyright
20
+ and certain other rights specified in the public license below. The
21
+ following considerations are for informational purposes only, are not
22
+ exhaustive, and do not form part of our licenses.
23
+
24
+ Considerations for licensors: Our public licenses are
25
+ intended for use by those authorized to give the public
26
+ permission to use material in ways otherwise restricted by
27
+ copyright and certain other rights. Our licenses are
28
+ irrevocable. Licensors should read and understand the terms
29
+ and conditions of the license they choose before applying it.
30
+ Licensors should also secure all rights necessary before
31
+ applying our licenses so that the public can reuse the
32
+ material as expected. Licensors should clearly mark any
33
+ material not subject to the license. This includes other CC-
34
+ licensed material, or material used under an exception or
35
+ limitation to copyright. More considerations for licensors:
36
+ wiki.creativecommons.org/Considerations_for_licensors
37
+
38
+ Considerations for the public: By using one of our public
39
+ licenses, a licensor grants the public permission to use the
40
+ licensed material under specified terms and conditions. If
41
+ the licensor's permission is not necessary for any reason--for
42
+ example, because of any applicable exception or limitation to
43
+ copyright--then that use is not regulated by the license. Our
44
+ licenses grant only permissions under copyright and certain
45
+ other rights that a licensor has authority to grant. Use of
46
+ the licensed material may still be restricted for other
47
+ reasons, including because others have copyright or other
48
+ rights in the material. A licensor may make special requests,
49
+ such as asking that all changes be marked or described.
50
+ Although not required by our licenses, you are encouraged to
51
+ respect those requests where reasonable. More_considerations
52
+ for the public:
53
+ wiki.creativecommons.org/Considerations_for_licensees
54
+
55
+ =======================================================================
56
+
57
+ Creative Commons Attribution-NonCommercial 4.0 International Public
58
+ License
59
+
60
+ By exercising the Licensed Rights (defined below), You accept and agree
61
+ to be bound by the terms and conditions of this Creative Commons
62
+ Attribution-NonCommercial 4.0 International Public License ("Public
63
+ License"). To the extent this Public License may be interpreted as a
64
+ contract, You are granted the Licensed Rights in consideration of Your
65
+ acceptance of these terms and conditions, and the Licensor grants You
66
+ such rights in consideration of benefits the Licensor receives from
67
+ making the Licensed Material available under these terms and
68
+ conditions.
69
+
70
+ Section 1 -- Definitions.
71
+
72
+ a. Adapted Material means material subject to Copyright and Similar
73
+ Rights that is derived from or based upon the Licensed Material
74
+ and in which the Licensed Material is translated, altered,
75
+ arranged, transformed, or otherwise modified in a manner requiring
76
+ permission under the Copyright and Similar Rights held by the
77
+ Licensor. For purposes of this Public License, where the Licensed
78
+ Material is a musical work, performance, or sound recording,
79
+ Adapted Material is always produced where the Licensed Material is
80
+ synched in timed relation with a moving image.
81
+
82
+ b. Adapter's License means the license You apply to Your Copyright
83
+ and Similar Rights in Your contributions to Adapted Material in
84
+ accordance with the terms and conditions of this Public License.
85
+
86
+ c. Copyright and Similar Rights means copyright and/or similar rights
87
+ closely related to copyright including, without limitation,
88
+ performance, broadcast, sound recording, and Sui Generis Database
89
+ Rights, without regard to how the rights are labeled or
90
+ categorized. For purposes of this Public License, the rights
91
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
92
+ Rights.
93
+ d. Effective Technological Measures means those measures that, in the
94
+ absence of proper authority, may not be circumvented under laws
95
+ fulfilling obligations under Article 11 of the WIPO Copyright
96
+ Treaty adopted on December 20, 1996, and/or similar international
97
+ agreements.
98
+
99
+ e. Exceptions and Limitations means fair use, fair dealing, and/or
100
+ any other exception or limitation to Copyright and Similar Rights
101
+ that applies to Your use of the Licensed Material.
102
+
103
+ f. Licensed Material means the artistic or literary work, database,
104
+ or other material to which the Licensor applied this Public
105
+ License.
106
+
107
+ g. Licensed Rights means the rights granted to You subject to the
108
+ terms and conditions of this Public License, which are limited to
109
+ all Copyright and Similar Rights that apply to Your use of the
110
+ Licensed Material and that the Licensor has authority to license.
111
+
112
+ h. Licensor means the individual(s) or entity(ies) granting rights
113
+ under this Public License.
114
+
115
+ i. NonCommercial means not primarily intended for or directed towards
116
+ commercial advantage or monetary compensation. For purposes of
117
+ this Public License, the exchange of the Licensed Material for
118
+ other material subject to Copyright and Similar Rights by digital
119
+ file-sharing or similar means is NonCommercial provided there is
120
+ no payment of monetary compensation in connection with the
121
+ exchange.
122
+
123
+ j. Share means to provide material to the public by any means or
124
+ process that requires permission under the Licensed Rights, such
125
+ as reproduction, public display, public performance, distribution,
126
+ dissemination, communication, or importation, and to make material
127
+ available to the public including in ways that members of the
128
+ public may access the material from a place and at a time
129
+ individually chosen by them.
130
+
131
+ k. Sui Generis Database Rights means rights other than copyright
132
+ resulting from Directive 96/9/EC of the European Parliament and of
133
+ the Council of 11 March 1996 on the legal protection of databases,
134
+ as amended and/or succeeded, as well as other essentially
135
+ equivalent rights anywhere in the world.
136
+
137
+ l. You means the individual or entity exercising the Licensed Rights
138
+ under this Public License. Your has a corresponding meaning.
139
+
140
+ Section 2 -- Scope.
141
+
142
+ a. License grant.
143
+
144
+ 1. Subject to the terms and conditions of this Public License,
145
+ the Licensor hereby grants You a worldwide, royalty-free,
146
+ non-sublicensable, non-exclusive, irrevocable license to
147
+ exercise the Licensed Rights in the Licensed Material to:
148
+
149
+ a. reproduce and Share the Licensed Material, in whole or
150
+ in part, for NonCommercial purposes only; and
151
+
152
+ b. produce, reproduce, and Share Adapted Material for
153
+ NonCommercial purposes only.
154
+
155
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
156
+ Exceptions and Limitations apply to Your use, this Public
157
+ License does not apply, and You do not need to comply with
158
+ its terms and conditions.
159
+
160
+ 3. Term. The term of this Public License is specified in Section
161
+ 6(a).
162
+
163
+ 4. Media and formats; technical modifications allowed. The
164
+ Licensor authorizes You to exercise the Licensed Rights in
165
+ all media and formats whether now known or hereafter created,
166
+ and to make technical modifications necessary to do so. The
167
+ Licensor waives and/or agrees not to assert any right or
168
+ authority to forbid You from making technical modifications
169
+ necessary to exercise the Licensed Rights, including
170
+ technical modifications necessary to circumvent Effective
171
+ Technological Measures. For purposes of this Public License,
172
+ simply making modifications authorized by this Section 2(a)
173
+ (4) never produces Adapted Material.
174
+
175
+ 5. Downstream recipients.
176
+
177
+ a. Offer from the Licensor -- Licensed Material. Every
178
+ recipient of the Licensed Material automatically
179
+ receives an offer from the Licensor to exercise the
180
+ Licensed Rights under the terms and conditions of this
181
+ Public License.
182
+
183
+ b. No downstream restrictions. You may not offer or impose
184
+ any additional or different terms or conditions on, or
185
+ apply any Effective Technological Measures to, the
186
+ Licensed Material if doing so restricts exercise of the
187
+ Licensed Rights by any recipient of the Licensed
188
+ Material.
189
+
190
+ 6. No endorsement. Nothing in this Public License constitutes or
191
+ may be construed as permission to assert or imply that You
192
+ are, or that Your use of the Licensed Material is, connected
193
+ with, or sponsored, endorsed, or granted official status by,
194
+ the Licensor or others designated to receive attribution as
195
+ provided in Section 3(a)(1)(A)(i).
196
+
197
+ b. Other rights.
198
+
199
+ 1. Moral rights, such as the right of integrity, are not
200
+ licensed under this Public License, nor are publicity,
201
+ privacy, and/or other similar personality rights; however, to
202
+ the extent possible, the Licensor waives and/or agrees not to
203
+ assert any such rights held by the Licensor to the limited
204
+ extent necessary to allow You to exercise the Licensed
205
+ Rights, but not otherwise.
206
+
207
+ 2. Patent and trademark rights are not licensed under this
208
+ Public License.
209
+
210
+ 3. To the extent possible, the Licensor waives any right to
211
+ collect royalties from You for the exercise of the Licensed
212
+ Rights, whether directly or through a collecting society
213
+ under any voluntary or waivable statutory or compulsory
214
+ licensing scheme. In all other cases the Licensor expressly
215
+ reserves any right to collect such royalties, including when
216
+ the Licensed Material is used other than for NonCommercial
217
+ purposes.
218
+
219
+ Section 3 -- License Conditions.
220
+
221
+ Your exercise of the Licensed Rights is expressly made subject to the
222
+ following conditions.
223
+
224
+ a. Attribution.
225
+
226
+ 1. If You Share the Licensed Material (including in modified
227
+ form), You must:
228
+
229
+ a. retain the following if it is supplied by the Licensor
230
+ with the Licensed Material:
231
+
232
+ i. identification of the creator(s) of the Licensed
233
+ Material and any others designated to receive
234
+ attribution, in any reasonable manner requested by
235
+ the Licensor (including by pseudonym if
236
+ designated);
237
+
238
+ ii. a copyright notice;
239
+
240
+ iii. a notice that refers to this Public License;
241
+
242
+ iv. a notice that refers to the disclaimer of
243
+ warranties;
244
+
245
+ v. a URI or hyperlink to the Licensed Material to the
246
+ extent reasonably practicable;
247
+
248
+ b. indicate if You modified the Licensed Material and
249
+ retain an indication of any previous modifications; and
250
+
251
+ c. indicate the Licensed Material is licensed under this
252
+ Public License, and include the text of, or the URI or
253
+ hyperlink to, this Public License.
254
+
255
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
256
+ reasonable manner based on the medium, means, and context in
257
+ which You Share the Licensed Material. For example, it may be
258
+ reasonable to satisfy the conditions by providing a URI or
259
+ hyperlink to a resource that includes the required
260
+ information.
261
+
262
+ 3. If requested by the Licensor, You must remove any of the
263
+ information required by Section 3(a)(1)(A) to the extent
264
+ reasonably practicable.
265
+
266
+ 4. If You Share Adapted Material You produce, the Adapter's
267
+ License You apply must not prevent recipients of the Adapted
268
+ Material from complying with this Public License.
269
+
270
+ Section 4 -- Sui Generis Database Rights.
271
+
272
+ Where the Licensed Rights include Sui Generis Database Rights that
273
+ apply to Your use of the Licensed Material:
274
+
275
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
276
+ to extract, reuse, reproduce, and Share all or a substantial
277
+ portion of the contents of the database for NonCommercial purposes
278
+ only;
279
+
280
+ b. if You include all or a substantial portion of the database
281
+ contents in a database in which You have Sui Generis Database
282
+ Rights, then the database in which You have Sui Generis Database
283
+ Rights (but not its individual contents) is Adapted Material; and
284
+
285
+ c. You must comply with the conditions in Section 3(a) if You Share
286
+ all or a substantial portion of the contents of the database.
287
+
288
+ For the avoidance of doubt, this Section 4 supplements and does not
289
+ replace Your obligations under this Public License where the Licensed
290
+ Rights include other Copyright and Similar Rights.
291
+
292
+ Section 5 -- Disclaimer of Warranties and Limitation of Liability.
293
+
294
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
295
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
296
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
297
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
298
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
299
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
300
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
301
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
302
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
303
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
304
+
305
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
306
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
307
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
308
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
309
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
310
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
311
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
312
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
313
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
314
+
315
+ c. The disclaimer of warranties and limitation of liability provided
316
+ above shall be interpreted in a manner that, to the extent
317
+ possible, most closely approximates an absolute disclaimer and
318
+ waiver of all liability.
319
+
320
+ Section 6 -- Term and Termination.
321
+
322
+ a. This Public License applies for the term of the Copyright and
323
+ Similar Rights licensed here. However, if You fail to comply with
324
+ this Public License, then Your rights under this Public License
325
+ terminate automatically.
326
+
327
+ b. Where Your right to use the Licensed Material has terminated under
328
+ Section 6(a), it reinstates:
329
+
330
+ 1. automatically as of the date the violation is cured, provided
331
+ it is cured within 30 days of Your discovery of the
332
+ violation; or
333
+
334
+ 2. upon express reinstatement by the Licensor.
335
+
336
+ For the avoidance of doubt, this Section 6(b) does not affect any
337
+ right the Licensor may have to seek remedies for Your violations
338
+ of this Public License.
339
+
340
+ c. For the avoidance of doubt, the Licensor may also offer the
341
+ Licensed Material under separate terms or conditions or stop
342
+ distributing the Licensed Material at any time; however, doing so
343
+ will not terminate this Public License.
344
+
345
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
346
+ License.
347
+
348
+ Section 7 -- Other Terms and Conditions.
349
+
350
+ a. The Licensor shall not be bound by any additional or different
351
+ terms or conditions communicated by You unless expressly agreed.
352
+
353
+ b. Any arrangements, understandings, or agreements regarding the
354
+ Licensed Material not stated herein are separate from and
355
+ independent of the terms and conditions of this Public License.
356
+
357
+ Section 8 -- Interpretation.
358
+
359
+ a. For the avoidance of doubt, this Public License does not, and
360
+ shall not be interpreted to, reduce, limit, restrict, or impose
361
+ conditions on any use of the Licensed Material that could lawfully
362
+ be made without permission under this Public License.
363
+
364
+ b. To the extent possible, if any provision of this Public License is
365
+ deemed unenforceable, it shall be automatically reformed to the
366
+ minimum extent necessary to make it enforceable. If the provision
367
+ cannot be reformed, it shall be severed from this Public License
368
+ without affecting the enforceability of the remaining terms and
369
+ conditions.
370
+
371
+ c. No term or condition of this Public License will be waived and no
372
+ failure to comply consented to unless expressly agreed to by the
373
+ Licensor.
374
+
375
+ d. Nothing in this Public License constitutes or may be interpreted
376
+ as a limitation upon, or waiver of, any privileges and immunities
377
+ that apply to the Licensor or You, including from the legal
378
+ processes of any jurisdiction or authority.
379
+
380
+ =======================================================================
381
+
382
+ Creative Commons is not a party to its public
383
+ licenses. Notwithstanding, Creative Commons may elect to apply one of
384
+ its public licenses to material it publishes and in those instances
385
+ will be considered the “Licensor.” The text of the Creative Commons
386
+ public licenses is dedicated to the public domain under the CC0 Public
387
+ Domain Dedication. Except for the limited purpose of indicating that
388
+ material is shared under a Creative Commons public license or as
389
+ otherwise permitted by the Creative Commons policies published at
390
+ creativecommons.org/policies, Creative Commons does not authorize the
391
+ use of the trademark "Creative Commons" or any other trademark or logo
392
+ of Creative Commons without its prior written consent including,
393
+ without limitation, in connection with any unauthorized modifications
394
+ to any of its public licenses or any other arrangements,
395
+ understandings, or agreements concerning use of licensed material. For
396
+ the avoidance of doubt, this paragraph does not form part of the
397
+ public licenses.
398
+
399
+ Creative Commons may be contacted at creativecommons.org.
README.md CHANGED
@@ -1,12 +1,288 @@
1
  ---
2
- title: Vggt
3
- emoji: 🐢
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.34.2
8
- app_file: app.py
9
- pinned: false
10
  ---
 
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: vggt
3
+ app_file: demo_gradio.py
 
 
4
  sdk: gradio
5
  sdk_version: 5.34.2
 
 
6
  ---
7
+ <div align="center">
8
+ <h1>VGGT: Visual Geometry Grounded Transformer</h1>
9
 
10
+ <a href="https://jytime.github.io/data/VGGT_CVPR25.pdf" target="_blank" rel="noopener noreferrer">
11
+ <img src="https://img.shields.io/badge/Paper-VGGT" alt="Paper PDF">
12
+ </a>
13
+ <a href="https://arxiv.org/abs/2503.11651"><img src="https://img.shields.io/badge/arXiv-2503.11651-b31b1b" alt="arXiv"></a>
14
+ <a href="https://vgg-t.github.io/"><img src="https://img.shields.io/badge/Project_Page-green" alt="Project Page"></a>
15
+ <a href='https://huggingface.co/spaces/facebook/vggt'><img src='https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-blue'></a>
16
+
17
+
18
+ **[Visual Geometry Group, University of Oxford](https://www.robots.ox.ac.uk/~vgg/)**; **[Meta AI](https://ai.facebook.com/research/)**
19
+
20
+
21
+ [Jianyuan Wang](https://jytime.github.io/), [Minghao Chen](https://silent-chen.github.io/), [Nikita Karaev](https://nikitakaraevv.github.io/), [Andrea Vedaldi](https://www.robots.ox.ac.uk/~vedaldi/), [Christian Rupprecht](https://chrirupp.github.io/), [David Novotny](https://d-novotny.github.io/)
22
+ </div>
23
+
24
+ ```bibtex
25
+ @inproceedings{wang2025vggt,
26
+ title={VGGT: Visual Geometry Grounded Transformer},
27
+ author={Wang, Jianyuan and Chen, Minghao and Karaev, Nikita and Vedaldi, Andrea and Rupprecht, Christian and Novotny, David},
28
+ booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
29
+ year={2025}
30
+ }
31
+ ```
32
+
33
+ ## Updates
34
+ - [June 13, 2025] Honored to receive the Best Paper Award at CVPR 2025! Apologies if I’m slow to respond to queries or GitHub issues these days. If you’re interested, our oral presentation is available [here](https://docs.google.com/presentation/d/1JVuPnuZx6RgAy-U5Ezobg73XpBi7FrOh/edit?usp=sharing&ouid=107115712143490405606&rtpof=true&sd=true). (Note: it’s shared in .pptx format with animations — quite large, but feel free to use it as a template if helpful.)
35
+
36
+
37
+ - [June 2, 2025] Added a script to run VGGT and save predictions in COLMAP format, with bundle adjustment support optional. The saved COLMAP files can be directly used with [gsplat](https://github.com/nerfstudio-project/gsplat) or other NeRF/Gaussian splatting libraries.
38
+
39
+
40
+ - [May 3, 2025] Evaluation code for reproducing our camera pose estimation results on Co3D is now available in the [evaluation](https://github.com/facebookresearch/vggt/tree/evaluation) branch.
41
+
42
+
43
+ - [Apr 13, 2025] Training code is being gradually cleaned and uploaded to the [training](https://github.com/facebookresearch/vggt/tree/training) branch. It will be merged into the main branch once finalized.
44
+
45
+ ## Overview
46
+
47
+ Visual Geometry Grounded Transformer (VGGT, CVPR 2025) is a feed-forward neural network that directly infers all key 3D attributes of a scene, including extrinsic and intrinsic camera parameters, point maps, depth maps, and 3D point tracks, **from one, a few, or hundreds of its views, within seconds**.
48
+
49
+
50
+ ## Quick Start
51
+
52
+ First, clone this repository to your local machine, and install the dependencies (torch, torchvision, numpy, Pillow, and huggingface_hub).
53
+
54
+ ```bash
55
+ git clone git@github.com:facebookresearch/vggt.git
56
+ cd vggt
57
+ pip install -r requirements.txt
58
+ ```
59
+
60
+ Alternatively, you can install VGGT as a package (<a href="docs/package.md">click here</a> for details).
61
+
62
+
63
+ Now, try the model with just a few lines of code:
64
+
65
+ ```python
66
+ import torch
67
+ from vggt.models.vggt import VGGT
68
+ from vggt.utils.load_fn import load_and_preprocess_images
69
+
70
+ device = "cuda" if torch.cuda.is_available() else "cpu"
71
+ # bfloat16 is supported on Ampere GPUs (Compute Capability 8.0+)
72
+ dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] >= 8 else torch.float16
73
+
74
+ # Initialize the model and load the pretrained weights.
75
+ # This will automatically download the model weights the first time it's run, which may take a while.
76
+ model = VGGT.from_pretrained("facebook/VGGT-1B").to(device)
77
+
78
+ # Load and preprocess example images (replace with your own image paths)
79
+ image_names = ["path/to/imageA.png", "path/to/imageB.png", "path/to/imageC.png"]
80
+ images = load_and_preprocess_images(image_names).to(device)
81
+
82
+ with torch.no_grad():
83
+ with torch.cuda.amp.autocast(dtype=dtype):
84
+ # Predict attributes including cameras, depth maps, and point maps.
85
+ predictions = model(images)
86
+ ```
87
+
88
+ The model weights will be automatically downloaded from Hugging Face. If you encounter issues such as slow loading, you can manually download them [here](https://huggingface.co/facebook/VGGT-1B/blob/main/model.pt) and load, or:
89
+
90
+ ```python
91
+ model = VGGT()
92
+ _URL = "https://huggingface.co/facebook/VGGT-1B/resolve/main/model.pt"
93
+ model.load_state_dict(torch.hub.load_state_dict_from_url(_URL))
94
+ ```
95
+
96
+ ## Detailed Usage
97
+
98
+ <details>
99
+ <summary>Click to expand</summary>
100
+
101
+ You can also optionally choose which attributes (branches) to predict, as shown below. This achieves the same result as the example above. This example uses a batch size of 1 (processing a single scene), but it naturally works for multiple scenes.
102
+
103
+ ```python
104
+ from vggt.utils.pose_enc import pose_encoding_to_extri_intri
105
+ from vggt.utils.geometry import unproject_depth_map_to_point_map
106
+
107
+ with torch.no_grad():
108
+ with torch.cuda.amp.autocast(dtype=dtype):
109
+ images = images[None] # add batch dimension
110
+ aggregated_tokens_list, ps_idx = model.aggregator(images)
111
+
112
+ # Predict Cameras
113
+ pose_enc = model.camera_head(aggregated_tokens_list)[-1]
114
+ # Extrinsic and intrinsic matrices, following OpenCV convention (camera from world)
115
+ extrinsic, intrinsic = pose_encoding_to_extri_intri(pose_enc, images.shape[-2:])
116
+
117
+ # Predict Depth Maps
118
+ depth_map, depth_conf = model.depth_head(aggregated_tokens_list, images, ps_idx)
119
+
120
+ # Predict Point Maps
121
+ point_map, point_conf = model.point_head(aggregated_tokens_list, images, ps_idx)
122
+
123
+ # Construct 3D Points from Depth Maps and Cameras
124
+ # which usually leads to more accurate 3D points than point map branch
125
+ point_map_by_unprojection = unproject_depth_map_to_point_map(depth_map.squeeze(0),
126
+ extrinsic.squeeze(0),
127
+ intrinsic.squeeze(0))
128
+
129
+ # Predict Tracks
130
+ # choose your own points to track, with shape (N, 2) for one scene
131
+ query_points = torch.FloatTensor([[100.0, 200.0],
132
+ [60.72, 259.94]]).to(device)
133
+ track_list, vis_score, conf_score = model.track_head(aggregated_tokens_list, images, ps_idx, query_points=query_points[None])
134
+ ```
135
+
136
+
137
+ Furthermore, if certain pixels in the input frames are unwanted (e.g., reflective surfaces, sky, or water), you can simply mask them by setting the corresponding pixel values to 0 or 1. Precise segmentation masks aren't necessary - simple bounding box masks work effectively (check this [issue](https://github.com/facebookresearch/vggt/issues/47) for an example).
138
+
139
+ </details>
140
+
141
+
142
+ ## Interactive Demo
143
+
144
+ We provide multiple ways to visualize your 3D reconstructions. Before using these visualization tools, install the required dependencies:
145
+
146
+ ```bash
147
+ pip install -r requirements_demo.txt
148
+ ```
149
+
150
+ ### Interactive 3D Visualization
151
+
152
+ **Please note:** VGGT typically reconstructs a scene in less than 1 second. However, visualizing 3D points may take tens of seconds due to third-party rendering, independent of VGGT's processing time. The visualization is slow especially when the number of images is large.
153
+
154
+
155
+ #### Gradio Web Interface
156
+
157
+ Our Gradio-based interface allows you to upload images/videos, run reconstruction, and interactively explore the 3D scene in your browser. You can launch this in your local machine or try it on [Hugging Face](https://huggingface.co/spaces/facebook/vggt).
158
+
159
+
160
+ ```bash
161
+ python demo_gradio.py
162
+ ```
163
+
164
+ <details>
165
+ <summary>Click to preview the Gradio interactive interface</summary>
166
+
167
+ ![Gradio Web Interface Preview](https://jytime.github.io/data/vggt_hf_demo_screen.png)
168
+ </details>
169
+
170
+
171
+ #### Viser 3D Viewer
172
+
173
+ Run the following command to run reconstruction and visualize the point clouds in viser. Note this script requires a path to a folder containing images. It assumes only image files under the folder. You can set `--use_point_map` to use the point cloud from the point map branch, instead of the depth-based point cloud.
174
+
175
+ ```bash
176
+ python demo_viser.py --image_folder path/to/your/images/folder
177
+ ```
178
+
179
+ ## Exporting to COLMAP Format
180
+
181
+ We also support exporting VGGT's predictions directly to COLMAP format, by:
182
+
183
+ ```bash
184
+ # Feedforward prediction only
185
+ python demo_colmap.py --scene_dir=/YOUR/SCENE_DIR/
186
+
187
+ # With bundle adjustment
188
+ python demo_colmap.py --scene_dir=/YOUR/SCENE_DIR/ --use_ba
189
+
190
+ # Run with bundle adjustment using reduced parameters for faster processing
191
+ # Reduces max_query_pts from 4096 (default) to 2048 and query_frame_num from 8 (default) to 5
192
+ # Trade-off: Faster execution but potentially less robust reconstruction in complex scenes (you may consider setting query_frame_num equal to your total number of images)
193
+ # See demo_colmap.py for additional bundle adjustment configuration options
194
+ python demo_colmap.py --scene_dir=/YOUR/SCENE_DIR/ --use_ba --max_query_pts=2048 --query_frame_num=5
195
+ ```
196
+
197
+ Please ensure that the images are stored in `/YOUR/SCENE_DIR/images/`. This folder should contain only the images. Check the examples folder for the desired data structure.
198
+
199
+ The reconstruction result (camera parameters and 3D points) will be automatically saved under `/YOUR/SCENE_DIR/sparse/` in the COLMAP format, such as:
200
+
201
+ ```
202
+ SCENE_DIR/
203
+ ├── images/
204
+ └── sparse/
205
+ ├── cameras.bin
206
+ ├── images.bin
207
+ └── points3D.bin
208
+ ```
209
+
210
+ ## Integration with Gaussian Splatting
211
+
212
+
213
+ The exported COLMAP files can be directly used with [gsplat](https://github.com/nerfstudio-project/gsplat) for Gaussian Splatting training. Install `gsplat` following their official instructions (we recommend `gsplat==1.3.0`):
214
+
215
+ An example command to train the model is:
216
+ ```
217
+ cd gsplat
218
+ python examples/simple_trainer.py default --data_factor 1 --data_dir /YOUR/SCENE_DIR/ --result_dir /YOUR/RESULT_DIR/
219
+ ```
220
+
221
+
222
+
223
+ ## Zero-shot Single-view Reconstruction
224
+
225
+ Our model shows surprisingly good performance on single-view reconstruction, although it was never trained for this task. The model does not need to duplicate the single-view image to a pair, instead, it can directly infer the 3D structure from the tokens of the single view image. Feel free to try it with our demos above, which naturally works for single-view reconstruction.
226
+
227
+
228
+ We did not quantitatively test monocular depth estimation performance ourselves, but [@kabouzeid](https://github.com/kabouzeid) generously provided a comparison of VGGT to recent methods [here](https://github.com/facebookresearch/vggt/issues/36). VGGT shows competitive or better results compared to state-of-the-art monocular approaches such as DepthAnything v2 or MoGe, despite never being explicitly trained for single-view tasks.
229
+
230
+
231
+
232
+ ## Runtime and GPU Memory
233
+
234
+ We benchmark the runtime and GPU memory usage of VGGT's aggregator on a single NVIDIA H100 GPU across various input sizes.
235
+
236
+ | **Input Frames** | 1 | 2 | 4 | 8 | 10 | 20 | 50 | 100 | 200 |
237
+ |:----------------:|:-:|:-:|:-:|:-:|:--:|:--:|:--:|:---:|:---:|
238
+ | **Time (s)** | 0.04 | 0.05 | 0.07 | 0.11 | 0.14 | 0.31 | 1.04 | 3.12 | 8.75 |
239
+ | **Memory (GB)** | 1.88 | 2.07 | 2.45 | 3.23 | 3.63 | 5.58 | 11.41 | 21.15 | 40.63 |
240
+
241
+ Note that these results were obtained using Flash Attention 3, which is faster than the default Flash Attention 2 implementation while maintaining almost the same memory usage. Feel free to compile Flash Attention 3 from source to get better performance.
242
+
243
+
244
+ ## Research Progression
245
+
246
+ Our work builds upon a series of previous research projects. If you're interested in understanding how our research evolved, check out our previous works:
247
+
248
+
249
+ <table border="0" cellspacing="0" cellpadding="0">
250
+ <tr>
251
+ <td align="left">
252
+ <a href="https://github.com/jytime/Deep-SfM-Revisited">Deep SfM Revisited</a>
253
+ </td>
254
+ <td style="white-space: pre;">──┐</td>
255
+ <td></td>
256
+ </tr>
257
+ <tr>
258
+ <td align="left">
259
+ <a href="https://github.com/facebookresearch/PoseDiffusion">PoseDiffusion</a>
260
+ </td>
261
+ <td style="white-space: pre;">─────►</td>
262
+ <td>
263
+ <a href="https://github.com/facebookresearch/vggsfm">VGGSfM</a> ──►
264
+ <a href="https://github.com/facebookresearch/vggt">VGGT</a>
265
+ </td>
266
+ </tr>
267
+ <tr>
268
+ <td align="left">
269
+ <a href="https://github.com/facebookresearch/co-tracker">CoTracker</a>
270
+ </td>
271
+ <td style="white-space: pre;">──┘</td>
272
+ <td></td>
273
+ </tr>
274
+ </table>
275
+
276
+
277
+ ## Acknowledgements
278
+
279
+ Thanks to these great repositories: [PoseDiffusion](https://github.com/facebookresearch/PoseDiffusion), [VGGSfM](https://github.com/facebookresearch/vggsfm), [CoTracker](https://github.com/facebookresearch/co-tracker), [DINOv2](https://github.com/facebookresearch/dinov2), [Dust3r](https://github.com/naver/dust3r), [Moge](https://github.com/microsoft/moge), [PyTorch3D](https://github.com/facebookresearch/pytorch3d), [Sky Segmentation](https://github.com/xiongzhu666/Sky-Segmentation-and-Post-processing), [Depth Anything V2](https://github.com/DepthAnything/Depth-Anything-V2), [Metric3D](https://github.com/YvanYin/Metric3D) and many other inspiring works in the community.
280
+
281
+ ## Checklist
282
+
283
+ - [ ] Release the training code
284
+ - [ ] Release VGGT-500M and VGGT-200M
285
+
286
+
287
+ ## License
288
+ See the [LICENSE](./LICENSE.txt) file for details about the license under which this code is made available.
demo_colmap.py ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ import random
8
+ import numpy as np
9
+ import glob
10
+ import os
11
+ import copy
12
+ import torch
13
+ import torch.nn.functional as F
14
+
15
+ # Configure CUDA settings
16
+ torch.backends.cudnn.enabled = True
17
+ torch.backends.cudnn.benchmark = True
18
+ torch.backends.cudnn.deterministic = False
19
+
20
+ import argparse
21
+ from pathlib import Path
22
+ import trimesh
23
+ import pycolmap
24
+
25
+
26
+ from vggt.models.vggt import VGGT
27
+ from vggt.utils.load_fn import load_and_preprocess_images_square
28
+ from vggt.utils.pose_enc import pose_encoding_to_extri_intri
29
+ from vggt.utils.geometry import unproject_depth_map_to_point_map
30
+ from vggt.utils.helper import create_pixel_coordinate_grid, randomly_limit_trues
31
+ from vggt.dependency.track_predict import predict_tracks
32
+ from vggt.dependency.np_to_pycolmap import batch_np_matrix_to_pycolmap, batch_np_matrix_to_pycolmap_wo_track
33
+
34
+
35
+ # TODO: add support for masks
36
+ # TODO: add iterative BA
37
+ # TODO: add support for radial distortion, which needs extra_params
38
+ # TODO: test with more cases
39
+ # TODO: test different camera types
40
+
41
+
42
+ def parse_args():
43
+ parser = argparse.ArgumentParser(description="VGGT Demo")
44
+ parser.add_argument("--scene_dir", type=str, required=True, help="Directory containing the scene images")
45
+ parser.add_argument("--seed", type=int, default=42, help="Random seed for reproducibility")
46
+ parser.add_argument("--use_ba", action="store_true", default=False, help="Use BA for reconstruction")
47
+ ######### BA parameters #########
48
+ parser.add_argument(
49
+ "--max_reproj_error", type=float, default=8.0, help="Maximum reprojection error for reconstruction"
50
+ )
51
+ parser.add_argument("--shared_camera", action="store_true", default=False, help="Use shared camera for all images")
52
+ parser.add_argument("--camera_type", type=str, default="SIMPLE_PINHOLE", help="Camera type for reconstruction")
53
+ parser.add_argument("--vis_thresh", type=float, default=0.2, help="Visibility threshold for tracks")
54
+ parser.add_argument("--query_frame_num", type=int, default=8, help="Number of frames to query")
55
+ parser.add_argument("--max_query_pts", type=int, default=4096, help="Maximum number of query points")
56
+ parser.add_argument(
57
+ "--fine_tracking", action="store_true", default=True, help="Use fine tracking (slower but more accurate)"
58
+ )
59
+ parser.add_argument(
60
+ "--conf_thres_value", type=float, default=5.0, help="Confidence threshold value for depth filtering (wo BA)"
61
+ )
62
+ return parser.parse_args()
63
+
64
+
65
+ def run_VGGT(model, images, dtype, resolution=518):
66
+ # images: [B, 3, H, W]
67
+
68
+ assert len(images.shape) == 4
69
+ assert images.shape[1] == 3
70
+
71
+ # hard-coded to use 518 for VGGT
72
+ images = F.interpolate(images, size=(resolution, resolution), mode="bilinear", align_corners=False)
73
+
74
+ with torch.no_grad():
75
+ with torch.cuda.amp.autocast(dtype=dtype):
76
+ images = images[None] # add batch dimension
77
+ aggregated_tokens_list, ps_idx = model.aggregator(images)
78
+
79
+ # Predict Cameras
80
+ pose_enc = model.camera_head(aggregated_tokens_list)[-1]
81
+ # Extrinsic and intrinsic matrices, following OpenCV convention (camera from world)
82
+ extrinsic, intrinsic = pose_encoding_to_extri_intri(pose_enc, images.shape[-2:])
83
+ # Predict Depth Maps
84
+ depth_map, depth_conf = model.depth_head(aggregated_tokens_list, images, ps_idx)
85
+
86
+ extrinsic = extrinsic.squeeze(0).cpu().numpy()
87
+ intrinsic = intrinsic.squeeze(0).cpu().numpy()
88
+ depth_map = depth_map.squeeze(0).cpu().numpy()
89
+ depth_conf = depth_conf.squeeze(0).cpu().numpy()
90
+ return extrinsic, intrinsic, depth_map, depth_conf
91
+
92
+
93
+ def demo_fn(args):
94
+ # Print configuration
95
+ print("Arguments:", vars(args))
96
+
97
+ # Set seed for reproducibility
98
+ np.random.seed(args.seed)
99
+ torch.manual_seed(args.seed)
100
+ random.seed(args.seed)
101
+ if torch.cuda.is_available():
102
+ torch.cuda.manual_seed(args.seed)
103
+ torch.cuda.manual_seed_all(args.seed) # for multi-GPU
104
+ print(f"Setting seed as: {args.seed}")
105
+
106
+ # Set device and dtype
107
+ dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] >= 8 else torch.float16
108
+ device = "cuda" if torch.cuda.is_available() else "cpu"
109
+ print(f"Using device: {device}")
110
+ print(f"Using dtype: {dtype}")
111
+
112
+ # Run VGGT for camera and depth estimation
113
+ model = VGGT()
114
+ _URL = "https://huggingface.co/facebook/VGGT-1B/resolve/main/model.pt"
115
+ model.load_state_dict(torch.hub.load_state_dict_from_url(_URL))
116
+ model.eval()
117
+ model = model.to(device)
118
+ print(f"Model loaded")
119
+
120
+ # Get image paths and preprocess them
121
+ image_dir = os.path.join(args.scene_dir, "images")
122
+ image_path_list = glob.glob(os.path.join(image_dir, "*"))
123
+ if len(image_path_list) == 0:
124
+ raise ValueError(f"No images found in {image_dir}")
125
+ base_image_path_list = [os.path.basename(path) for path in image_path_list]
126
+
127
+ # Load images and original coordinates
128
+ # Load Image in 1024, while running VGGT with 518
129
+ vggt_fixed_resolution = 518
130
+ img_load_resolution = 1024
131
+
132
+ images, original_coords = load_and_preprocess_images_square(image_path_list, img_load_resolution)
133
+ images = images.to(device)
134
+ original_coords = original_coords.to(device)
135
+ print(f"Loaded {len(images)} images from {image_dir}")
136
+
137
+ # Run VGGT to estimate camera and depth
138
+ # Run with 518x518 images
139
+ extrinsic, intrinsic, depth_map, depth_conf = run_VGGT(model, images, dtype, vggt_fixed_resolution)
140
+ points_3d = unproject_depth_map_to_point_map(depth_map, extrinsic, intrinsic)
141
+
142
+ if args.use_ba:
143
+ image_size = np.array(images.shape[-2:])
144
+ scale = img_load_resolution / vggt_fixed_resolution
145
+ shared_camera = args.shared_camera
146
+
147
+ with torch.cuda.amp.autocast(dtype=dtype):
148
+ # Predicting Tracks
149
+ # Using VGGSfM tracker instead of VGGT tracker for efficiency
150
+ # VGGT tracker requires multiple backbone runs to query different frames (this is a problem caused by the training process)
151
+ # Will be fixed in VGGT v2
152
+
153
+ # You can also change the pred_tracks to tracks from any other methods
154
+ # e.g., from COLMAP, from CoTracker, or by chaining 2D matches from Lightglue/LoFTR.
155
+ pred_tracks, pred_vis_scores, pred_confs, points_3d, points_rgb = predict_tracks(
156
+ images,
157
+ conf=depth_conf,
158
+ points_3d=points_3d,
159
+ masks=None,
160
+ max_query_pts=args.max_query_pts,
161
+ query_frame_num=args.query_frame_num,
162
+ keypoint_extractor="aliked+sp",
163
+ fine_tracking=args.fine_tracking,
164
+ )
165
+
166
+ torch.cuda.empty_cache()
167
+
168
+ # rescale the intrinsic matrix from 518 to 1024
169
+ intrinsic[:, :2, :] *= scale
170
+ track_mask = pred_vis_scores > args.vis_thresh
171
+
172
+ # TODO: radial distortion, iterative BA, masks
173
+ reconstruction, valid_track_mask = batch_np_matrix_to_pycolmap(
174
+ points_3d,
175
+ extrinsic,
176
+ intrinsic,
177
+ pred_tracks,
178
+ image_size,
179
+ masks=track_mask,
180
+ max_reproj_error=args.max_reproj_error,
181
+ shared_camera=shared_camera,
182
+ camera_type=args.camera_type,
183
+ points_rgb=points_rgb,
184
+ )
185
+
186
+ if reconstruction is None:
187
+ raise ValueError("No reconstruction can be built with BA")
188
+
189
+ # Bundle Adjustment
190
+ ba_options = pycolmap.BundleAdjustmentOptions()
191
+ pycolmap.bundle_adjustment(reconstruction, ba_options)
192
+
193
+ reconstruction_resolution = img_load_resolution
194
+ else:
195
+ conf_thres_value = args.conf_thres_value
196
+ max_points_for_colmap = 100000 # randomly sample 3D points
197
+ shared_camera = False # in the feedforward manner, we do not support shared camera
198
+ camera_type = "PINHOLE" # in the feedforward manner, we only support PINHOLE camera
199
+
200
+ image_size = np.array([vggt_fixed_resolution, vggt_fixed_resolution])
201
+ num_frames, height, width, _ = points_3d.shape
202
+
203
+ points_rgb = F.interpolate(
204
+ images, size=(vggt_fixed_resolution, vggt_fixed_resolution), mode="bilinear", align_corners=False
205
+ )
206
+ points_rgb = (points_rgb.cpu().numpy() * 255).astype(np.uint8)
207
+ points_rgb = points_rgb.transpose(0, 2, 3, 1)
208
+
209
+ # (S, H, W, 3), with x, y coordinates and frame indices
210
+ points_xyf = create_pixel_coordinate_grid(num_frames, height, width)
211
+
212
+ conf_mask = depth_conf >= conf_thres_value
213
+ # at most writing 100000 3d points to colmap reconstruction object
214
+ conf_mask = randomly_limit_trues(conf_mask, max_points_for_colmap)
215
+
216
+ points_3d = points_3d[conf_mask]
217
+ points_xyf = points_xyf[conf_mask]
218
+ points_rgb = points_rgb[conf_mask]
219
+
220
+ print("Converting to COLMAP format")
221
+ reconstruction = batch_np_matrix_to_pycolmap_wo_track(
222
+ points_3d,
223
+ points_xyf,
224
+ points_rgb,
225
+ extrinsic,
226
+ intrinsic,
227
+ image_size,
228
+ shared_camera=shared_camera,
229
+ camera_type=camera_type,
230
+ )
231
+
232
+ reconstruction_resolution = vggt_fixed_resolution
233
+
234
+ reconstruction = rename_colmap_recons_and_rescale_camera(
235
+ reconstruction,
236
+ base_image_path_list,
237
+ original_coords.cpu().numpy(),
238
+ img_size=reconstruction_resolution,
239
+ shift_point2d_to_original_res=True,
240
+ shared_camera=shared_camera,
241
+ )
242
+
243
+ print(f"Saving reconstruction to {args.scene_dir}/sparse")
244
+ sparse_reconstruction_dir = os.path.join(args.scene_dir, "sparse")
245
+ os.makedirs(sparse_reconstruction_dir, exist_ok=True)
246
+ reconstruction.write(sparse_reconstruction_dir)
247
+
248
+ # Save point cloud for fast visualization
249
+ trimesh.PointCloud(points_3d, colors=points_rgb).export(os.path.join(args.scene_dir, "sparse/points.ply"))
250
+
251
+ return True
252
+
253
+
254
+ def rename_colmap_recons_and_rescale_camera(
255
+ reconstruction, image_paths, original_coords, img_size, shift_point2d_to_original_res=False, shared_camera=False
256
+ ):
257
+ rescale_camera = True
258
+
259
+ for pyimageid in reconstruction.images:
260
+ # Reshaped the padded&resized image to the original size
261
+ # Rename the images to the original names
262
+ pyimage = reconstruction.images[pyimageid]
263
+ pycamera = reconstruction.cameras[pyimage.camera_id]
264
+ pyimage.name = image_paths[pyimageid - 1]
265
+
266
+ if rescale_camera:
267
+ # Rescale the camera parameters
268
+ pred_params = copy.deepcopy(pycamera.params)
269
+
270
+ real_image_size = original_coords[pyimageid - 1, -2:]
271
+ resize_ratio = max(real_image_size) / img_size
272
+ pred_params = pred_params * resize_ratio
273
+ real_pp = real_image_size / 2
274
+ pred_params[-2:] = real_pp # center of the image
275
+
276
+ pycamera.params = pred_params
277
+ pycamera.width = real_image_size[0]
278
+ pycamera.height = real_image_size[1]
279
+
280
+ if shift_point2d_to_original_res:
281
+ # Also shift the point2D to original resolution
282
+ top_left = original_coords[pyimageid - 1, :2]
283
+
284
+ for point2D in pyimage.points2D:
285
+ point2D.xy = (point2D.xy - top_left) * resize_ratio
286
+
287
+ if shared_camera:
288
+ # If shared_camera, all images share the same camera
289
+ # no need to rescale any more
290
+ rescale_camera = False
291
+
292
+ return reconstruction
293
+
294
+
295
+ if __name__ == "__main__":
296
+ args = parse_args()
297
+ with torch.no_grad():
298
+ demo_fn(args)
299
+
300
+
301
+ # Work in Progress (WIP)
302
+
303
+ """
304
+ VGGT Runner Script
305
+ =================
306
+
307
+ A script to run the VGGT model for 3D reconstruction from image sequences.
308
+
309
+ Directory Structure
310
+ ------------------
311
+ Input:
312
+ input_folder/
313
+ └── images/ # Source images for reconstruction
314
+
315
+ Output:
316
+ output_folder/
317
+ ├── images/
318
+ ├── sparse/ # Reconstruction results
319
+ │ ├── cameras.bin # Camera parameters (COLMAP format)
320
+ │ ├── images.bin # Pose for each image (COLMAP format)
321
+ │ ├── points3D.bin # 3D points (COLMAP format)
322
+ │ └── points.ply # Point cloud visualization file
323
+ └── visuals/ # Visualization outputs TODO
324
+
325
+ Key Features
326
+ -----------
327
+ • Dual-mode Support: Run reconstructions using either VGGT or VGGT+BA
328
+ • Resolution Preservation: Maintains original image resolution in camera parameters and tracks
329
+ • COLMAP Compatibility: Exports results in standard COLMAP sparse reconstruction format
330
+ """
demo_gradio.py ADDED
@@ -0,0 +1,690 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ import os
8
+ import cv2
9
+ import torch
10
+ import numpy as np
11
+ import gradio as gr
12
+ import sys
13
+ import shutil
14
+ from datetime import datetime
15
+ import glob
16
+ import gc
17
+ import time
18
+
19
+ sys.path.append("vggt/")
20
+
21
+ from visual_util import predictions_to_glb
22
+ from vggt.models.vggt import VGGT
23
+ from vggt.utils.load_fn import load_and_preprocess_images
24
+ from vggt.utils.pose_enc import pose_encoding_to_extri_intri
25
+ from vggt.utils.geometry import unproject_depth_map_to_point_map
26
+
27
+ device = "cuda" if torch.cuda.is_available() else "cpu"
28
+
29
+ print("Initializing and loading VGGT model...")
30
+ # model = VGGT.from_pretrained("facebook/VGGT-1B") # another way to load the model
31
+
32
+ model = VGGT()
33
+ _URL = "https://huggingface.co/facebook/VGGT-1B/resolve/main/model.pt"
34
+ model.load_state_dict(torch.hub.load_state_dict_from_url(_URL))
35
+
36
+
37
+ model.eval()
38
+ model = model.to(device)
39
+
40
+
41
+ # -------------------------------------------------------------------------
42
+ # 1) Core model inference
43
+ # -------------------------------------------------------------------------
44
+ def run_model(target_dir, model) -> dict:
45
+ """
46
+ Run the VGGT model on images in the 'target_dir/images' folder and return predictions.
47
+ """
48
+ print(f"Processing images from {target_dir}")
49
+
50
+ # Device check
51
+ device = "cuda" if torch.cuda.is_available() else "cpu"
52
+ if not torch.cuda.is_available():
53
+ raise ValueError("CUDA is not available. Check your environment.")
54
+
55
+ # Move model to device
56
+ model = model.to(device)
57
+ model.eval()
58
+
59
+ # Load and preprocess images
60
+ image_names = glob.glob(os.path.join(target_dir, "images", "*"))
61
+ image_names = sorted(image_names)
62
+ print(f"Found {len(image_names)} images")
63
+ if len(image_names) == 0:
64
+ raise ValueError("No images found. Check your upload.")
65
+
66
+ images = load_and_preprocess_images(image_names).to(device)
67
+ print(f"Preprocessed images shape: {images.shape}")
68
+
69
+ # Run inference
70
+ print("Running inference...")
71
+ dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] >= 8 else torch.float16
72
+
73
+ with torch.no_grad():
74
+ with torch.cuda.amp.autocast(dtype=dtype):
75
+ predictions = model(images)
76
+
77
+ # Convert pose encoding to extrinsic and intrinsic matrices
78
+ print("Converting pose encoding to extrinsic and intrinsic matrices...")
79
+ extrinsic, intrinsic = pose_encoding_to_extri_intri(predictions["pose_enc"], images.shape[-2:])
80
+ predictions["extrinsic"] = extrinsic
81
+ predictions["intrinsic"] = intrinsic
82
+
83
+ # Convert tensors to numpy
84
+ for key in predictions.keys():
85
+ if isinstance(predictions[key], torch.Tensor):
86
+ predictions[key] = predictions[key].cpu().numpy().squeeze(0) # remove batch dimension
87
+
88
+ # Generate world points from depth map
89
+ print("Computing world points from depth map...")
90
+ depth_map = predictions["depth"] # (S, H, W, 1)
91
+ world_points = unproject_depth_map_to_point_map(depth_map, predictions["extrinsic"], predictions["intrinsic"])
92
+ predictions["world_points_from_depth"] = world_points
93
+
94
+ # Clean up
95
+ torch.cuda.empty_cache()
96
+ return predictions
97
+
98
+
99
+ # -------------------------------------------------------------------------
100
+ # 2) Handle uploaded video/images --> produce target_dir + images
101
+ # -------------------------------------------------------------------------
102
+ def handle_uploads(input_video, input_images):
103
+ """
104
+ Create a new 'target_dir' + 'images' subfolder, and place user-uploaded
105
+ images or extracted frames from video into it. Return (target_dir, image_paths).
106
+ """
107
+ start_time = time.time()
108
+ gc.collect()
109
+ torch.cuda.empty_cache()
110
+
111
+ # Create a unique folder name
112
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
113
+ target_dir = f"input_images_{timestamp}"
114
+ target_dir_images = os.path.join(target_dir, "images")
115
+
116
+ # Clean up if somehow that folder already exists
117
+ if os.path.exists(target_dir):
118
+ shutil.rmtree(target_dir)
119
+ os.makedirs(target_dir)
120
+ os.makedirs(target_dir_images)
121
+
122
+ image_paths = []
123
+
124
+ # --- Handle images ---
125
+ if input_images is not None:
126
+ for file_data in input_images:
127
+ if isinstance(file_data, dict) and "name" in file_data:
128
+ file_path = file_data["name"]
129
+ else:
130
+ file_path = file_data
131
+ dst_path = os.path.join(target_dir_images, os.path.basename(file_path))
132
+ shutil.copy(file_path, dst_path)
133
+ image_paths.append(dst_path)
134
+
135
+ # --- Handle video ---
136
+ if input_video is not None:
137
+ if isinstance(input_video, dict) and "name" in input_video:
138
+ video_path = input_video["name"]
139
+ else:
140
+ video_path = input_video
141
+
142
+ vs = cv2.VideoCapture(video_path)
143
+ fps = vs.get(cv2.CAP_PROP_FPS)
144
+ frame_interval = int(fps * 1) # 1 frame/sec
145
+
146
+ count = 0
147
+ video_frame_num = 0
148
+ while True:
149
+ gotit, frame = vs.read()
150
+ if not gotit:
151
+ break
152
+ count += 1
153
+ if count % frame_interval == 0:
154
+ image_path = os.path.join(target_dir_images, f"{video_frame_num:06}.png")
155
+ cv2.imwrite(image_path, frame)
156
+ image_paths.append(image_path)
157
+ video_frame_num += 1
158
+
159
+ # Sort final images for gallery
160
+ image_paths = sorted(image_paths)
161
+
162
+ end_time = time.time()
163
+ print(f"Files copied to {target_dir_images}; took {end_time - start_time:.3f} seconds")
164
+ return target_dir, image_paths
165
+
166
+
167
+ # -------------------------------------------------------------------------
168
+ # 3) Update gallery on upload
169
+ # -------------------------------------------------------------------------
170
+ def update_gallery_on_upload(input_video, input_images):
171
+ """
172
+ Whenever user uploads or changes files, immediately handle them
173
+ and show in the gallery. Return (target_dir, image_paths).
174
+ If nothing is uploaded, returns "None" and empty list.
175
+ """
176
+ if not input_video and not input_images:
177
+ return None, None, None, None
178
+ target_dir, image_paths = handle_uploads(input_video, input_images)
179
+ return None, target_dir, image_paths, "Upload complete. Click 'Reconstruct' to begin 3D processing."
180
+
181
+
182
+ # -------------------------------------------------------------------------
183
+ # 4) Reconstruction: uses the target_dir plus any viz parameters
184
+ # -------------------------------------------------------------------------
185
+ def gradio_demo(
186
+ target_dir,
187
+ conf_thres=3.0,
188
+ frame_filter="All",
189
+ mask_black_bg=False,
190
+ mask_white_bg=False,
191
+ show_cam=True,
192
+ mask_sky=False,
193
+ prediction_mode="Pointmap Regression",
194
+ ):
195
+ """
196
+ Perform reconstruction using the already-created target_dir/images.
197
+ """
198
+ if not os.path.isdir(target_dir) or target_dir == "None":
199
+ return None, "No valid target directory found. Please upload first.", None, None
200
+
201
+ start_time = time.time()
202
+ gc.collect()
203
+ torch.cuda.empty_cache()
204
+
205
+ # Prepare frame_filter dropdown
206
+ target_dir_images = os.path.join(target_dir, "images")
207
+ all_files = sorted(os.listdir(target_dir_images)) if os.path.isdir(target_dir_images) else []
208
+ all_files = [f"{i}: {filename}" for i, filename in enumerate(all_files)]
209
+ frame_filter_choices = ["All"] + all_files
210
+
211
+ print("Running run_model...")
212
+ with torch.no_grad():
213
+ predictions = run_model(target_dir, model)
214
+
215
+ # Save predictions
216
+ prediction_save_path = os.path.join(target_dir, "predictions.npz")
217
+ np.savez(prediction_save_path, **predictions)
218
+
219
+ # Handle None frame_filter
220
+ if frame_filter is None:
221
+ frame_filter = "All"
222
+
223
+ # Build a GLB file name
224
+ glbfile = os.path.join(
225
+ target_dir,
226
+ f"glbscene_{conf_thres}_{frame_filter.replace('.', '_').replace(':', '').replace(' ', '_')}_maskb{mask_black_bg}_maskw{mask_white_bg}_cam{show_cam}_sky{mask_sky}_pred{prediction_mode.replace(' ', '_')}.glb",
227
+ )
228
+
229
+ # Convert predictions to GLB
230
+ glbscene = predictions_to_glb(
231
+ predictions,
232
+ conf_thres=conf_thres,
233
+ filter_by_frames=frame_filter,
234
+ mask_black_bg=mask_black_bg,
235
+ mask_white_bg=mask_white_bg,
236
+ show_cam=show_cam,
237
+ mask_sky=mask_sky,
238
+ target_dir=target_dir,
239
+ prediction_mode=prediction_mode,
240
+ )
241
+ glbscene.export(file_obj=glbfile)
242
+
243
+ # Cleanup
244
+ del predictions
245
+ gc.collect()
246
+ torch.cuda.empty_cache()
247
+
248
+ end_time = time.time()
249
+ print(f"Total time: {end_time - start_time:.2f} seconds (including IO)")
250
+ log_msg = f"Reconstruction Success ({len(all_files)} frames). Waiting for visualization."
251
+
252
+ return glbfile, log_msg, gr.Dropdown(choices=frame_filter_choices, value=frame_filter, interactive=True)
253
+
254
+
255
+ # -------------------------------------------------------------------------
256
+ # 5) Helper functions for UI resets + re-visualization
257
+ # -------------------------------------------------------------------------
258
+ def clear_fields():
259
+ """
260
+ Clears the 3D viewer, the stored target_dir, and empties the gallery.
261
+ """
262
+ return None
263
+
264
+
265
+ def update_log():
266
+ """
267
+ Display a quick log message while waiting.
268
+ """
269
+ return "Loading and Reconstructing..."
270
+
271
+
272
+ def update_visualization(
273
+ target_dir, conf_thres, frame_filter, mask_black_bg, mask_white_bg, show_cam, mask_sky, prediction_mode, is_example
274
+ ):
275
+ """
276
+ Reload saved predictions from npz, create (or reuse) the GLB for new parameters,
277
+ and return it for the 3D viewer. If is_example == "True", skip.
278
+ """
279
+
280
+ # If it's an example click, skip as requested
281
+ if is_example == "True":
282
+ return None, "No reconstruction available. Please click the Reconstruct button first."
283
+
284
+ if not target_dir or target_dir == "None" or not os.path.isdir(target_dir):
285
+ return None, "No reconstruction available. Please click the Reconstruct button first."
286
+
287
+ predictions_path = os.path.join(target_dir, "predictions.npz")
288
+ if not os.path.exists(predictions_path):
289
+ return None, f"No reconstruction available at {predictions_path}. Please run 'Reconstruct' first."
290
+
291
+ key_list = [
292
+ "pose_enc",
293
+ "depth",
294
+ "depth_conf",
295
+ "world_points",
296
+ "world_points_conf",
297
+ "images",
298
+ "extrinsic",
299
+ "intrinsic",
300
+ "world_points_from_depth",
301
+ ]
302
+
303
+ loaded = np.load(predictions_path)
304
+ predictions = {key: np.array(loaded[key]) for key in key_list}
305
+
306
+ glbfile = os.path.join(
307
+ target_dir,
308
+ f"glbscene_{conf_thres}_{frame_filter.replace('.', '_').replace(':', '').replace(' ', '_')}_maskb{mask_black_bg}_maskw{mask_white_bg}_cam{show_cam}_sky{mask_sky}_pred{prediction_mode.replace(' ', '_')}.glb",
309
+ )
310
+
311
+ if not os.path.exists(glbfile):
312
+ glbscene = predictions_to_glb(
313
+ predictions,
314
+ conf_thres=conf_thres,
315
+ filter_by_frames=frame_filter,
316
+ mask_black_bg=mask_black_bg,
317
+ mask_white_bg=mask_white_bg,
318
+ show_cam=show_cam,
319
+ mask_sky=mask_sky,
320
+ target_dir=target_dir,
321
+ prediction_mode=prediction_mode,
322
+ )
323
+ glbscene.export(file_obj=glbfile)
324
+
325
+ return glbfile, "Updating Visualization"
326
+
327
+
328
+ # -------------------------------------------------------------------------
329
+ # Example images
330
+ # -------------------------------------------------------------------------
331
+
332
+ great_wall_video = "examples/videos/great_wall.mp4"
333
+ colosseum_video = "examples/videos/Colosseum.mp4"
334
+ room_video = "examples/videos/room.mp4"
335
+ kitchen_video = "examples/videos/kitchen.mp4"
336
+ fern_video = "examples/videos/fern.mp4"
337
+ single_cartoon_video = "examples/videos/single_cartoon.mp4"
338
+ single_oil_painting_video = "examples/videos/single_oil_painting.mp4"
339
+ pyramid_video = "examples/videos/pyramid.mp4"
340
+
341
+
342
+ # -------------------------------------------------------------------------
343
+ # 6) Build Gradio UI
344
+ # -------------------------------------------------------------------------
345
+ theme = gr.themes.Ocean()
346
+ theme.set(
347
+ checkbox_label_background_fill_selected="*button_primary_background_fill",
348
+ checkbox_label_text_color_selected="*button_primary_text_color",
349
+ )
350
+
351
+ with gr.Blocks(
352
+ theme=theme,
353
+ css="""
354
+ .custom-log * {
355
+ font-style: italic;
356
+ font-size: 22px !important;
357
+ background-image: linear-gradient(120deg, #0ea5e9 0%, #6ee7b7 60%, #34d399 100%);
358
+ -webkit-background-clip: text;
359
+ background-clip: text;
360
+ font-weight: bold !important;
361
+ color: transparent !important;
362
+ text-align: center !important;
363
+ }
364
+
365
+ .example-log * {
366
+ font-style: italic;
367
+ font-size: 16px !important;
368
+ background-image: linear-gradient(120deg, #0ea5e9 0%, #6ee7b7 60%, #34d399 100%);
369
+ -webkit-background-clip: text;
370
+ background-clip: text;
371
+ color: transparent !important;
372
+ }
373
+
374
+ #my_radio .wrap {
375
+ display: flex;
376
+ flex-wrap: nowrap;
377
+ justify-content: center;
378
+ align-items: center;
379
+ }
380
+
381
+ #my_radio .wrap label {
382
+ display: flex;
383
+ width: 50%;
384
+ justify-content: center;
385
+ align-items: center;
386
+ margin: 0;
387
+ padding: 10px 0;
388
+ box-sizing: border-box;
389
+ }
390
+ """,
391
+ ) as demo:
392
+ # Instead of gr.State, we use a hidden Textbox:
393
+ is_example = gr.Textbox(label="is_example", visible=False, value="None")
394
+ num_images = gr.Textbox(label="num_images", visible=False, value="None")
395
+
396
+ gr.HTML(
397
+ """
398
+ <h1>🏛️ VGGT: Visual Geometry Grounded Transformer</h1>
399
+ <p>
400
+ <a href="https://github.com/facebookresearch/vggt">🐙 GitHub Repository</a> |
401
+ <a href="#">Project Page</a>
402
+ </p>
403
+
404
+ <div style="font-size: 16px; line-height: 1.5;">
405
+ <p>Upload a video or a set of images to create a 3D reconstruction of a scene or object. VGGT takes these images and generates a 3D point cloud, along with estimated camera poses.</p>
406
+
407
+ <h3>Getting Started:</h3>
408
+ <ol>
409
+ <li><strong>Upload Your Data:</strong> Use the "Upload Video" or "Upload Images" buttons on the left to provide your input. Videos will be automatically split into individual frames (one frame per second).</li>
410
+ <li><strong>Preview:</strong> Your uploaded images will appear in the gallery on the left.</li>
411
+ <li><strong>Reconstruct:</strong> Click the "Reconstruct" button to start the 3D reconstruction process.</li>
412
+ <li><strong>Visualize:</strong> The 3D reconstruction will appear in the viewer on the right. You can rotate, pan, and zoom to explore the model, and download the GLB file. Note the visualization of 3D points may be slow for a large number of input images.</li>
413
+ <li>
414
+ <strong>Adjust Visualization (Optional):</strong>
415
+ After reconstruction, you can fine-tune the visualization using the options below
416
+ <details style="display:inline;">
417
+ <summary style="display:inline;">(<strong>click to expand</strong>):</summary>
418
+ <ul>
419
+ <li><em>Confidence Threshold:</em> Adjust the filtering of points based on confidence.</li>
420
+ <li><em>Show Points from Frame:</em> Select specific frames to display in the point cloud.</li>
421
+ <li><em>Show Camera:</em> Toggle the display of estimated camera positions.</li>
422
+ <li><em>Filter Sky / Filter Black Background:</em> Remove sky or black-background points.</li>
423
+ <li><em>Select a Prediction Mode:</em> Choose between "Depthmap and Camera Branch" or "Pointmap Branch."</li>
424
+ </ul>
425
+ </details>
426
+ </li>
427
+ </ol>
428
+ <p><strong style="color: #0ea5e9;">Please note:</strong> <span style="color: #0ea5e9; font-weight: bold;">VGGT typically reconstructs a scene in less than 1 second. However, visualizing 3D points may take tens of seconds due to third-party rendering, which are independent of VGGT's processing time. </span></p>
429
+ </div>
430
+ """
431
+ )
432
+
433
+ target_dir_output = gr.Textbox(label="Target Dir", visible=False, value="None")
434
+
435
+ with gr.Row():
436
+ with gr.Column(scale=2):
437
+ input_video = gr.Video(label="Upload Video", interactive=True)
438
+ input_images = gr.File(file_count="multiple", label="Upload Images", interactive=True)
439
+
440
+ image_gallery = gr.Gallery(
441
+ label="Preview",
442
+ columns=4,
443
+ height="300px",
444
+ show_download_button=True,
445
+ object_fit="contain",
446
+ preview=True,
447
+ )
448
+
449
+ with gr.Column(scale=4):
450
+ with gr.Column():
451
+ gr.Markdown("**3D Reconstruction (Point Cloud and Camera Poses)**")
452
+ log_output = gr.Markdown(
453
+ "Please upload a video or images, then click Reconstruct.", elem_classes=["custom-log"]
454
+ )
455
+ reconstruction_output = gr.Model3D(height=520, zoom_speed=0.5, pan_speed=0.5)
456
+
457
+ with gr.Row():
458
+ submit_btn = gr.Button("Reconstruct", scale=1, variant="primary")
459
+ clear_btn = gr.ClearButton(
460
+ [input_video, input_images, reconstruction_output, log_output, target_dir_output, image_gallery],
461
+ scale=1,
462
+ )
463
+
464
+ with gr.Row():
465
+ prediction_mode = gr.Radio(
466
+ ["Depthmap and Camera Branch", "Pointmap Branch"],
467
+ label="Select a Prediction Mode",
468
+ value="Depthmap and Camera Branch",
469
+ scale=1,
470
+ elem_id="my_radio",
471
+ )
472
+
473
+ with gr.Row():
474
+ conf_thres = gr.Slider(minimum=0, maximum=100, value=50, step=0.1, label="Confidence Threshold (%)")
475
+ frame_filter = gr.Dropdown(choices=["All"], value="All", label="Show Points from Frame")
476
+ with gr.Column():
477
+ show_cam = gr.Checkbox(label="Show Camera", value=True)
478
+ mask_sky = gr.Checkbox(label="Filter Sky", value=False)
479
+ mask_black_bg = gr.Checkbox(label="Filter Black Background", value=False)
480
+ mask_white_bg = gr.Checkbox(label="Filter White Background", value=False)
481
+
482
+ # ---------------------- Examples section ----------------------
483
+ examples = [
484
+ [colosseum_video, "22", None, 20.0, False, False, True, False, "Depthmap and Camera Branch", "True"],
485
+ [pyramid_video, "30", None, 35.0, False, False, True, False, "Depthmap and Camera Branch", "True"],
486
+ [single_cartoon_video, "1", None, 15.0, False, False, True, False, "Depthmap and Camera Branch", "True"],
487
+ [single_oil_painting_video, "1", None, 20.0, False, False, True, True, "Depthmap and Camera Branch", "True"],
488
+ [room_video, "8", None, 5.0, False, False, True, False, "Depthmap and Camera Branch", "True"],
489
+ [kitchen_video, "25", None, 50.0, False, False, True, False, "Depthmap and Camera Branch", "True"],
490
+ [fern_video, "20", None, 45.0, False, False, True, False, "Depthmap and Camera Branch", "True"],
491
+ ]
492
+
493
+ def example_pipeline(
494
+ input_video,
495
+ num_images_str,
496
+ input_images,
497
+ conf_thres,
498
+ mask_black_bg,
499
+ mask_white_bg,
500
+ show_cam,
501
+ mask_sky,
502
+ prediction_mode,
503
+ is_example_str,
504
+ ):
505
+ """
506
+ 1) Copy example images to new target_dir
507
+ 2) Reconstruct
508
+ 3) Return model3D + logs + new_dir + updated dropdown + gallery
509
+ We do NOT return is_example. It's just an input.
510
+ """
511
+ target_dir, image_paths = handle_uploads(input_video, input_images)
512
+ # Always use "All" for frame_filter in examples
513
+ frame_filter = "All"
514
+ glbfile, log_msg, dropdown = gradio_demo(
515
+ target_dir, conf_thres, frame_filter, mask_black_bg, mask_white_bg, show_cam, mask_sky, prediction_mode
516
+ )
517
+ return glbfile, log_msg, target_dir, dropdown, image_paths
518
+
519
+ gr.Markdown("Click any row to load an example.", elem_classes=["example-log"])
520
+
521
+ gr.Examples(
522
+ examples=examples,
523
+ inputs=[
524
+ input_video,
525
+ num_images,
526
+ input_images,
527
+ conf_thres,
528
+ mask_black_bg,
529
+ mask_white_bg,
530
+ show_cam,
531
+ mask_sky,
532
+ prediction_mode,
533
+ is_example,
534
+ ],
535
+ outputs=[reconstruction_output, log_output, target_dir_output, frame_filter, image_gallery],
536
+ fn=example_pipeline,
537
+ cache_examples=False,
538
+ examples_per_page=50,
539
+ )
540
+
541
+ # -------------------------------------------------------------------------
542
+ # "Reconstruct" button logic:
543
+ # - Clear fields
544
+ # - Update log
545
+ # - gradio_demo(...) with the existing target_dir
546
+ # - Then set is_example = "False"
547
+ # -------------------------------------------------------------------------
548
+ submit_btn.click(fn=clear_fields, inputs=[], outputs=[reconstruction_output]).then(
549
+ fn=update_log, inputs=[], outputs=[log_output]
550
+ ).then(
551
+ fn=gradio_demo,
552
+ inputs=[
553
+ target_dir_output,
554
+ conf_thres,
555
+ frame_filter,
556
+ mask_black_bg,
557
+ mask_white_bg,
558
+ show_cam,
559
+ mask_sky,
560
+ prediction_mode,
561
+ ],
562
+ outputs=[reconstruction_output, log_output, frame_filter],
563
+ ).then(
564
+ fn=lambda: "False", inputs=[], outputs=[is_example] # set is_example to "False"
565
+ )
566
+
567
+ # -------------------------------------------------------------------------
568
+ # Real-time Visualization Updates
569
+ # -------------------------------------------------------------------------
570
+ conf_thres.change(
571
+ update_visualization,
572
+ [
573
+ target_dir_output,
574
+ conf_thres,
575
+ frame_filter,
576
+ mask_black_bg,
577
+ mask_white_bg,
578
+ show_cam,
579
+ mask_sky,
580
+ prediction_mode,
581
+ is_example,
582
+ ],
583
+ [reconstruction_output, log_output],
584
+ )
585
+ frame_filter.change(
586
+ update_visualization,
587
+ [
588
+ target_dir_output,
589
+ conf_thres,
590
+ frame_filter,
591
+ mask_black_bg,
592
+ mask_white_bg,
593
+ show_cam,
594
+ mask_sky,
595
+ prediction_mode,
596
+ is_example,
597
+ ],
598
+ [reconstruction_output, log_output],
599
+ )
600
+ mask_black_bg.change(
601
+ update_visualization,
602
+ [
603
+ target_dir_output,
604
+ conf_thres,
605
+ frame_filter,
606
+ mask_black_bg,
607
+ mask_white_bg,
608
+ show_cam,
609
+ mask_sky,
610
+ prediction_mode,
611
+ is_example,
612
+ ],
613
+ [reconstruction_output, log_output],
614
+ )
615
+ mask_white_bg.change(
616
+ update_visualization,
617
+ [
618
+ target_dir_output,
619
+ conf_thres,
620
+ frame_filter,
621
+ mask_black_bg,
622
+ mask_white_bg,
623
+ show_cam,
624
+ mask_sky,
625
+ prediction_mode,
626
+ is_example,
627
+ ],
628
+ [reconstruction_output, log_output],
629
+ )
630
+ show_cam.change(
631
+ update_visualization,
632
+ [
633
+ target_dir_output,
634
+ conf_thres,
635
+ frame_filter,
636
+ mask_black_bg,
637
+ mask_white_bg,
638
+ show_cam,
639
+ mask_sky,
640
+ prediction_mode,
641
+ is_example,
642
+ ],
643
+ [reconstruction_output, log_output],
644
+ )
645
+ mask_sky.change(
646
+ update_visualization,
647
+ [
648
+ target_dir_output,
649
+ conf_thres,
650
+ frame_filter,
651
+ mask_black_bg,
652
+ mask_white_bg,
653
+ show_cam,
654
+ mask_sky,
655
+ prediction_mode,
656
+ is_example,
657
+ ],
658
+ [reconstruction_output, log_output],
659
+ )
660
+ prediction_mode.change(
661
+ update_visualization,
662
+ [
663
+ target_dir_output,
664
+ conf_thres,
665
+ frame_filter,
666
+ mask_black_bg,
667
+ mask_white_bg,
668
+ show_cam,
669
+ mask_sky,
670
+ prediction_mode,
671
+ is_example,
672
+ ],
673
+ [reconstruction_output, log_output],
674
+ )
675
+
676
+ # -------------------------------------------------------------------------
677
+ # Auto-update gallery whenever user uploads or changes their files
678
+ # -------------------------------------------------------------------------
679
+ input_video.change(
680
+ fn=update_gallery_on_upload,
681
+ inputs=[input_video, input_images],
682
+ outputs=[reconstruction_output, target_dir_output, image_gallery, log_output],
683
+ )
684
+ input_images.change(
685
+ fn=update_gallery_on_upload,
686
+ inputs=[input_video, input_images],
687
+ outputs=[reconstruction_output, target_dir_output, image_gallery, log_output],
688
+ )
689
+
690
+ demo.queue(max_size=20).launch(show_error=True, share=True)
demo_viser.py ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ import os
8
+ import glob
9
+ import time
10
+ import threading
11
+ import argparse
12
+ from typing import List, Optional
13
+
14
+ import numpy as np
15
+ import torch
16
+ from tqdm.auto import tqdm
17
+ import viser
18
+ import viser.transforms as viser_tf
19
+ import cv2
20
+
21
+
22
+ try:
23
+ import onnxruntime
24
+ except ImportError:
25
+ print("onnxruntime not found. Sky segmentation may not work.")
26
+
27
+ from visual_util import segment_sky, download_file_from_url
28
+ from vggt.models.vggt import VGGT
29
+ from vggt.utils.load_fn import load_and_preprocess_images
30
+ from vggt.utils.geometry import closed_form_inverse_se3, unproject_depth_map_to_point_map
31
+ from vggt.utils.pose_enc import pose_encoding_to_extri_intri
32
+
33
+
34
+ def viser_wrapper(
35
+ pred_dict: dict,
36
+ port: int = 8080,
37
+ init_conf_threshold: float = 50.0, # represents percentage (e.g., 50 means filter lowest 50%)
38
+ use_point_map: bool = False,
39
+ background_mode: bool = False,
40
+ mask_sky: bool = False,
41
+ image_folder: str = None,
42
+ ):
43
+ """
44
+ Visualize predicted 3D points and camera poses with viser.
45
+
46
+ Args:
47
+ pred_dict (dict):
48
+ {
49
+ "images": (S, 3, H, W) - Input images,
50
+ "world_points": (S, H, W, 3),
51
+ "world_points_conf": (S, H, W),
52
+ "depth": (S, H, W, 1),
53
+ "depth_conf": (S, H, W),
54
+ "extrinsic": (S, 3, 4),
55
+ "intrinsic": (S, 3, 3),
56
+ }
57
+ port (int): Port number for the viser server.
58
+ init_conf_threshold (float): Initial percentage of low-confidence points to filter out.
59
+ use_point_map (bool): Whether to visualize world_points or use depth-based points.
60
+ background_mode (bool): Whether to run the server in background thread.
61
+ mask_sky (bool): Whether to apply sky segmentation to filter out sky points.
62
+ image_folder (str): Path to the folder containing input images.
63
+ """
64
+ print(f"Starting viser server on port {port}")
65
+
66
+ server = viser.ViserServer(host="0.0.0.0", port=port)
67
+ server.gui.configure_theme(titlebar_content=None, control_layout="collapsible")
68
+
69
+ # Unpack prediction dict
70
+ images = pred_dict["images"] # (S, 3, H, W)
71
+ world_points_map = pred_dict["world_points"] # (S, H, W, 3)
72
+ conf_map = pred_dict["world_points_conf"] # (S, H, W)
73
+
74
+ depth_map = pred_dict["depth"] # (S, H, W, 1)
75
+ depth_conf = pred_dict["depth_conf"] # (S, H, W)
76
+
77
+ extrinsics_cam = pred_dict["extrinsic"] # (S, 3, 4)
78
+ intrinsics_cam = pred_dict["intrinsic"] # (S, 3, 3)
79
+
80
+ # Compute world points from depth if not using the precomputed point map
81
+ if not use_point_map:
82
+ world_points = unproject_depth_map_to_point_map(depth_map, extrinsics_cam, intrinsics_cam)
83
+ conf = depth_conf
84
+ else:
85
+ world_points = world_points_map
86
+ conf = conf_map
87
+
88
+ # Apply sky segmentation if enabled
89
+ if mask_sky and image_folder is not None:
90
+ conf = apply_sky_segmentation(conf, image_folder)
91
+
92
+ # Convert images from (S, 3, H, W) to (S, H, W, 3)
93
+ # Then flatten everything for the point cloud
94
+ colors = images.transpose(0, 2, 3, 1) # now (S, H, W, 3)
95
+ S, H, W, _ = world_points.shape
96
+
97
+ # Flatten
98
+ points = world_points.reshape(-1, 3)
99
+ colors_flat = (colors.reshape(-1, 3) * 255).astype(np.uint8)
100
+ conf_flat = conf.reshape(-1)
101
+
102
+ cam_to_world_mat = closed_form_inverse_se3(extrinsics_cam) # shape (S, 4, 4) typically
103
+ # For convenience, we store only (3,4) portion
104
+ cam_to_world = cam_to_world_mat[:, :3, :]
105
+
106
+ # Compute scene center and recenter
107
+ scene_center = np.mean(points, axis=0)
108
+ points_centered = points - scene_center
109
+ cam_to_world[..., -1] -= scene_center
110
+
111
+ # Store frame indices so we can filter by frame
112
+ frame_indices = np.repeat(np.arange(S), H * W)
113
+
114
+ # Build the viser GUI
115
+ gui_show_frames = server.gui.add_checkbox("Show Cameras", initial_value=True)
116
+
117
+ # Now the slider represents percentage of points to filter out
118
+ gui_points_conf = server.gui.add_slider(
119
+ "Confidence Percent", min=0, max=100, step=0.1, initial_value=init_conf_threshold
120
+ )
121
+
122
+ gui_frame_selector = server.gui.add_dropdown(
123
+ "Show Points from Frames", options=["All"] + [str(i) for i in range(S)], initial_value="All"
124
+ )
125
+
126
+ # Create the main point cloud handle
127
+ # Compute the threshold value as the given percentile
128
+ init_threshold_val = np.percentile(conf_flat, init_conf_threshold)
129
+ init_conf_mask = (conf_flat >= init_threshold_val) & (conf_flat > 0.1)
130
+ point_cloud = server.scene.add_point_cloud(
131
+ name="viser_pcd",
132
+ points=points_centered[init_conf_mask],
133
+ colors=colors_flat[init_conf_mask],
134
+ point_size=0.001,
135
+ point_shape="circle",
136
+ )
137
+
138
+ # We will store references to frames & frustums so we can toggle visibility
139
+ frames: List[viser.FrameHandle] = []
140
+ frustums: List[viser.CameraFrustumHandle] = []
141
+
142
+ def visualize_frames(extrinsics: np.ndarray, images_: np.ndarray) -> None:
143
+ """
144
+ Add camera frames and frustums to the scene.
145
+ extrinsics: (S, 3, 4)
146
+ images_: (S, 3, H, W)
147
+ """
148
+ # Clear any existing frames or frustums
149
+ for f in frames:
150
+ f.remove()
151
+ frames.clear()
152
+ for fr in frustums:
153
+ fr.remove()
154
+ frustums.clear()
155
+
156
+ # Optionally attach a callback that sets the viewpoint to the chosen camera
157
+ def attach_callback(frustum: viser.CameraFrustumHandle, frame: viser.FrameHandle) -> None:
158
+ @frustum.on_click
159
+ def _(_) -> None:
160
+ for client in server.get_clients().values():
161
+ client.camera.wxyz = frame.wxyz
162
+ client.camera.position = frame.position
163
+
164
+ img_ids = range(S)
165
+ for img_id in tqdm(img_ids):
166
+ cam2world_3x4 = extrinsics[img_id]
167
+ T_world_camera = viser_tf.SE3.from_matrix(cam2world_3x4)
168
+
169
+ # Add a small frame axis
170
+ frame_axis = server.scene.add_frame(
171
+ f"frame_{img_id}",
172
+ wxyz=T_world_camera.rotation().wxyz,
173
+ position=T_world_camera.translation(),
174
+ axes_length=0.05,
175
+ axes_radius=0.002,
176
+ origin_radius=0.002,
177
+ )
178
+ frames.append(frame_axis)
179
+
180
+ # Convert the image for the frustum
181
+ img = images_[img_id] # shape (3, H, W)
182
+ img = (img.transpose(1, 2, 0) * 255).astype(np.uint8)
183
+ h, w = img.shape[:2]
184
+
185
+ # If you want correct FOV from intrinsics, do something like:
186
+ # fx = intrinsics_cam[img_id, 0, 0]
187
+ # fov = 2 * np.arctan2(h/2, fx)
188
+ # For demonstration, we pick a simple approximate FOV:
189
+ fy = 1.1 * h
190
+ fov = 2 * np.arctan2(h / 2, fy)
191
+
192
+ # Add the frustum
193
+ frustum_cam = server.scene.add_camera_frustum(
194
+ f"frame_{img_id}/frustum", fov=fov, aspect=w / h, scale=0.05, image=img, line_width=1.0
195
+ )
196
+ frustums.append(frustum_cam)
197
+ attach_callback(frustum_cam, frame_axis)
198
+
199
+ def update_point_cloud() -> None:
200
+ """Update the point cloud based on current GUI selections."""
201
+ # Here we compute the threshold value based on the current percentage
202
+ current_percentage = gui_points_conf.value
203
+ threshold_val = np.percentile(conf_flat, current_percentage)
204
+
205
+ print(f"Threshold absolute value: {threshold_val}, percentage: {current_percentage}%")
206
+
207
+ conf_mask = (conf_flat >= threshold_val) & (conf_flat > 1e-5)
208
+
209
+ if gui_frame_selector.value == "All":
210
+ frame_mask = np.ones_like(conf_mask, dtype=bool)
211
+ else:
212
+ selected_idx = int(gui_frame_selector.value)
213
+ frame_mask = frame_indices == selected_idx
214
+
215
+ combined_mask = conf_mask & frame_mask
216
+ point_cloud.points = points_centered[combined_mask]
217
+ point_cloud.colors = colors_flat[combined_mask]
218
+
219
+ @gui_points_conf.on_update
220
+ def _(_) -> None:
221
+ update_point_cloud()
222
+
223
+ @gui_frame_selector.on_update
224
+ def _(_) -> None:
225
+ update_point_cloud()
226
+
227
+ @gui_show_frames.on_update
228
+ def _(_) -> None:
229
+ """Toggle visibility of camera frames and frustums."""
230
+ for f in frames:
231
+ f.visible = gui_show_frames.value
232
+ for fr in frustums:
233
+ fr.visible = gui_show_frames.value
234
+
235
+ # Add the camera frames to the scene
236
+ visualize_frames(cam_to_world, images)
237
+
238
+ print("Starting viser server...")
239
+ # If background_mode is True, spawn a daemon thread so the main thread can continue.
240
+ if background_mode:
241
+
242
+ def server_loop():
243
+ while True:
244
+ time.sleep(0.001)
245
+
246
+ thread = threading.Thread(target=server_loop, daemon=True)
247
+ thread.start()
248
+ else:
249
+ while True:
250
+ time.sleep(0.01)
251
+
252
+ return server
253
+
254
+
255
+ # Helper functions for sky segmentation
256
+
257
+
258
+ def apply_sky_segmentation(conf: np.ndarray, image_folder: str) -> np.ndarray:
259
+ """
260
+ Apply sky segmentation to confidence scores.
261
+
262
+ Args:
263
+ conf (np.ndarray): Confidence scores with shape (S, H, W)
264
+ image_folder (str): Path to the folder containing input images
265
+
266
+ Returns:
267
+ np.ndarray: Updated confidence scores with sky regions masked out
268
+ """
269
+ S, H, W = conf.shape
270
+ sky_masks_dir = image_folder.rstrip("/") + "_sky_masks"
271
+ os.makedirs(sky_masks_dir, exist_ok=True)
272
+
273
+ # Download skyseg.onnx if it doesn't exist
274
+ if not os.path.exists("skyseg.onnx"):
275
+ print("Downloading skyseg.onnx...")
276
+ download_file_from_url("https://huggingface.co/JianyuanWang/skyseg/resolve/main/skyseg.onnx", "skyseg.onnx")
277
+
278
+ skyseg_session = onnxruntime.InferenceSession("skyseg.onnx")
279
+ image_files = sorted(glob.glob(os.path.join(image_folder, "*")))
280
+ sky_mask_list = []
281
+
282
+ print("Generating sky masks...")
283
+ for i, image_path in enumerate(tqdm(image_files[:S])): # Limit to the number of images in the batch
284
+ image_name = os.path.basename(image_path)
285
+ mask_filepath = os.path.join(sky_masks_dir, image_name)
286
+
287
+ if os.path.exists(mask_filepath):
288
+ sky_mask = cv2.imread(mask_filepath, cv2.IMREAD_GRAYSCALE)
289
+ else:
290
+ sky_mask = segment_sky(image_path, skyseg_session, mask_filepath)
291
+
292
+ # Resize mask to match H×W if needed
293
+ if sky_mask.shape[0] != H or sky_mask.shape[1] != W:
294
+ sky_mask = cv2.resize(sky_mask, (W, H))
295
+
296
+ sky_mask_list.append(sky_mask)
297
+
298
+ # Convert list to numpy array with shape S×H×W
299
+ sky_mask_array = np.array(sky_mask_list)
300
+ # Apply sky mask to confidence scores
301
+ sky_mask_binary = (sky_mask_array > 0.1).astype(np.float32)
302
+ conf = conf * sky_mask_binary
303
+
304
+ print("Sky segmentation applied successfully")
305
+ return conf
306
+
307
+
308
+ parser = argparse.ArgumentParser(description="VGGT demo with viser for 3D visualization")
309
+ parser.add_argument(
310
+ "--image_folder", type=str, default="examples/kitchen/images/", help="Path to folder containing images"
311
+ )
312
+ parser.add_argument("--use_point_map", action="store_true", help="Use point map instead of depth-based points")
313
+ parser.add_argument("--background_mode", action="store_true", help="Run the viser server in background mode")
314
+ parser.add_argument("--port", type=int, default=8080, help="Port number for the viser server")
315
+ parser.add_argument(
316
+ "--conf_threshold", type=float, default=25.0, help="Initial percentage of low-confidence points to filter out"
317
+ )
318
+ parser.add_argument("--mask_sky", action="store_true", help="Apply sky segmentation to filter out sky points")
319
+
320
+
321
+ def main():
322
+ """
323
+ Main function for the VGGT demo with viser for 3D visualization.
324
+
325
+ This function:
326
+ 1. Loads the VGGT model
327
+ 2. Processes input images from the specified folder
328
+ 3. Runs inference to generate 3D points and camera poses
329
+ 4. Optionally applies sky segmentation to filter out sky points
330
+ 5. Visualizes the results using viser
331
+
332
+ Command-line arguments:
333
+ --image_folder: Path to folder containing input images
334
+ --use_point_map: Use point map instead of depth-based points
335
+ --background_mode: Run the viser server in background mode
336
+ --port: Port number for the viser server
337
+ --conf_threshold: Initial percentage of low-confidence points to filter out
338
+ --mask_sky: Apply sky segmentation to filter out sky points
339
+ """
340
+ args = parser.parse_args()
341
+ device = "cuda" if torch.cuda.is_available() else "cpu"
342
+ print(f"Using device: {device}")
343
+
344
+ print("Initializing and loading VGGT model...")
345
+ # model = VGGT.from_pretrained("facebook/VGGT-1B")
346
+
347
+ model = VGGT()
348
+ _URL = "https://huggingface.co/facebook/VGGT-1B/resolve/main/model.pt"
349
+ model.load_state_dict(torch.hub.load_state_dict_from_url(_URL))
350
+
351
+ model.eval()
352
+ model = model.to(device)
353
+
354
+ # Use the provided image folder path
355
+ print(f"Loading images from {args.image_folder}...")
356
+ image_names = glob.glob(os.path.join(args.image_folder, "*"))
357
+ print(f"Found {len(image_names)} images")
358
+
359
+ images = load_and_preprocess_images(image_names).to(device)
360
+ print(f"Preprocessed images shape: {images.shape}")
361
+
362
+ print("Running inference...")
363
+ dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] >= 8 else torch.float16
364
+
365
+ with torch.no_grad():
366
+ with torch.cuda.amp.autocast(dtype=dtype):
367
+ predictions = model(images)
368
+
369
+ print("Converting pose encoding to extrinsic and intrinsic matrices...")
370
+ extrinsic, intrinsic = pose_encoding_to_extri_intri(predictions["pose_enc"], images.shape[-2:])
371
+ predictions["extrinsic"] = extrinsic
372
+ predictions["intrinsic"] = intrinsic
373
+
374
+ print("Processing model outputs...")
375
+ for key in predictions.keys():
376
+ if isinstance(predictions[key], torch.Tensor):
377
+ predictions[key] = predictions[key].cpu().numpy().squeeze(0) # remove batch dimension and convert to numpy
378
+
379
+ if args.use_point_map:
380
+ print("Visualizing 3D points from point map")
381
+ else:
382
+ print("Visualizing 3D points by unprojecting depth map by cameras")
383
+
384
+ if args.mask_sky:
385
+ print("Sky segmentation enabled - will filter out sky points")
386
+
387
+ print("Starting viser visualization...")
388
+
389
+ viser_server = viser_wrapper(
390
+ predictions,
391
+ port=args.port,
392
+ init_conf_threshold=args.conf_threshold,
393
+ use_point_map=args.use_point_map,
394
+ background_mode=args.background_mode,
395
+ mask_sky=args.mask_sky,
396
+ image_folder=args.image_folder,
397
+ )
398
+ print("Visualization complete")
399
+
400
+
401
+ if __name__ == "__main__":
402
+ main()
docs/package.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Alternative Installation Methods
2
+
3
+ This document explains how to install VGGT as a package using different package managers.
4
+
5
+ ## Prerequisites
6
+
7
+ Before installing VGGT as a package, you need to install PyTorch and torchvision. We don't list these as dependencies to avoid CUDA version mismatches. Install them first, with an example as:
8
+
9
+ ```bash
10
+ # install pytorch 2.3.1 with cuda 12.1
11
+ pip install torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu121
12
+ ```
13
+
14
+ ## Installation Options
15
+
16
+ ### Install with pip
17
+
18
+ The simplest way to install VGGT is using pip:
19
+
20
+ ```bash
21
+ pip install -e .
22
+ ```
23
+
24
+ ### Install and run with pixi
25
+
26
+ [Pixi](https://pixi.sh) is a package management tool for creating reproducible environments.
27
+
28
+ 1. First, [download and install pixi](https://pixi.sh/latest/get_started/)
29
+ 2. Then run:
30
+
31
+ ```bash
32
+ pixi run -e python demo_gradio.py
33
+ ```
34
+
35
+ ### Install and run with uv
36
+
37
+ [uv](https://docs.astral.sh/uv/) is a fast Python package installer and resolver.
38
+
39
+ 1. First, [install uv](https://docs.astral.sh/uv/getting-started/installation/)
40
+ 2. Then run:
41
+
42
+ ```bash
43
+ uv run --extra demo demo_gradio.py
44
+ ```
45
+
examples/demo.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from vggt.models.vggt import VGGT
3
+ from vggt.utils.load_fn import load_and_preprocess_images
4
+
5
+ device = "cuda" if torch.cuda.is_available() else "cpu"
6
+ # bfloat16 is supported on Ampere GPUs (Compute Capability 8.0+)
7
+ dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] >= 8 else torch.float16
8
+
9
+ # Initialize the model and load the pretrained weights.
10
+ # This will automatically download the model weights the first time it's run, which may take a while.
11
+ model = VGGT.from_pretrained("facebook/VGGT-1B").to(device)
12
+
13
+ # Load and preprocess example images (replace with your own image paths)
14
+ image_names = ["path/to/imageA.png", "path/to/imageB.png", "path/to/imageC.png"]
15
+ images = load_and_preprocess_images(image_names).to(device)
16
+
17
+ with torch.no_grad():
18
+ with torch.cuda.amp.autocast(dtype=dtype):
19
+ # Predict attributes including cameras, depth maps, and point maps.
20
+ predictions = model(images)
examples/kitchen/images/00.png ADDED

Git LFS Details

  • SHA256: 54527a575988094058cdc1975b421c48e0f446726473d0ac21ea55ecb24e96a7
  • Pointer size: 131 Bytes
  • Size of remote file: 691 kB
examples/kitchen/images/01.png ADDED

Git LFS Details

  • SHA256: 0ad4c6d74c16661ed427f8100124aaf53e7fd0577b32c362f13559dfad7027a7
  • Pointer size: 131 Bytes
  • Size of remote file: 726 kB
examples/kitchen/images/02.png ADDED

Git LFS Details

  • SHA256: 596bd54d26f889fc80cedee81d95dda709fa134d86ac199b6509337e413246d5
  • Pointer size: 131 Bytes
  • Size of remote file: 789 kB
examples/kitchen/images/03.png ADDED

Git LFS Details

  • SHA256: 78193756310d9abaf81fa28902cf0b284260a0a916b085a7c08a4723eead1dd6
  • Pointer size: 131 Bytes
  • Size of remote file: 828 kB
examples/kitchen/images/04.png ADDED

Git LFS Details

  • SHA256: ca551254002a318228e19e46982813f3e489828796e98547ff632043f3002f9d
  • Pointer size: 131 Bytes
  • Size of remote file: 724 kB
examples/kitchen/images/05.png ADDED

Git LFS Details

  • SHA256: a8dcd116d782d32b404d7e4aa69f462abbd048a0d8727440ec37f18cc4548ee4
  • Pointer size: 131 Bytes
  • Size of remote file: 759 kB
examples/kitchen/images/06.png ADDED

Git LFS Details

  • SHA256: 2fcc2b871c6fef6f3a3e0f06a3ffc1f0eee3e40afa2461f7c7c665057decb3e6
  • Pointer size: 131 Bytes
  • Size of remote file: 674 kB
examples/kitchen/images/07.png ADDED

Git LFS Details

  • SHA256: 28d21898de0e6370790839a40f7f45d84fbb3e6ff5809f0a0e14bd01bdef730e
  • Pointer size: 131 Bytes
  • Size of remote file: 856 kB
examples/kitchen/images/08.png ADDED

Git LFS Details

  • SHA256: 0137a2bb3eb3e691d8d8b1f8884a9c8f99748888b1db770091d7acdf35fe8efa
  • Pointer size: 131 Bytes
  • Size of remote file: 677 kB
examples/kitchen/images/09.png ADDED

Git LFS Details

  • SHA256: 1ab59c1ef85d8169b404463f01b7ae4d287da12677126b68a3dce407ca2b9077
  • Pointer size: 131 Bytes
  • Size of remote file: 797 kB
examples/kitchen/images/10.png ADDED

Git LFS Details

  • SHA256: f180cbf110bc65b89ad616328ad7d076dc3901a18def4b1337a134cdf65233a0
  • Pointer size: 131 Bytes
  • Size of remote file: 730 kB
examples/kitchen/images/11.png ADDED

Git LFS Details

  • SHA256: 781196eadae8d907928e877e073289c0998e2b9e513d4f7580e147d15d1ae571
  • Pointer size: 131 Bytes
  • Size of remote file: 799 kB
examples/kitchen/images/12.png ADDED

Git LFS Details

  • SHA256: dd59b24dc8962ba0fc7fbb37b53a6d76fec9730c74e7e3235a06902b250e7d44
  • Pointer size: 131 Bytes
  • Size of remote file: 707 kB
examples/kitchen/images/13.png ADDED

Git LFS Details

  • SHA256: b4cd39f22c766477bad741ff37a1ee5f71aecde8bb6762d869b4c9dca1ceacfb
  • Pointer size: 131 Bytes
  • Size of remote file: 755 kB
examples/kitchen/images/14.png ADDED

Git LFS Details

  • SHA256: 5df1f398efc144271e342d7b65447e022a100b93b3850a755fbc66aff5fca0f2
  • Pointer size: 131 Bytes
  • Size of remote file: 642 kB
examples/kitchen/images/15.png ADDED

Git LFS Details

  • SHA256: 325262829ddb11d1c7df1a8f1fef79a297332dad51870ab0d40a73f1dd6869b1
  • Pointer size: 131 Bytes
  • Size of remote file: 639 kB
examples/kitchen/images/16.png ADDED

Git LFS Details

  • SHA256: 9779a78d72fc25f2118a270f060afeacbcef149a4f012119ff041effa8727cbf
  • Pointer size: 131 Bytes
  • Size of remote file: 754 kB
examples/kitchen/images/17.png ADDED

Git LFS Details

  • SHA256: 2549f4f505ea021eebe0bf579b969b6c162d2dee18b0c8e9d7a3c043d200e45b
  • Pointer size: 131 Bytes
  • Size of remote file: 774 kB
examples/kitchen/images/18.png ADDED

Git LFS Details

  • SHA256: e1c21131c4732756d5774dd732af86c1d39dea96fd2d613afd570633b3a76ef6
  • Pointer size: 131 Bytes
  • Size of remote file: 829 kB
examples/kitchen/images/19.png ADDED

Git LFS Details

  • SHA256: d17680e77c6cb326eb4604e29f9e532db34769ca20b938e944ab53e8bd3798e2
  • Pointer size: 131 Bytes
  • Size of remote file: 678 kB
examples/kitchen/images/20.png ADDED

Git LFS Details

  • SHA256: 5e9c835a0e0c1bc162a8bff6b93677c58cb53afaadca260b0ca2a388565b4cc2
  • Pointer size: 131 Bytes
  • Size of remote file: 718 kB
examples/kitchen/images/21.png ADDED

Git LFS Details

  • SHA256: 0747b2d1b44ef538a9aa40a067881ef9d3ed5cacbf954c926a2bdf5f29c114e6
  • Pointer size: 131 Bytes
  • Size of remote file: 787 kB
examples/kitchen/images/22.png ADDED

Git LFS Details

  • SHA256: 77a0014d7c7d5802ce23cda4e102759274fd8f4c150271a3b61cbb2fe33b69b6
  • Pointer size: 131 Bytes
  • Size of remote file: 675 kB
examples/kitchen/images/23.png ADDED

Git LFS Details

  • SHA256: 1a9415e9b8f08ff298829ffac779bb1e8dedccb3bf36060d59a7da2a35c4f790
  • Pointer size: 131 Bytes
  • Size of remote file: 652 kB
examples/kitchen/images/24.png ADDED

Git LFS Details

  • SHA256: 5199003307466bf4706a0898f139bf3590946f255d08c6b11d5aa9eede54c83a
  • Pointer size: 131 Bytes
  • Size of remote file: 800 kB
examples/llff_fern/images/000.png ADDED

Git LFS Details

  • SHA256: 47f447d31a84d53494045087cbb8a40b877a68a76f549af14f6bb6f490a5b05d
  • Pointer size: 131 Bytes
  • Size of remote file: 671 kB
examples/llff_fern/images/001.png ADDED

Git LFS Details

  • SHA256: 05402df1d7247e794768461571c188737dcae5fcb34400990f5751244a3e41c0
  • Pointer size: 131 Bytes
  • Size of remote file: 666 kB
examples/llff_fern/images/002.png ADDED

Git LFS Details

  • SHA256: e17135aa9b506fac24a9529ee56c37ef5a52c55498998d3de64cf3e46210dccc
  • Pointer size: 131 Bytes
  • Size of remote file: 652 kB
examples/llff_fern/images/003.png ADDED

Git LFS Details

  • SHA256: 3285c7cc6b4b75703a68f510072c5eca81cff9b983044426cbe2ca27d4e526c5
  • Pointer size: 131 Bytes
  • Size of remote file: 653 kB
examples/llff_fern/images/004.png ADDED

Git LFS Details

  • SHA256: 9976282206f9aff0fc3eaa3daa182ba93e0c6734c69bdf31f40989641b4f8fea
  • Pointer size: 131 Bytes
  • Size of remote file: 609 kB
examples/llff_fern/images/005.png ADDED

Git LFS Details

  • SHA256: e7ce2bcabcd2b2972c505e2649eb0f5b9efb30adcd455d93f5014370d53f2653
  • Pointer size: 131 Bytes
  • Size of remote file: 633 kB
examples/llff_fern/images/006.png ADDED

Git LFS Details

  • SHA256: 57dfa176d28662655adda9c0c04d6949424ddb3c702f533ddb332543dd1dcbdb
  • Pointer size: 131 Bytes
  • Size of remote file: 634 kB
examples/llff_fern/images/007.png ADDED

Git LFS Details

  • SHA256: da42e3dd198bc0951591b2a5e41bb15fbff18c2aef194d17a6acbf128487749e
  • Pointer size: 131 Bytes
  • Size of remote file: 632 kB
examples/llff_fern/images/008.png ADDED

Git LFS Details

  • SHA256: a8b8ac9860697b9cb1bfe41b358b03aef7a97ecb2fa9af61bc6e11210d99e8be
  • Pointer size: 131 Bytes
  • Size of remote file: 633 kB
examples/llff_fern/images/009.png ADDED

Git LFS Details

  • SHA256: beb825c8fee0b21801bca59ddddf65e560bd87fdc6823ec733cb8e6be05002c9
  • Pointer size: 131 Bytes
  • Size of remote file: 640 kB
examples/llff_fern/images/010.png ADDED

Git LFS Details

  • SHA256: 390054ae2969ce5ed0e8ed9b9c0501c527028b565e18807e0acd5d62a4627dae
  • Pointer size: 131 Bytes
  • Size of remote file: 637 kB
examples/llff_fern/images/011.png ADDED

Git LFS Details

  • SHA256: a3875f648038011549183d4c6a273be3d75e868e7f4971b474089121acbf8d52
  • Pointer size: 131 Bytes
  • Size of remote file: 618 kB
examples/llff_fern/images/012.png ADDED

Git LFS Details

  • SHA256: e003aa530890edaf01a34701e0a83f21d90d41e36e80b91dc5aba9a055a72063
  • Pointer size: 131 Bytes
  • Size of remote file: 647 kB