lvsm-pytorch 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lvsm_pytorch-0.0.1/.github/workflows/python-publish.yml +36 -0
- lvsm_pytorch-0.0.1/.gitignore +162 -0
- lvsm_pytorch-0.0.1/LICENSE +21 -0
- lvsm_pytorch-0.0.1/PKG-INFO +111 -0
- lvsm_pytorch-0.0.1/README.md +66 -0
- lvsm_pytorch-0.0.1/lvsm-finding.png +0 -0
- lvsm_pytorch-0.0.1/lvsm.png +0 -0
- lvsm_pytorch-0.0.1/lvsm_pytorch/__init__.py +1 -0
- lvsm_pytorch-0.0.1/lvsm_pytorch/lvsm.py +96 -0
- lvsm_pytorch-0.0.1/lvsm_pytorch/tensor_typing.py +26 -0
- lvsm_pytorch-0.0.1/pyproject.toml +61 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# This workflow will upload a Python Package using Twine when a release is created
|
|
2
|
+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
|
|
3
|
+
|
|
4
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
+
# They are provided by a third-party and are governed by
|
|
6
|
+
# separate terms of service, privacy policy, and support
|
|
7
|
+
# documentation.
|
|
8
|
+
|
|
9
|
+
name: Upload Python Package
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
release:
|
|
13
|
+
types: [published]
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
deploy:
|
|
17
|
+
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v2
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
uses: actions/setup-python@v2
|
|
24
|
+
with:
|
|
25
|
+
python-version: '3.x'
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: |
|
|
28
|
+
python -m pip install --upgrade pip
|
|
29
|
+
pip install build
|
|
30
|
+
- name: Build package
|
|
31
|
+
run: python -m build
|
|
32
|
+
- name: Publish package
|
|
33
|
+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
|
|
34
|
+
with:
|
|
35
|
+
user: __token__
|
|
36
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# mypy
|
|
144
|
+
.mypy_cache/
|
|
145
|
+
.dmypy.json
|
|
146
|
+
dmypy.json
|
|
147
|
+
|
|
148
|
+
# Pyre type checker
|
|
149
|
+
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
#.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Phil Wang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: lvsm-pytorch
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: LVSM - Pytorch
|
|
5
|
+
Project-URL: Homepage, https://pypi.org/project/lvsm-pytorch/
|
|
6
|
+
Project-URL: Repository, https://github.com/lucidrains/lvsm-pytorch
|
|
7
|
+
Author-email: Phil Wang <lucidrains@gmail.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2024 Phil Wang
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: artificial intelligence,attention mechanism,deep learning,novel view synthesis,transformers
|
|
31
|
+
Classifier: Development Status :: 4 - Beta
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
35
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
36
|
+
Requires-Python: >=3.9
|
|
37
|
+
Requires-Dist: einops>=0.8.0
|
|
38
|
+
Requires-Dist: jaxtyping
|
|
39
|
+
Requires-Dist: torch>=2.0
|
|
40
|
+
Requires-Dist: x-transformers>=1.42.5
|
|
41
|
+
Provides-Extra: examples
|
|
42
|
+
Provides-Extra: test
|
|
43
|
+
Requires-Dist: pytest; extra == 'test'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
<img src="./lvsm.png" width="500px"></img>
|
|
47
|
+
|
|
48
|
+
<img src="./lvsm-finding.png" width="400px"></img>
|
|
49
|
+
|
|
50
|
+
## LVSM - Pytorch (wip)
|
|
51
|
+
|
|
52
|
+
Implementation of [LVSM](https://haian-jin.github.io/projects/LVSM/), Large View Synthesis with Minimal 3d Inductive Bias, from Adobe Research
|
|
53
|
+
|
|
54
|
+
We will focus only on the Decoder-only architecture in this repository.
|
|
55
|
+
|
|
56
|
+
This paper lines up with <a href="https://openreview.net/forum?id=A8Vuf2e8y6">another</a> from ICLR 2025
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
$ pip install lvsm-pytorch
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import torch
|
|
68
|
+
from lvsm_pytorch.lvsm import LVSM
|
|
69
|
+
|
|
70
|
+
rays = torch.randn(2, 6, 256, 256)
|
|
71
|
+
images = torch.randn(2, 3, 256, 256)
|
|
72
|
+
|
|
73
|
+
target_rays = torch.randn(2, 6, 256, 256)
|
|
74
|
+
target_images = torch.randn(2, 3, 256, 256)
|
|
75
|
+
|
|
76
|
+
model = LVSM(
|
|
77
|
+
dim = 512,
|
|
78
|
+
patch_size = 32,
|
|
79
|
+
depth = 2,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
loss = model(
|
|
83
|
+
input_images = images,
|
|
84
|
+
input_rays = rays,
|
|
85
|
+
target_rays = target_rays,
|
|
86
|
+
target_images = target_images
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
loss.backward()
|
|
90
|
+
|
|
91
|
+
# after much training
|
|
92
|
+
|
|
93
|
+
pred_images = model(
|
|
94
|
+
input_images = images,
|
|
95
|
+
input_rays = rays,
|
|
96
|
+
target_rays = target_rays,
|
|
97
|
+
) # (2, 3, 256, 256)
|
|
98
|
+
|
|
99
|
+
assert pred_images.shape == target_images.shape
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Citations
|
|
103
|
+
|
|
104
|
+
```bibtex
|
|
105
|
+
@inproceedings{Jin2024LVSMAL,
|
|
106
|
+
title={LVSM: A Large View Synthesis Model with Minimal 3D Inductive Bias},
|
|
107
|
+
author={Haian Jin and Hanwen Jiang and Hao Tan and Kai Zhang and Sai Bi and Tianyuan Zhang and Fujun Luan and Noah Snavely and Zexiang Xu},
|
|
108
|
+
year={2024},
|
|
109
|
+
url={https://api.semanticscholar.org/CorpusID:273507016}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<img src="./lvsm.png" width="500px"></img>
|
|
2
|
+
|
|
3
|
+
<img src="./lvsm-finding.png" width="400px"></img>
|
|
4
|
+
|
|
5
|
+
## LVSM - Pytorch (wip)
|
|
6
|
+
|
|
7
|
+
Implementation of [LVSM](https://haian-jin.github.io/projects/LVSM/), Large View Synthesis with Minimal 3d Inductive Bias, from Adobe Research
|
|
8
|
+
|
|
9
|
+
We will focus only on the Decoder-only architecture in this repository.
|
|
10
|
+
|
|
11
|
+
This paper lines up with <a href="https://openreview.net/forum?id=A8Vuf2e8y6">another</a> from ICLR 2025
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ pip install lvsm-pytorch
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import torch
|
|
23
|
+
from lvsm_pytorch.lvsm import LVSM
|
|
24
|
+
|
|
25
|
+
rays = torch.randn(2, 6, 256, 256)
|
|
26
|
+
images = torch.randn(2, 3, 256, 256)
|
|
27
|
+
|
|
28
|
+
target_rays = torch.randn(2, 6, 256, 256)
|
|
29
|
+
target_images = torch.randn(2, 3, 256, 256)
|
|
30
|
+
|
|
31
|
+
model = LVSM(
|
|
32
|
+
dim = 512,
|
|
33
|
+
patch_size = 32,
|
|
34
|
+
depth = 2,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
loss = model(
|
|
38
|
+
input_images = images,
|
|
39
|
+
input_rays = rays,
|
|
40
|
+
target_rays = target_rays,
|
|
41
|
+
target_images = target_images
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
loss.backward()
|
|
45
|
+
|
|
46
|
+
# after much training
|
|
47
|
+
|
|
48
|
+
pred_images = model(
|
|
49
|
+
input_images = images,
|
|
50
|
+
input_rays = rays,
|
|
51
|
+
target_rays = target_rays,
|
|
52
|
+
) # (2, 3, 256, 256)
|
|
53
|
+
|
|
54
|
+
assert pred_images.shape == target_images.shape
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Citations
|
|
58
|
+
|
|
59
|
+
```bibtex
|
|
60
|
+
@inproceedings{Jin2024LVSMAL,
|
|
61
|
+
title={LVSM: A Large View Synthesis Model with Minimal 3D Inductive Bias},
|
|
62
|
+
author={Haian Jin and Hanwen Jiang and Hao Tan and Kai Zhang and Sai Bi and Tianyuan Zhang and Fujun Luan and Noah Snavely and Zexiang Xu},
|
|
63
|
+
year={2024},
|
|
64
|
+
url={https://api.semanticscholar.org/CorpusID:273507016}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from lvsm_pytorch.lvsm import LVSM
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from lvsm_pytorch.tensor_typing import Float
|
|
3
|
+
|
|
4
|
+
import torch
|
|
5
|
+
from torch import nn
|
|
6
|
+
from torch.nn import Module, ModuleList
|
|
7
|
+
import torch.nn.functional as F
|
|
8
|
+
|
|
9
|
+
from x_transformers import Encoder
|
|
10
|
+
|
|
11
|
+
from einops.layers.torch import Rearrange
|
|
12
|
+
from einops import rearrange, repeat, pack, unpack
|
|
13
|
+
|
|
14
|
+
# functions
|
|
15
|
+
|
|
16
|
+
def exists(v):
|
|
17
|
+
return v is not None
|
|
18
|
+
|
|
19
|
+
def default(v, d):
|
|
20
|
+
return v if exists(v) else d
|
|
21
|
+
|
|
22
|
+
# class
|
|
23
|
+
|
|
24
|
+
class LVSM(Module):
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
dim,
|
|
28
|
+
*,
|
|
29
|
+
patch_size,
|
|
30
|
+
depth = 12,
|
|
31
|
+
heads = 8,
|
|
32
|
+
dim_head = 64,
|
|
33
|
+
decoder_kwargs: dict = dict()
|
|
34
|
+
):
|
|
35
|
+
super().__init__()
|
|
36
|
+
|
|
37
|
+
self.input_to_patch_tokens = nn.Sequential(
|
|
38
|
+
Rearrange('b c (h p1) (w p2) -> b h w (c p1 p2)', p1 = patch_size, p2 = patch_size),
|
|
39
|
+
nn.Linear(9 * patch_size ** 2, dim)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
self.target_rays_to_patch_tokens = nn.Sequential(
|
|
43
|
+
Rearrange('b c (h p1) (w p2) -> b h w (c p1 p2)', p1 = patch_size, p2 = patch_size),
|
|
44
|
+
nn.Linear(6 * patch_size ** 2, dim)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
self.decoder = Encoder(
|
|
48
|
+
dim = dim,
|
|
49
|
+
depth = depth,
|
|
50
|
+
heads = heads,
|
|
51
|
+
attn_dim_head = dim_head,
|
|
52
|
+
**decoder_kwargs
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
self.target_unpatchify_to_image = nn.Sequential(
|
|
56
|
+
nn.Linear(dim, 3 * patch_size ** 2),
|
|
57
|
+
Rearrange('b h w (c p1 p2) -> b c (h p1) (w p2)', p1 = patch_size, p2 = patch_size, c = 3)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def forward(
|
|
61
|
+
self,
|
|
62
|
+
input_images: Float['b 3 h w'],
|
|
63
|
+
input_rays: Float['b 6 h w'],
|
|
64
|
+
target_rays: Float['b 6 h w'],
|
|
65
|
+
target_images: Float['b 3 h w'] | None = None
|
|
66
|
+
):
|
|
67
|
+
|
|
68
|
+
input_tokens = self.input_to_patch_tokens(torch.cat((input_images, input_rays), dim = 1))
|
|
69
|
+
|
|
70
|
+
target_tokens = self.target_rays_to_patch_tokens(target_rays)
|
|
71
|
+
|
|
72
|
+
input_tokens, _ = pack([input_tokens], 'b * d')
|
|
73
|
+
target_tokens, packed_height_width = pack([target_tokens], 'b * d')
|
|
74
|
+
|
|
75
|
+
tokens, packed_shape = pack([input_tokens, target_tokens], 'b * d')
|
|
76
|
+
|
|
77
|
+
# attention
|
|
78
|
+
|
|
79
|
+
tokens = self.decoder(tokens)
|
|
80
|
+
|
|
81
|
+
# unpack
|
|
82
|
+
|
|
83
|
+
input_tokens, target_tokens = unpack(tokens, packed_shape, 'b * d')
|
|
84
|
+
|
|
85
|
+
# project target tokens out
|
|
86
|
+
|
|
87
|
+
target_tokens, = unpack(target_tokens, packed_height_width, 'b * d')
|
|
88
|
+
|
|
89
|
+
# project back to image
|
|
90
|
+
|
|
91
|
+
pred_target_images = self.target_unpatchify_to_image(target_tokens)
|
|
92
|
+
|
|
93
|
+
if not exists(target_images):
|
|
94
|
+
return pred_target_images
|
|
95
|
+
|
|
96
|
+
return F.mse_loss(pred_target_images, target_images)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from torch import Tensor
|
|
2
|
+
|
|
3
|
+
from jaxtyping import (
|
|
4
|
+
Float,
|
|
5
|
+
Int,
|
|
6
|
+
Bool
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
# jaxtyping is a misnomer, works for pytorch
|
|
10
|
+
|
|
11
|
+
class TorchTyping:
|
|
12
|
+
def __init__(self, abstract_dtype):
|
|
13
|
+
self.abstract_dtype = abstract_dtype
|
|
14
|
+
|
|
15
|
+
def __getitem__(self, shapes: str):
|
|
16
|
+
return self.abstract_dtype[Tensor, shapes]
|
|
17
|
+
|
|
18
|
+
Float = TorchTyping(Float)
|
|
19
|
+
Int = TorchTyping(Int)
|
|
20
|
+
Bool = TorchTyping(Bool)
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
Float,
|
|
24
|
+
Int,
|
|
25
|
+
Bool
|
|
26
|
+
]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lvsm-pytorch"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "LVSM - Pytorch"
|
|
5
|
+
authors = [
|
|
6
|
+
{ name = "Phil Wang", email = "lucidrains@gmail.com" }
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">= 3.9"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
keywords = [
|
|
12
|
+
'artificial intelligence',
|
|
13
|
+
'deep learning',
|
|
14
|
+
'attention mechanism',
|
|
15
|
+
'transformers',
|
|
16
|
+
'novel view synthesis'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
classifiers=[
|
|
20
|
+
'Development Status :: 4 - Beta',
|
|
21
|
+
'Intended Audience :: Developers',
|
|
22
|
+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
|
|
23
|
+
'License :: OSI Approved :: MIT License',
|
|
24
|
+
'Programming Language :: Python :: 3.9',
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
dependencies = [
|
|
28
|
+
"einops>=0.8.0",
|
|
29
|
+
"jaxtyping",
|
|
30
|
+
"torch>=2.0",
|
|
31
|
+
"x-transformers>=1.42.5"
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://pypi.org/project/lvsm-pytorch/"
|
|
36
|
+
Repository = "https://github.com/lucidrains/lvsm-pytorch"
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
examples = []
|
|
40
|
+
test = [
|
|
41
|
+
"pytest"
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
pythonpath = [
|
|
46
|
+
"."
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["hatchling"]
|
|
51
|
+
build-backend = "hatchling.build"
|
|
52
|
+
|
|
53
|
+
[tool.rye]
|
|
54
|
+
managed = true
|
|
55
|
+
dev-dependencies = []
|
|
56
|
+
|
|
57
|
+
[tool.hatch.metadata]
|
|
58
|
+
allow-direct-references = true
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build.targets.wheel]
|
|
61
|
+
packages = ["lvsm_pytorch"]
|