Spaces:
Runtime error
Runtime error
refactor
Browse filesThis view is limited to 50 files because it contains too many changes. Β
See raw diff
- .gitignore +4 -0
- .idea/{3D_Zeroshot_Neural_Style_Transfer.iml β Thesis_3DStyleTransfer.iml} +1 -5
- .idea/misc.xml +4 -0
- .idea/modules.xml +1 -1
- .idea/vcs.xml +0 -1
- README.md +0 -13
- __pycache__/inference.cpython-38.pyc +0 -0
- app.py +0 -4
- configs/feature_baseline.yml +65 -0
- configs/llff.txt +0 -35
- configs/llff_feature.txt +0 -26
- configs/llff_style.txt +0 -28
- configs/nerf_synthetic.txt +0 -33
- configs/nerf_synthetic_feature.txt +0 -24
- configs/nerf_synthetic_style.txt +0 -22
- configs/style_baseline.yml +80 -0
- configs/style_inference.yml +80 -0
- dataLoader/__init__.py +0 -13
- dataLoader/__pycache__/__init__.cpython-38.pyc +0 -0
- dataLoader/__pycache__/nsvf.cpython-38.pyc +0 -0
- dataLoader/__pycache__/styleLoader.cpython-38.pyc +0 -0
- dataLoader/__pycache__/tankstemple.cpython-38.pyc +0 -0
- dataLoader/__pycache__/your_own_data.cpython-38.pyc +0 -0
- dataLoader/colmap2nerf.py +0 -305
- dataLoader/nsvf.py +0 -160
- dataLoader/styleLoader.py +0 -16
- dataLoader/tankstemple.py +0 -247
- dataLoader/your_own_data.py +0 -129
- extra/auto_run_paramsets.py +0 -207
- inference.py +75 -0
- main.py +75 -0
- models/__pycache__/__init__.cpython-38.pyc +0 -0
- opt.py +0 -153
- requirements.txt +12 -2
- scripts/test.sh +0 -5
- scripts/test_feature.sh +0 -10
- scripts/test_style.sh +0 -13
- scripts/train.sh +0 -1
- scripts/train_feature.sh +0 -1
- scripts/train_style.sh +0 -1
- {models β src}/__init__.py +0 -0
- src/__pycache__/__init__.cpython-38.pyc +0 -0
- src/callback/__init__.py +16 -0
- src/callback/__pycache__/__init__.cpython-38.pyc +0 -0
- src/dataset/__init__.py +10 -0
- src/dataset/__pycache__/__init__.cpython-38.pyc +0 -0
- dataLoader/__pycache__/blender.cpython-38.pyc β src/dataset/__pycache__/blender_dataset.cpython-38.pyc +0 -0
- dataLoader/__pycache__/llff.cpython-38.pyc β src/dataset/__pycache__/llff_dataset.cpython-38.pyc +0 -0
- {dataLoader β src/dataset}/__pycache__/ray_utils.cpython-38.pyc +0 -0
- src/dataset/__pycache__/style_dataset.cpython-38.pyc +0 -0
.gitignore
CHANGED
@@ -1,5 +1,9 @@
|
|
1 |
data/
|
2 |
checkpoints/
|
3 |
venv/
|
|
|
|
|
|
|
4 |
log_style/
|
5 |
|
|
|
|
1 |
data/
|
2 |
checkpoints/
|
3 |
venv/
|
4 |
+
log_feature/
|
5 |
+
log/
|
6 |
+
trex/
|
7 |
log_style/
|
8 |
|
9 |
+
|
.idea/{3D_Zeroshot_Neural_Style_Transfer.iml β Thesis_3DStyleTransfer.iml}
RENAMED
@@ -2,11 +2,7 @@
|
|
2 |
<module type="PYTHON_MODULE" version="4">
|
3 |
<component name="NewModuleRootManager">
|
4 |
<content url="file://$MODULE_DIR$" />
|
5 |
-
<orderEntry type="
|
6 |
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
</component>
|
8 |
-
<component name="PyDocumentationSettings">
|
9 |
-
<option name="format" value="PLAIN" />
|
10 |
-
<option name="myDocStringFormat" value="Plain" />
|
11 |
-
</component>
|
12 |
</module>
|
|
|
2 |
<module type="PYTHON_MODULE" version="4">
|
3 |
<component name="NewModuleRootManager">
|
4 |
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="jdk" jdkName="Python 3.8 (Thesis_3DStyleTransfer)" jdkType="Python SDK" />
|
6 |
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
</component>
|
|
|
|
|
|
|
|
|
8 |
</module>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (Thesis_3DStyleTransfer)" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
.idea/modules.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<project version="4">
|
3 |
<component name="ProjectModuleManager">
|
4 |
<modules>
|
5 |
-
<module fileurl="file://$PROJECT_DIR$/.idea/
|
6 |
</modules>
|
7 |
</component>
|
8 |
</project>
|
|
|
2 |
<project version="4">
|
3 |
<component name="ProjectModuleManager">
|
4 |
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/Thesis_3DStyleTransfer.iml" filepath="$PROJECT_DIR$/.idea/Thesis_3DStyleTransfer.iml" />
|
6 |
</modules>
|
7 |
</component>
|
8 |
</project>
|
.idea/vcs.xml
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<project version="4">
|
3 |
<component name="VcsDirectoryMappings">
|
4 |
-
<mapping directory="" vcs="Git" />
|
5 |
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
6 |
</component>
|
7 |
</project>
|
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<project version="4">
|
3 |
<component name="VcsDirectoryMappings">
|
|
|
4 |
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
5 |
</component>
|
6 |
</project>
|
README.md
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: 3D Zeroshot Neural Style Transfer
|
3 |
-
emoji: π
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: green
|
6 |
-
sdk: streamlit
|
7 |
-
sdk_version: 1.26.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: unlicense
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__pycache__/inference.cpython-38.pyc
ADDED
Binary file (2.57 kB). View file
|
|
app.py
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
-
x = st.slider('Select a value')
|
4 |
-
st.write(x, 'squared is', x * x)
|
|
|
|
|
|
|
|
|
|
configs/feature_baseline.yml
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
global:
|
2 |
+
username: totuanan06
|
3 |
+
project_name: thesis
|
4 |
+
name: 3d-style-transfer
|
5 |
+
expname: "lego"
|
6 |
+
base_dir: "./log"
|
7 |
+
save_dir: "./runs"
|
8 |
+
verbose: true
|
9 |
+
pretrained: null
|
10 |
+
resume: 0
|
11 |
+
SEED: 20211202
|
12 |
+
dataset:
|
13 |
+
name: BlenderDataset
|
14 |
+
train:
|
15 |
+
params:
|
16 |
+
datadir: "data/nerf_synthetic/lego"
|
17 |
+
split: "train"
|
18 |
+
downsample: 1.0
|
19 |
+
is_stack: True
|
20 |
+
N_vis: -1
|
21 |
+
val:
|
22 |
+
params:
|
23 |
+
datadir: "data/nerf_synthetic/lego"
|
24 |
+
split: "val"
|
25 |
+
downsample: 1.0
|
26 |
+
is_stack: False
|
27 |
+
N_vis: -1
|
28 |
+
sampler:
|
29 |
+
name: SimpleSampler
|
30 |
+
params:
|
31 |
+
N_voxel_init: 2097156 # 128**3
|
32 |
+
step_ratio: 0.5
|
33 |
+
batch_size: 2048
|
34 |
+
chunk_size: 1024
|
35 |
+
patch_size: 256
|
36 |
+
n_samples: 1000000
|
37 |
+
model:
|
38 |
+
name: StyleRF
|
39 |
+
type: "feature"
|
40 |
+
tensorf:
|
41 |
+
ckpt: "log/lego/lego.th"
|
42 |
+
model_name: "TensorVMSplit"
|
43 |
+
lamb_sh: [48,48,48]
|
44 |
+
rm_weight_mask_thre: 0.01
|
45 |
+
TV_weight_feature: 0
|
46 |
+
optimizer:
|
47 |
+
lr_init: 0.02
|
48 |
+
lr_basis: 1e-4
|
49 |
+
lr_decay_iters: -1
|
50 |
+
lr_decay_target_ratio: 0.1
|
51 |
+
trainer:
|
52 |
+
use_fp16: false
|
53 |
+
debug: false
|
54 |
+
n_iters: 30000
|
55 |
+
evaluate_interval: 1
|
56 |
+
log_interval: 1
|
57 |
+
save_interval: 1
|
58 |
+
callbacks:
|
59 |
+
- name: ModelCheckpoint
|
60 |
+
params:
|
61 |
+
filename: "baseline-{epoch}-{NN:.4f}-{mAP:.4f}-{train_loss:.4f}-{val_loss:.4f}"
|
62 |
+
monitor: "NN"
|
63 |
+
verbose: True
|
64 |
+
save_top_k: 1
|
65 |
+
mode: min
|
configs/llff.txt
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
|
2 |
-
dataset_name = llff
|
3 |
-
datadir = ./data/nerf_llff_data/trex
|
4 |
-
expname = trex
|
5 |
-
basedir = ./log
|
6 |
-
|
7 |
-
downsample_train = 4.0
|
8 |
-
ndc_ray = 1
|
9 |
-
|
10 |
-
n_iters = 25000
|
11 |
-
batch_size = 4096
|
12 |
-
|
13 |
-
N_voxel_init = 2097156 # 128**3
|
14 |
-
N_voxel_final = 262144000 # 640**3
|
15 |
-
upsamp_list = [2000,3000,4000,5500]
|
16 |
-
update_AlphaMask_list = [2500]
|
17 |
-
|
18 |
-
N_vis = -1 # vis all testing images
|
19 |
-
vis_every = 10000
|
20 |
-
|
21 |
-
render_test = 1
|
22 |
-
render_path = 1
|
23 |
-
|
24 |
-
n_lamb_sigma = [16,4,4]
|
25 |
-
n_lamb_sh = [48,12,12]
|
26 |
-
|
27 |
-
shadingMode = MLP_Fea
|
28 |
-
fea2denseAct = relu
|
29 |
-
|
30 |
-
view_pe = 0
|
31 |
-
fea_pe = 0
|
32 |
-
|
33 |
-
TV_weight_density = 1.0
|
34 |
-
TV_weight_app = 1.0
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/llff_feature.txt
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
dataset_name = llff
|
2 |
-
datadir = ./data/nerf_llff_data/trex
|
3 |
-
ckpt = ./log/trex/trex.th
|
4 |
-
expname = trex
|
5 |
-
basedir = ./log_feature
|
6 |
-
|
7 |
-
TV_weight_feature = 80
|
8 |
-
|
9 |
-
downsample_train = 4.0
|
10 |
-
ndc_ray = 1
|
11 |
-
|
12 |
-
n_iters = 25000
|
13 |
-
patch_size = 256
|
14 |
-
batch_size = 4096
|
15 |
-
chunk_size = 4096
|
16 |
-
|
17 |
-
N_voxel_init = 2097156 # 128**3
|
18 |
-
N_voxel_final = 262144000 # 640**3
|
19 |
-
upsamp_list = [2000,3000,4000,5500]
|
20 |
-
update_AlphaMask_list = [2500]
|
21 |
-
|
22 |
-
n_lamb_sigma = [16,4,4]
|
23 |
-
n_lamb_sh = [48,12,12]
|
24 |
-
|
25 |
-
fea2denseAct = relu
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/llff_style.txt
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
dataset_name = llff
|
2 |
-
datadir = ./data/nerf_llff_data/trex
|
3 |
-
ckpt = ./log_feature/trex/trex.th
|
4 |
-
expname = trex
|
5 |
-
basedir = ./log_style
|
6 |
-
|
7 |
-
nSamples = 300
|
8 |
-
patch_size = 256
|
9 |
-
chunk_size = 2048
|
10 |
-
|
11 |
-
content_weight = 1
|
12 |
-
style_weight = 20
|
13 |
-
featuremap_tv_weight = 0
|
14 |
-
image_tv_weight = 0
|
15 |
-
|
16 |
-
rm_weight_mask_thre = 0.001
|
17 |
-
|
18 |
-
downsample_train = 4.0
|
19 |
-
ndc_ray = 1
|
20 |
-
|
21 |
-
n_iters = 25000
|
22 |
-
|
23 |
-
n_lamb_sigma = [16,4,4]
|
24 |
-
n_lamb_sh = [48,12,12]
|
25 |
-
N_voxel_init = 2097156 # 128**3
|
26 |
-
N_voxel_final = 262144000 # 640**3
|
27 |
-
|
28 |
-
fea2denseAct = relu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/nerf_synthetic.txt
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
|
2 |
-
dataset_name = blender
|
3 |
-
datadir = ./data/nerf_synthetic/lego
|
4 |
-
expname = lego
|
5 |
-
basedir = ./log
|
6 |
-
|
7 |
-
n_iters = 30000
|
8 |
-
batch_size = 4096
|
9 |
-
|
10 |
-
N_voxel_init = 2097156 # 128**3
|
11 |
-
N_voxel_final = 27000000 # 300**3
|
12 |
-
upsamp_list = [2000,3000,4000,5500,7000]
|
13 |
-
update_AlphaMask_list = [2000,4000]
|
14 |
-
|
15 |
-
N_vis = 5
|
16 |
-
vis_every = 10000
|
17 |
-
|
18 |
-
render_test = 1
|
19 |
-
|
20 |
-
n_lamb_sigma = [16,16,16]
|
21 |
-
n_lamb_sh = [48,48,48]
|
22 |
-
model_name = TensorVMSplit
|
23 |
-
|
24 |
-
|
25 |
-
shadingMode = MLP_Fea
|
26 |
-
fea2denseAct = softplus
|
27 |
-
|
28 |
-
view_pe = 2
|
29 |
-
fea_pe = 2
|
30 |
-
|
31 |
-
L1_weight_inital = 8e-5
|
32 |
-
L1_weight_rest = 4e-5
|
33 |
-
rm_weight_mask_thre = 1e-4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/nerf_synthetic_feature.txt
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
dataset_name = blender
|
2 |
-
datadir = ./data/nerf_synthetic/lego
|
3 |
-
ckpt = ./log/lego/lego.th
|
4 |
-
expname = lego
|
5 |
-
basedir = ./log_feature
|
6 |
-
|
7 |
-
TV_weight_feature = 10
|
8 |
-
|
9 |
-
n_iters = 25000
|
10 |
-
patch_size = 256
|
11 |
-
batch_size = 4096
|
12 |
-
chunk_size = 4096
|
13 |
-
|
14 |
-
N_voxel_init = 2097156 # 128**3
|
15 |
-
N_voxel_final = 27000000 # 300**3
|
16 |
-
upsamp_list = [2000,3000,4000,5500,7000]
|
17 |
-
update_AlphaMask_list = [2000,4000]
|
18 |
-
|
19 |
-
rm_weight_mask_thre = 0.01
|
20 |
-
|
21 |
-
n_lamb_sigma = [16,16,16]
|
22 |
-
n_lamb_sh = [48,48,48]
|
23 |
-
|
24 |
-
fea2denseAct = softplus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/nerf_synthetic_style.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
dataset_name = blender
|
2 |
-
datadir = ./data/nerf_synthetic/lego
|
3 |
-
ckpt = ./log_feature/lego/lego.th
|
4 |
-
expname = lego
|
5 |
-
basedir = ./log_style
|
6 |
-
|
7 |
-
patch_size = 256
|
8 |
-
chunk_size = 2048
|
9 |
-
|
10 |
-
content_weight = 1
|
11 |
-
style_weight = 20
|
12 |
-
|
13 |
-
rm_weight_mask_thre = 0.01
|
14 |
-
|
15 |
-
n_iters = 25000
|
16 |
-
|
17 |
-
n_lamb_sigma = [16,16,16]
|
18 |
-
n_lamb_sh = [48,48,48]
|
19 |
-
N_voxel_init = 2097156 # 128**3
|
20 |
-
N_voxel_final = 27000000 # 300**3
|
21 |
-
|
22 |
-
fea2denseAct = softplus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/style_baseline.yml
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
global:
|
2 |
+
username: totuanan06
|
3 |
+
project_name: thesis
|
4 |
+
name: 3d-style-transfer
|
5 |
+
expname: "trex"
|
6 |
+
base_dir: "./log"
|
7 |
+
save_dir: "./runs"
|
8 |
+
style_img: "image_style/example.jpg"
|
9 |
+
verbose: true
|
10 |
+
pretrained: null
|
11 |
+
resume: 0
|
12 |
+
SEED: 20211202
|
13 |
+
dataset:
|
14 |
+
name: BlenderDataset
|
15 |
+
train:
|
16 |
+
params:
|
17 |
+
datadir: "data/nerf_llff/trex"
|
18 |
+
split: "train"
|
19 |
+
downsample: 4.0
|
20 |
+
is_stack: True
|
21 |
+
N_vis: -1
|
22 |
+
val:
|
23 |
+
params:
|
24 |
+
datadir: "data/nerf_llff/trex"
|
25 |
+
split: "val"
|
26 |
+
downsample: 1.0
|
27 |
+
is_stack: False
|
28 |
+
N_vis: -1
|
29 |
+
sampler:
|
30 |
+
name: SimpleSampler
|
31 |
+
params:
|
32 |
+
N_voxel_init: 2097156 # 128**3
|
33 |
+
step_ratio: 0.5
|
34 |
+
batch_size: 2048
|
35 |
+
chunk_size: 2048
|
36 |
+
patch_size: 256
|
37 |
+
n_samples: 300
|
38 |
+
model:
|
39 |
+
name: StyleRF
|
40 |
+
type: "style"
|
41 |
+
tensorf:
|
42 |
+
ckpt: "log_style/trex/trex.th"
|
43 |
+
model_name: "TensorVMSplit"
|
44 |
+
lamb_sh: [48,12,12]
|
45 |
+
rm_weight_mask_thre: 0.001
|
46 |
+
TV_weight_feature: 0
|
47 |
+
ndc_ray: 1
|
48 |
+
style_dataset:
|
49 |
+
name: StyleDataset
|
50 |
+
train:
|
51 |
+
params:
|
52 |
+
datadir: "..."
|
53 |
+
batch_size: 1
|
54 |
+
image_side_length: 256
|
55 |
+
num_workers: 2
|
56 |
+
style_config:
|
57 |
+
content_weight: 1
|
58 |
+
style_weight: 20
|
59 |
+
featuremap_tv_weight: 0
|
60 |
+
image_tv_weight: 0
|
61 |
+
optimizer:
|
62 |
+
lr_init: 0.02
|
63 |
+
lr_basis: 1e-4
|
64 |
+
lr_decay_iters: -1
|
65 |
+
lr_decay_target_ratio: 0.1
|
66 |
+
trainer:
|
67 |
+
use_fp16: false
|
68 |
+
debug: false
|
69 |
+
n_iters: 25000
|
70 |
+
evaluate_interval: 1
|
71 |
+
log_interval: 1
|
72 |
+
save_interval: 1
|
73 |
+
callbacks:
|
74 |
+
- name: ModelCheckpoint
|
75 |
+
params:
|
76 |
+
filename: "baseline-{epoch}-{NN:.4f}-{mAP:.4f}-{train_loss:.4f}-{val_loss:.4f}"
|
77 |
+
monitor: "NN"
|
78 |
+
verbose: True
|
79 |
+
save_top_k: 1
|
80 |
+
mode: min
|
configs/style_inference.yml
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
global:
|
2 |
+
username: totuanan06
|
3 |
+
project_name: thesis
|
4 |
+
name: 3d-style-transfer
|
5 |
+
expname: "trex"
|
6 |
+
base_dir: "./log"
|
7 |
+
save_dir: "./runs"
|
8 |
+
style_img: "image_style/example.jpg"
|
9 |
+
verbose: true
|
10 |
+
pretrained: null
|
11 |
+
resume: 0
|
12 |
+
SEED: 20211202
|
13 |
+
dataset:
|
14 |
+
name: LLFFDataset
|
15 |
+
train:
|
16 |
+
params:
|
17 |
+
datadir: "data/nerf_llff_data/trex"
|
18 |
+
split: "train"
|
19 |
+
downsample: 4.0
|
20 |
+
is_stack: True
|
21 |
+
N_vis: -1
|
22 |
+
val:
|
23 |
+
params:
|
24 |
+
datadir: "data/nerf_llff_data/trex"
|
25 |
+
split: "test"
|
26 |
+
downsample: 4.0
|
27 |
+
is_stack: True
|
28 |
+
N_vis: -1
|
29 |
+
sampler:
|
30 |
+
name: SimpleSampler
|
31 |
+
params:
|
32 |
+
N_voxel_init: 2097156 # 128**3
|
33 |
+
step_ratio: 0.5
|
34 |
+
batch_size: 2048
|
35 |
+
chunk_size: 1024
|
36 |
+
patch_size: 256
|
37 |
+
n_samples: 300
|
38 |
+
model:
|
39 |
+
name: StyleRF
|
40 |
+
type: "style"
|
41 |
+
tensorf:
|
42 |
+
ckpt: "log_style/trex/trex.th"
|
43 |
+
model_name: "TensorVMSplit"
|
44 |
+
lamb_sh: [48,12,12]
|
45 |
+
rm_weight_mask_thre: 0.001
|
46 |
+
TV_weight_feature: 0
|
47 |
+
ndc_ray: 1
|
48 |
+
style_dataset:
|
49 |
+
name: StyleDataset
|
50 |
+
train:
|
51 |
+
params:
|
52 |
+
datadir: "..."
|
53 |
+
batch_size: 1
|
54 |
+
image_side_length: 256
|
55 |
+
num_workers: 2
|
56 |
+
style_config:
|
57 |
+
content_weight: 1
|
58 |
+
style_weight: 20
|
59 |
+
featuremap_tv_weight: 0
|
60 |
+
image_tv_weight: 0
|
61 |
+
optimizer:
|
62 |
+
lr_init: 0.02
|
63 |
+
lr_basis: 1e-4
|
64 |
+
lr_decay_iters: -1
|
65 |
+
lr_decay_target_ratio: 0.1
|
66 |
+
trainer:
|
67 |
+
use_fp16: false
|
68 |
+
debug: false
|
69 |
+
n_iters: 5
|
70 |
+
evaluate_interval: 1
|
71 |
+
log_interval: 1
|
72 |
+
save_interval: 1
|
73 |
+
callbacks:
|
74 |
+
- name: ModelCheckpoint
|
75 |
+
params:
|
76 |
+
filename: "baseline-{epoch}-{NN:.4f}-{mAP:.4f}-{train_loss:.4f}-{val_loss:.4f}"
|
77 |
+
monitor: "NN"
|
78 |
+
verbose: True
|
79 |
+
save_top_k: 1
|
80 |
+
mode: min
|
dataLoader/__init__.py
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
from .llff import LLFFDataset
|
2 |
-
from .blender import BlenderDataset
|
3 |
-
from .nsvf import NSVF
|
4 |
-
from .tankstemple import TanksTempleDataset
|
5 |
-
from .your_own_data import YourOwnDataset
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
dataset_dict = {'blender': BlenderDataset,
|
10 |
-
'llff':LLFFDataset,
|
11 |
-
'tankstemple':TanksTempleDataset,
|
12 |
-
'nsvf':NSVF,
|
13 |
-
'own_data':YourOwnDataset}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataLoader/__pycache__/__init__.cpython-38.pyc
DELETED
Binary file (445 Bytes)
|
|
dataLoader/__pycache__/nsvf.cpython-38.pyc
DELETED
Binary file (6.47 kB)
|
|
dataLoader/__pycache__/styleLoader.cpython-38.pyc
DELETED
Binary file (735 Bytes)
|
|
dataLoader/__pycache__/tankstemple.cpython-38.pyc
DELETED
Binary file (9.75 kB)
|
|
dataLoader/__pycache__/your_own_data.cpython-38.pyc
DELETED
Binary file (4.24 kB)
|
|
dataLoader/colmap2nerf.py
DELETED
@@ -1,305 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python3
|
2 |
-
|
3 |
-
# Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved.
|
4 |
-
#
|
5 |
-
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
6 |
-
# and proprietary rights in and to this software, related documentation
|
7 |
-
# and any modifications thereto. Any use, reproduction, disclosure or
|
8 |
-
# distribution of this software and related documentation without an express
|
9 |
-
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
10 |
-
|
11 |
-
import argparse
|
12 |
-
import os
|
13 |
-
from pathlib import Path, PurePosixPath
|
14 |
-
|
15 |
-
import numpy as np
|
16 |
-
import json
|
17 |
-
import sys
|
18 |
-
import math
|
19 |
-
import cv2
|
20 |
-
import os
|
21 |
-
import shutil
|
22 |
-
|
23 |
-
def parse_args():
|
24 |
-
parser = argparse.ArgumentParser(description="convert a text colmap export to nerf format transforms.json; optionally convert video to images, and optionally run colmap in the first place")
|
25 |
-
|
26 |
-
parser.add_argument("--video_in", default="", help="run ffmpeg first to convert a provided video file into a set of images. uses the video_fps parameter also")
|
27 |
-
parser.add_argument("--video_fps", default=2)
|
28 |
-
parser.add_argument("--time_slice", default="", help="time (in seconds) in the format t1,t2 within which the images should be generated from the video. eg: \"--time_slice '10,300'\" will generate images only from 10th second to 300th second of the video")
|
29 |
-
parser.add_argument("--run_colmap", action="store_true", help="run colmap first on the image folder")
|
30 |
-
parser.add_argument("--colmap_matcher", default="sequential", choices=["exhaustive","sequential","spatial","transitive","vocab_tree"], help="select which matcher colmap should use. sequential for videos, exhaustive for adhoc images")
|
31 |
-
parser.add_argument("--colmap_db", default="colmap.db", help="colmap database filename")
|
32 |
-
parser.add_argument("--images", default="images", help="input path to the images")
|
33 |
-
parser.add_argument("--text", default="colmap_text", help="input path to the colmap text files (set automatically if run_colmap is used)")
|
34 |
-
parser.add_argument("--aabb_scale", default=16, choices=["1","2","4","8","16"], help="large scene scale factor. 1=scene fits in unit cube; power of 2 up to 16")
|
35 |
-
parser.add_argument("--skip_early", default=0, help="skip this many images from the start")
|
36 |
-
parser.add_argument("--out", default="transforms.json", help="output path")
|
37 |
-
args = parser.parse_args()
|
38 |
-
return args
|
39 |
-
|
40 |
-
def do_system(arg):
|
41 |
-
print(f"==== running: {arg}")
|
42 |
-
err = os.system(arg)
|
43 |
-
if err:
|
44 |
-
print("FATAL: command failed")
|
45 |
-
sys.exit(err)
|
46 |
-
|
47 |
-
def run_ffmpeg(args):
|
48 |
-
if not os.path.isabs(args.images):
|
49 |
-
args.images = os.path.join(os.path.dirname(args.video_in), args.images)
|
50 |
-
images = args.images
|
51 |
-
video = args.video_in
|
52 |
-
fps = float(args.video_fps) or 1.0
|
53 |
-
print(f"running ffmpeg with input video file={video}, output image folder={images}, fps={fps}.")
|
54 |
-
if (input(f"warning! folder '{images}' will be deleted/replaced. continue? (Y/n)").lower().strip()+"y")[:1] != "y":
|
55 |
-
sys.exit(1)
|
56 |
-
try:
|
57 |
-
shutil.rmtree(images)
|
58 |
-
except:
|
59 |
-
pass
|
60 |
-
do_system(f"mkdir {images}")
|
61 |
-
|
62 |
-
time_slice_value = ""
|
63 |
-
time_slice = args.time_slice
|
64 |
-
if time_slice:
|
65 |
-
start, end = time_slice.split(",")
|
66 |
-
time_slice_value = f",select='between(t\,{start}\,{end})'"
|
67 |
-
do_system(f"ffmpeg -i {video} -qscale:v 1 -qmin 1 -vf \"fps={fps}{time_slice_value}\" {images}/%04d.jpg")
|
68 |
-
|
69 |
-
def run_colmap(args):
|
70 |
-
db=args.colmap_db
|
71 |
-
images=args.images
|
72 |
-
db_noext=str(Path(db).with_suffix(""))
|
73 |
-
|
74 |
-
if args.text=="text":
|
75 |
-
args.text=db_noext+"_text"
|
76 |
-
text=args.text
|
77 |
-
sparse=db_noext+"_sparse"
|
78 |
-
print(f"running colmap with:\n\tdb={db}\n\timages={images}\n\tsparse={sparse}\n\ttext={text}")
|
79 |
-
if (input(f"warning! folders '{sparse}' and '{text}' will be deleted/replaced. continue? (Y/n)").lower().strip()+"y")[:1] != "y":
|
80 |
-
sys.exit(1)
|
81 |
-
if os.path.exists(db):
|
82 |
-
os.remove(db)
|
83 |
-
do_system(f"colmap feature_extractor --ImageReader.camera_model OPENCV --SiftExtraction.estimate_affine_shape=true --SiftExtraction.domain_size_pooling=true --ImageReader.single_camera 1 --database_path {db} --image_path {images}")
|
84 |
-
do_system(f"colmap {args.colmap_matcher}_matcher --SiftMatching.guided_matching=true --database_path {db}")
|
85 |
-
try:
|
86 |
-
shutil.rmtree(sparse)
|
87 |
-
except:
|
88 |
-
pass
|
89 |
-
do_system(f"mkdir {sparse}")
|
90 |
-
do_system(f"colmap mapper --database_path {db} --image_path {images} --output_path {sparse}")
|
91 |
-
do_system(f"colmap bundle_adjuster --input_path {sparse}/0 --output_path {sparse}/0 --BundleAdjustment.refine_principal_point 1")
|
92 |
-
try:
|
93 |
-
shutil.rmtree(text)
|
94 |
-
except:
|
95 |
-
pass
|
96 |
-
do_system(f"mkdir {text}")
|
97 |
-
do_system(f"colmap model_converter --input_path {sparse}/0 --output_path {text} --output_type TXT")
|
98 |
-
|
99 |
-
def variance_of_laplacian(image):
|
100 |
-
return cv2.Laplacian(image, cv2.CV_64F).var()
|
101 |
-
|
102 |
-
def sharpness(imagePath):
|
103 |
-
image = cv2.imread(imagePath)
|
104 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
105 |
-
fm = variance_of_laplacian(gray)
|
106 |
-
return fm
|
107 |
-
|
108 |
-
def qvec2rotmat(qvec):
|
109 |
-
return np.array([
|
110 |
-
[
|
111 |
-
1 - 2 * qvec[2]**2 - 2 * qvec[3]**2,
|
112 |
-
2 * qvec[1] * qvec[2] - 2 * qvec[0] * qvec[3],
|
113 |
-
2 * qvec[3] * qvec[1] + 2 * qvec[0] * qvec[2]
|
114 |
-
], [
|
115 |
-
2 * qvec[1] * qvec[2] + 2 * qvec[0] * qvec[3],
|
116 |
-
1 - 2 * qvec[1]**2 - 2 * qvec[3]**2,
|
117 |
-
2 * qvec[2] * qvec[3] - 2 * qvec[0] * qvec[1]
|
118 |
-
], [
|
119 |
-
2 * qvec[3] * qvec[1] - 2 * qvec[0] * qvec[2],
|
120 |
-
2 * qvec[2] * qvec[3] + 2 * qvec[0] * qvec[1],
|
121 |
-
1 - 2 * qvec[1]**2 - 2 * qvec[2]**2
|
122 |
-
]
|
123 |
-
])
|
124 |
-
|
125 |
-
def rotmat(a, b):
|
126 |
-
a, b = a / np.linalg.norm(a), b / np.linalg.norm(b)
|
127 |
-
v = np.cross(a, b)
|
128 |
-
c = np.dot(a, b)
|
129 |
-
s = np.linalg.norm(v)
|
130 |
-
kmat = np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])
|
131 |
-
return np.eye(3) + kmat + kmat.dot(kmat) * ((1 - c) / (s ** 2 + 1e-10))
|
132 |
-
|
133 |
-
def closest_point_2_lines(oa, da, ob, db): # returns point closest to both rays of form o+t*d, and a weight factor that goes to 0 if the lines are parallel
|
134 |
-
da = da / np.linalg.norm(da)
|
135 |
-
db = db / np.linalg.norm(db)
|
136 |
-
c = np.cross(da, db)
|
137 |
-
denom = np.linalg.norm(c)**2
|
138 |
-
t = ob - oa
|
139 |
-
ta = np.linalg.det([t, db, c]) / (denom + 1e-10)
|
140 |
-
tb = np.linalg.det([t, da, c]) / (denom + 1e-10)
|
141 |
-
if ta > 0:
|
142 |
-
ta = 0
|
143 |
-
if tb > 0:
|
144 |
-
tb = 0
|
145 |
-
return (oa+ta*da+ob+tb*db) * 0.5, denom
|
146 |
-
|
147 |
-
if __name__ == "__main__":
|
148 |
-
args = parse_args()
|
149 |
-
if args.video_in != "":
|
150 |
-
run_ffmpeg(args)
|
151 |
-
if args.run_colmap:
|
152 |
-
run_colmap(args)
|
153 |
-
AABB_SCALE = int(args.aabb_scale)
|
154 |
-
SKIP_EARLY = int(args.skip_early)
|
155 |
-
IMAGE_FOLDER = args.images
|
156 |
-
TEXT_FOLDER = args.text
|
157 |
-
OUT_PATH = args.out
|
158 |
-
print(f"outputting to {OUT_PATH}...")
|
159 |
-
with open(os.path.join(TEXT_FOLDER,"cameras.txt"), "r") as f:
|
160 |
-
angle_x = math.pi / 2
|
161 |
-
for line in f:
|
162 |
-
# 1 SIMPLE_RADIAL 2048 1536 1580.46 1024 768 0.0045691
|
163 |
-
# 1 OPENCV 3840 2160 3178.27 3182.09 1920 1080 0.159668 -0.231286 -0.00123982 0.00272224
|
164 |
-
# 1 RADIAL 1920 1080 1665.1 960 540 0.0672856 -0.0761443
|
165 |
-
if line[0] == "#":
|
166 |
-
continue
|
167 |
-
els = line.split(" ")
|
168 |
-
w = float(els[2])
|
169 |
-
h = float(els[3])
|
170 |
-
fl_x = float(els[4])
|
171 |
-
fl_y = float(els[4])
|
172 |
-
k1 = 0
|
173 |
-
k2 = 0
|
174 |
-
p1 = 0
|
175 |
-
p2 = 0
|
176 |
-
cx = w / 2
|
177 |
-
cy = h / 2
|
178 |
-
if els[1] == "SIMPLE_PINHOLE":
|
179 |
-
cx = float(els[5])
|
180 |
-
cy = float(els[6])
|
181 |
-
elif els[1] == "PINHOLE":
|
182 |
-
fl_y = float(els[5])
|
183 |
-
cx = float(els[6])
|
184 |
-
cy = float(els[7])
|
185 |
-
elif els[1] == "SIMPLE_RADIAL":
|
186 |
-
cx = float(els[5])
|
187 |
-
cy = float(els[6])
|
188 |
-
k1 = float(els[7])
|
189 |
-
elif els[1] == "RADIAL":
|
190 |
-
cx = float(els[5])
|
191 |
-
cy = float(els[6])
|
192 |
-
k1 = float(els[7])
|
193 |
-
k2 = float(els[8])
|
194 |
-
elif els[1] == "OPENCV":
|
195 |
-
fl_y = float(els[5])
|
196 |
-
cx = float(els[6])
|
197 |
-
cy = float(els[7])
|
198 |
-
k1 = float(els[8])
|
199 |
-
k2 = float(els[9])
|
200 |
-
p1 = float(els[10])
|
201 |
-
p2 = float(els[11])
|
202 |
-
else:
|
203 |
-
print("unknown camera model ", els[1])
|
204 |
-
# fl = 0.5 * w / tan(0.5 * angle_x);
|
205 |
-
angle_x = math.atan(w / (fl_x * 2)) * 2
|
206 |
-
angle_y = math.atan(h / (fl_y * 2)) * 2
|
207 |
-
fovx = angle_x * 180 / math.pi
|
208 |
-
fovy = angle_y * 180 / math.pi
|
209 |
-
|
210 |
-
print(f"camera:\n\tres={w,h}\n\tcenter={cx,cy}\n\tfocal={fl_x,fl_y}\n\tfov={fovx,fovy}\n\tk={k1,k2} p={p1,p2} ")
|
211 |
-
|
212 |
-
with open(os.path.join(TEXT_FOLDER,"images.txt"), "r") as f:
|
213 |
-
i = 0
|
214 |
-
bottom = np.array([0.0, 0.0, 0.0, 1.0]).reshape([1, 4])
|
215 |
-
out = {
|
216 |
-
"camera_angle_x": angle_x,
|
217 |
-
"camera_angle_y": angle_y,
|
218 |
-
"fl_x": fl_x,
|
219 |
-
"fl_y": fl_y,
|
220 |
-
"k1": k1,
|
221 |
-
"k2": k2,
|
222 |
-
"p1": p1,
|
223 |
-
"p2": p2,
|
224 |
-
"cx": cx,
|
225 |
-
"cy": cy,
|
226 |
-
"w": w,
|
227 |
-
"h": h,
|
228 |
-
"aabb_scale": AABB_SCALE,
|
229 |
-
"frames": [],
|
230 |
-
}
|
231 |
-
|
232 |
-
up = np.zeros(3)
|
233 |
-
for line in f:
|
234 |
-
line = line.strip()
|
235 |
-
if line[0] == "#":
|
236 |
-
continue
|
237 |
-
i = i + 1
|
238 |
-
if i < SKIP_EARLY*2:
|
239 |
-
continue
|
240 |
-
if i % 2 == 1:
|
241 |
-
elems=line.split(" ") # 1-4 is quat, 5-7 is trans, 9ff is filename (9, if filename contains no spaces)
|
242 |
-
#name = str(PurePosixPath(Path(IMAGE_FOLDER, elems[9])))
|
243 |
-
# why is this requireing a relitive path while using ^
|
244 |
-
image_rel = os.path.relpath(IMAGE_FOLDER)
|
245 |
-
name = str(f"./{image_rel}/{'_'.join(elems[9:])}")
|
246 |
-
b=sharpness(name)
|
247 |
-
print(name, "sharpness=",b)
|
248 |
-
image_id = int(elems[0])
|
249 |
-
qvec = np.array(tuple(map(float, elems[1:5])))
|
250 |
-
tvec = np.array(tuple(map(float, elems[5:8])))
|
251 |
-
R = qvec2rotmat(-qvec)
|
252 |
-
t = tvec.reshape([3,1])
|
253 |
-
m = np.concatenate([np.concatenate([R, t], 1), bottom], 0)
|
254 |
-
c2w = np.linalg.inv(m)
|
255 |
-
c2w[0:3,2] *= -1 # flip the y and z axis
|
256 |
-
c2w[0:3,1] *= -1
|
257 |
-
c2w = c2w[[1,0,2,3],:] # swap y and z
|
258 |
-
c2w[2,:] *= -1 # flip whole world upside down
|
259 |
-
|
260 |
-
up += c2w[0:3,1]
|
261 |
-
|
262 |
-
frame={"file_path":name,"sharpness":b,"transform_matrix": c2w}
|
263 |
-
out["frames"].append(frame)
|
264 |
-
nframes = len(out["frames"])
|
265 |
-
up = up / np.linalg.norm(up)
|
266 |
-
print("up vector was", up)
|
267 |
-
R = rotmat(up,[0,0,1]) # rotate up vector to [0,0,1]
|
268 |
-
R = np.pad(R,[0,1])
|
269 |
-
R[-1, -1] = 1
|
270 |
-
|
271 |
-
|
272 |
-
for f in out["frames"]:
|
273 |
-
f["transform_matrix"] = np.matmul(R, f["transform_matrix"]) # rotate up to be the z axis
|
274 |
-
|
275 |
-
# find a central point they are all looking at
|
276 |
-
print("computing center of attention...")
|
277 |
-
totw = 0.0
|
278 |
-
totp = np.array([0.0, 0.0, 0.0])
|
279 |
-
for f in out["frames"]:
|
280 |
-
mf = f["transform_matrix"][0:3,:]
|
281 |
-
for g in out["frames"]:
|
282 |
-
mg = g["transform_matrix"][0:3,:]
|
283 |
-
p, w = closest_point_2_lines(mf[:,3], mf[:,2], mg[:,3], mg[:,2])
|
284 |
-
if w > 0.01:
|
285 |
-
totp += p*w
|
286 |
-
totw += w
|
287 |
-
totp /= totw
|
288 |
-
print(totp) # the cameras are looking at totp
|
289 |
-
for f in out["frames"]:
|
290 |
-
f["transform_matrix"][0:3,3] -= totp
|
291 |
-
|
292 |
-
avglen = 0.
|
293 |
-
for f in out["frames"]:
|
294 |
-
avglen += np.linalg.norm(f["transform_matrix"][0:3,3])
|
295 |
-
avglen /= nframes
|
296 |
-
print("avg camera distance from origin", avglen)
|
297 |
-
for f in out["frames"]:
|
298 |
-
f["transform_matrix"][0:3,3] *= 4.0 / avglen # scale to "nerf sized"
|
299 |
-
|
300 |
-
for f in out["frames"]:
|
301 |
-
f["transform_matrix"] = f["transform_matrix"].tolist()
|
302 |
-
print(nframes,"frames")
|
303 |
-
print(f"writing {OUT_PATH}")
|
304 |
-
with open(OUT_PATH, "w") as outfile:
|
305 |
-
json.dump(out, outfile, indent=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataLoader/nsvf.py
DELETED
@@ -1,160 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
from torch.utils.data import Dataset
|
3 |
-
from tqdm import tqdm
|
4 |
-
import os
|
5 |
-
from PIL import Image
|
6 |
-
from torchvision import transforms as T
|
7 |
-
|
8 |
-
from .ray_utils import *
|
9 |
-
|
10 |
-
trans_t = lambda t : torch.Tensor([
|
11 |
-
[1,0,0,0],
|
12 |
-
[0,1,0,0],
|
13 |
-
[0,0,1,t],
|
14 |
-
[0,0,0,1]]).float()
|
15 |
-
|
16 |
-
rot_phi = lambda phi : torch.Tensor([
|
17 |
-
[1,0,0,0],
|
18 |
-
[0,np.cos(phi),-np.sin(phi),0],
|
19 |
-
[0,np.sin(phi), np.cos(phi),0],
|
20 |
-
[0,0,0,1]]).float()
|
21 |
-
|
22 |
-
rot_theta = lambda th : torch.Tensor([
|
23 |
-
[np.cos(th),0,-np.sin(th),0],
|
24 |
-
[0,1,0,0],
|
25 |
-
[np.sin(th),0, np.cos(th),0],
|
26 |
-
[0,0,0,1]]).float()
|
27 |
-
|
28 |
-
|
29 |
-
def pose_spherical(theta, phi, radius):
|
30 |
-
c2w = trans_t(radius)
|
31 |
-
c2w = rot_phi(phi/180.*np.pi) @ c2w
|
32 |
-
c2w = rot_theta(theta/180.*np.pi) @ c2w
|
33 |
-
c2w = torch.Tensor(np.array([[-1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]])) @ c2w
|
34 |
-
return c2w
|
35 |
-
|
36 |
-
class NSVF(Dataset):
|
37 |
-
"""NSVF Generic Dataset."""
|
38 |
-
def __init__(self, datadir, split='train', downsample=1.0, wh=[800,800], is_stack=False):
|
39 |
-
self.root_dir = datadir
|
40 |
-
self.split = split
|
41 |
-
self.is_stack = is_stack
|
42 |
-
self.downsample = downsample
|
43 |
-
self.img_wh = (int(wh[0]/downsample),int(wh[1]/downsample))
|
44 |
-
self.define_transforms()
|
45 |
-
|
46 |
-
self.white_bg = True
|
47 |
-
self.near_far = [0.5,6.0]
|
48 |
-
self.scene_bbox = torch.from_numpy(np.loadtxt(f'{self.root_dir}/bbox.txt')).float()[:6].view(2,3)
|
49 |
-
self.blender2opencv = np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
|
50 |
-
self.read_meta()
|
51 |
-
self.define_proj_mat()
|
52 |
-
|
53 |
-
self.center = torch.mean(self.scene_bbox, axis=0).float().view(1, 1, 3)
|
54 |
-
self.radius = (self.scene_bbox[1] - self.center).float().view(1, 1, 3)
|
55 |
-
|
56 |
-
def bbox2corners(self):
|
57 |
-
corners = self.scene_bbox.unsqueeze(0).repeat(4,1,1)
|
58 |
-
for i in range(3):
|
59 |
-
corners[i,[0,1],i] = corners[i,[1,0],i]
|
60 |
-
return corners.view(-1,3)
|
61 |
-
|
62 |
-
|
63 |
-
def read_meta(self):
|
64 |
-
with open(os.path.join(self.root_dir, "intrinsics.txt")) as f:
|
65 |
-
focal = float(f.readline().split()[0])
|
66 |
-
self.intrinsics = np.array([[focal,0,400.0],[0,focal,400.0],[0,0,1]])
|
67 |
-
self.intrinsics[:2] *= (np.array(self.img_wh)/np.array([800,800])).reshape(2,1)
|
68 |
-
|
69 |
-
pose_files = sorted(os.listdir(os.path.join(self.root_dir, 'pose')))
|
70 |
-
img_files = sorted(os.listdir(os.path.join(self.root_dir, 'rgb')))
|
71 |
-
|
72 |
-
if self.split == 'train':
|
73 |
-
pose_files = [x for x in pose_files if x.startswith('0_')]
|
74 |
-
img_files = [x for x in img_files if x.startswith('0_')]
|
75 |
-
elif self.split == 'val':
|
76 |
-
pose_files = [x for x in pose_files if x.startswith('1_')]
|
77 |
-
img_files = [x for x in img_files if x.startswith('1_')]
|
78 |
-
elif self.split == 'test':
|
79 |
-
test_pose_files = [x for x in pose_files if x.startswith('2_')]
|
80 |
-
test_img_files = [x for x in img_files if x.startswith('2_')]
|
81 |
-
if len(test_pose_files) == 0:
|
82 |
-
test_pose_files = [x for x in pose_files if x.startswith('1_')]
|
83 |
-
test_img_files = [x for x in img_files if x.startswith('1_')]
|
84 |
-
pose_files = test_pose_files
|
85 |
-
img_files = test_img_files
|
86 |
-
|
87 |
-
# ray directions for all pixels, same for all images (same H, W, focal)
|
88 |
-
self.directions = get_ray_directions(self.img_wh[1], self.img_wh[0], [self.intrinsics[0,0],self.intrinsics[1,1]], center=self.intrinsics[:2,2]) # (h, w, 3)
|
89 |
-
self.directions = self.directions / torch.norm(self.directions, dim=-1, keepdim=True)
|
90 |
-
|
91 |
-
|
92 |
-
self.render_path = torch.stack([pose_spherical(angle, -30.0, 4.0) for angle in np.linspace(-180,180,40+1)[:-1]], 0)
|
93 |
-
|
94 |
-
self.poses = []
|
95 |
-
self.all_rays = []
|
96 |
-
self.all_rgbs = []
|
97 |
-
|
98 |
-
assert len(img_files) == len(pose_files)
|
99 |
-
for img_fname, pose_fname in tqdm(zip(img_files, pose_files), desc=f'Loading data {self.split} ({len(img_files)})'):
|
100 |
-
image_path = os.path.join(self.root_dir, 'rgb', img_fname)
|
101 |
-
img = Image.open(image_path)
|
102 |
-
if self.downsample!=1.0:
|
103 |
-
img = img.resize(self.img_wh, Image.LANCZOS)
|
104 |
-
img = self.transform(img) # (4, h, w)
|
105 |
-
img = img.view(img.shape[0], -1).permute(1, 0) # (h*w, 4) RGBA
|
106 |
-
if img.shape[-1]==4:
|
107 |
-
img = img[:, :3] * img[:, -1:] + (1 - img[:, -1:]) # blend A to RGB
|
108 |
-
self.all_rgbs += [img]
|
109 |
-
|
110 |
-
c2w = np.loadtxt(os.path.join(self.root_dir, 'pose', pose_fname)) #@ self.blender2opencv
|
111 |
-
c2w = torch.FloatTensor(c2w)
|
112 |
-
self.poses.append(c2w) # C2W
|
113 |
-
rays_o, rays_d = get_rays(self.directions, c2w) # both (h*w, 3)
|
114 |
-
self.all_rays += [torch.cat([rays_o, rays_d], 1)] # (h*w, 8)
|
115 |
-
|
116 |
-
# w2c = torch.inverse(c2w)
|
117 |
-
#
|
118 |
-
|
119 |
-
self.poses = torch.stack(self.poses)
|
120 |
-
if 'train' == self.split:
|
121 |
-
if self.is_stack:
|
122 |
-
self.all_rays = torch.stack(self.all_rays, 0).reshape(-1,*self.img_wh[::-1], 6) # (len(self.meta['frames])*h*w, 3)
|
123 |
-
self.all_rgbs = torch.stack(self.all_rgbs, 0).reshape(-1,*self.img_wh[::-1], 3) # (len(self.meta['frames])*h*w, 3)
|
124 |
-
else:
|
125 |
-
self.all_rays = torch.cat(self.all_rays, 0) # (len(self.meta['frames])*h*w, 3)
|
126 |
-
self.all_rgbs = torch.cat(self.all_rgbs, 0) # (len(self.meta['frames])*h*w, 3)
|
127 |
-
else:
|
128 |
-
self.all_rays = torch.stack(self.all_rays, 0) # (len(self.meta['frames]),h*w, 3)
|
129 |
-
self.all_rgbs = torch.stack(self.all_rgbs, 0).reshape(-1,*self.img_wh[::-1], 3) # (len(self.meta['frames]),h,w,3)
|
130 |
-
|
131 |
-
|
132 |
-
def define_transforms(self):
|
133 |
-
self.transform = T.ToTensor()
|
134 |
-
|
135 |
-
def define_proj_mat(self):
|
136 |
-
self.proj_mat = torch.from_numpy(self.intrinsics[:3,:3]).unsqueeze(0).float() @ torch.inverse(self.poses)[:,:3]
|
137 |
-
|
138 |
-
def world2ndc(self, points):
|
139 |
-
device = points.device
|
140 |
-
return (points - self.center.to(device)) / self.radius.to(device)
|
141 |
-
|
142 |
-
def __len__(self):
|
143 |
-
if self.split == 'train':
|
144 |
-
return len(self.all_rays)
|
145 |
-
return len(self.all_rgbs)
|
146 |
-
|
147 |
-
def __getitem__(self, idx):
|
148 |
-
|
149 |
-
if self.split == 'train': # use data in the buffers
|
150 |
-
sample = {'rays': self.all_rays[idx],
|
151 |
-
'rgbs': self.all_rgbs[idx]}
|
152 |
-
|
153 |
-
else: # create data for each image separately
|
154 |
-
|
155 |
-
img = self.all_rgbs[idx]
|
156 |
-
rays = self.all_rays[idx]
|
157 |
-
|
158 |
-
sample = {'rays': rays,
|
159 |
-
'rgbs': img}
|
160 |
-
return sample
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataLoader/styleLoader.py
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
from torch.utils.data import DataLoader
|
2 |
-
from torchvision import datasets
|
3 |
-
import torchvision.transforms as T
|
4 |
-
|
5 |
-
|
6 |
-
def getDataLoader(dataset_path, batch_size, sampler, image_side_length=256, num_workers=2):
|
7 |
-
transform = T.Compose([
|
8 |
-
T.Resize(size=(image_side_length*2, image_side_length*2)),
|
9 |
-
T.RandomCrop(image_side_length),
|
10 |
-
T.ToTensor(),
|
11 |
-
])
|
12 |
-
|
13 |
-
train_dataset = datasets.ImageFolder(dataset_path, transform=transform)
|
14 |
-
dataloader = DataLoader(train_dataset, batch_size=batch_size, sampler=sampler(len(train_dataset)), num_workers=num_workers)
|
15 |
-
|
16 |
-
return dataloader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataLoader/tankstemple.py
DELETED
@@ -1,247 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
from torch.utils.data import Dataset
|
3 |
-
from tqdm import tqdm
|
4 |
-
import os
|
5 |
-
from PIL import Image
|
6 |
-
from torchvision import transforms as T
|
7 |
-
import random
|
8 |
-
|
9 |
-
from .ray_utils import *
|
10 |
-
|
11 |
-
|
12 |
-
def circle(radius=3.5, h=0.0, axis='z', t0=0, r=1):
|
13 |
-
if axis == 'z':
|
14 |
-
return lambda t: [radius * np.cos(r * t + t0), radius * np.sin(r * t + t0), h]
|
15 |
-
elif axis == 'y':
|
16 |
-
return lambda t: [radius * np.cos(r * t + t0), h, radius * np.sin(r * t + t0)]
|
17 |
-
else:
|
18 |
-
return lambda t: [h, radius * np.cos(r * t + t0), radius * np.sin(r * t + t0)]
|
19 |
-
|
20 |
-
|
21 |
-
def cross(x, y, axis=0):
|
22 |
-
T = torch if isinstance(x, torch.Tensor) else np
|
23 |
-
return T.cross(x, y, axis)
|
24 |
-
|
25 |
-
|
26 |
-
def normalize(x, axis=-1, order=2):
|
27 |
-
if isinstance(x, torch.Tensor):
|
28 |
-
l2 = x.norm(p=order, dim=axis, keepdim=True)
|
29 |
-
return x / (l2 + 1e-8), l2
|
30 |
-
|
31 |
-
else:
|
32 |
-
l2 = np.linalg.norm(x, order, axis)
|
33 |
-
l2 = np.expand_dims(l2, axis)
|
34 |
-
l2[l2 == 0] = 1
|
35 |
-
return x / l2,
|
36 |
-
|
37 |
-
|
38 |
-
def cat(x, axis=1):
|
39 |
-
if isinstance(x[0], torch.Tensor):
|
40 |
-
return torch.cat(x, dim=axis)
|
41 |
-
return np.concatenate(x, axis=axis)
|
42 |
-
|
43 |
-
|
44 |
-
def look_at_rotation(camera_position, at=None, up=None, inverse=False, cv=False):
|
45 |
-
"""
|
46 |
-
This function takes a vector 'camera_position' which specifies the location
|
47 |
-
of the camera in world coordinates and two vectors `at` and `up` which
|
48 |
-
indicate the position of the object and the up directions of the world
|
49 |
-
coordinate system respectively. The object is assumed to be centered at
|
50 |
-
the origin.
|
51 |
-
The output is a rotation matrix representing the transformation
|
52 |
-
from world coordinates -> view coordinates.
|
53 |
-
Input:
|
54 |
-
camera_position: 3
|
55 |
-
at: 1 x 3 or N x 3 (0, 0, 0) in default
|
56 |
-
up: 1 x 3 or N x 3 (0, 1, 0) in default
|
57 |
-
"""
|
58 |
-
|
59 |
-
if at is None:
|
60 |
-
at = torch.zeros_like(camera_position)
|
61 |
-
else:
|
62 |
-
at = torch.tensor(at).type_as(camera_position)
|
63 |
-
if up is None:
|
64 |
-
up = torch.zeros_like(camera_position)
|
65 |
-
up[2] = -1
|
66 |
-
else:
|
67 |
-
up = torch.tensor(up).type_as(camera_position)
|
68 |
-
|
69 |
-
z_axis = normalize(at - camera_position)[0]
|
70 |
-
x_axis = normalize(cross(up, z_axis))[0]
|
71 |
-
y_axis = normalize(cross(z_axis, x_axis))[0]
|
72 |
-
|
73 |
-
R = cat([x_axis[:, None], y_axis[:, None], z_axis[:, None]], axis=1)
|
74 |
-
return R
|
75 |
-
|
76 |
-
|
77 |
-
def gen_path(pos_gen, at=(0, 0, 0), up=(0, -1, 0), frames=180):
|
78 |
-
c2ws = []
|
79 |
-
for t in range(frames):
|
80 |
-
c2w = torch.eye(4)
|
81 |
-
cam_pos = torch.tensor(pos_gen(t * (360.0 / frames) / 180 * np.pi))
|
82 |
-
cam_rot = look_at_rotation(cam_pos, at=at, up=up, inverse=False, cv=True)
|
83 |
-
c2w[:3, 3], c2w[:3, :3] = cam_pos, cam_rot
|
84 |
-
c2ws.append(c2w)
|
85 |
-
return torch.stack(c2ws)
|
86 |
-
|
87 |
-
class TanksTempleDataset(Dataset):
|
88 |
-
"""NSVF Generic Dataset."""
|
89 |
-
def __init__(self, datadir, split='train', downsample=4.0, wh=[1920,1080], is_stack=False):
|
90 |
-
self.root_dir = datadir
|
91 |
-
self.split = split
|
92 |
-
self.is_stack = is_stack
|
93 |
-
self.downsample = downsample
|
94 |
-
self.img_wh = (int(wh[0]/downsample),int(wh[1]/downsample))
|
95 |
-
self.define_transforms()
|
96 |
-
|
97 |
-
self.white_bg = True
|
98 |
-
self.near_far = [0.01,6.0]
|
99 |
-
self.scene_bbox = torch.from_numpy(np.loadtxt(f'{self.root_dir}/bbox.txt')).float()[:6].view(2,3)*1.2
|
100 |
-
|
101 |
-
self.blender2opencv = np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
|
102 |
-
self.read_meta()
|
103 |
-
self.define_proj_mat()
|
104 |
-
|
105 |
-
self.center = torch.mean(self.scene_bbox, axis=0).float().view(1, 1, 3)
|
106 |
-
self.radius = (self.scene_bbox[1] - self.center).float().view(1, 1, 3)
|
107 |
-
|
108 |
-
def bbox2corners(self):
|
109 |
-
corners = self.scene_bbox.unsqueeze(0).repeat(4,1,1)
|
110 |
-
for i in range(3):
|
111 |
-
corners[i,[0,1],i] = corners[i,[1,0],i]
|
112 |
-
return corners.view(-1,3)
|
113 |
-
|
114 |
-
|
115 |
-
def read_meta(self):
|
116 |
-
|
117 |
-
self.intrinsics = np.loadtxt(os.path.join(self.root_dir, "intrinsics.txt"))
|
118 |
-
self.intrinsics[:2] *= (np.array(self.img_wh)/np.array([1920,1080])).reshape(2,1)
|
119 |
-
pose_files = sorted(os.listdir(os.path.join(self.root_dir, 'pose')))
|
120 |
-
img_files = sorted(os.listdir(os.path.join(self.root_dir, 'rgb')))
|
121 |
-
|
122 |
-
if self.split == 'train':
|
123 |
-
pose_files = [x for idx,x in enumerate(pose_files) if x.startswith('0_') and idx%3==0]
|
124 |
-
img_files = [x for idx,x in enumerate(img_files) if x.startswith('0_') and idx%3==0]
|
125 |
-
elif self.split == 'test':
|
126 |
-
pose_files = [x for idx,x in enumerate(pose_files) if x.startswith('2_') and idx%3==0]
|
127 |
-
img_files = [x for idx,x in enumerate(img_files) if x.startswith('2_') and idx%3==0]
|
128 |
-
if len(test_pose_files) == 0:
|
129 |
-
test_pose_files = [x for idx,x in enumerate(pose_files) if x.startswith('1_') and idx%3==0]
|
130 |
-
test_img_files = [x for idx,x in enumerate(img_files) if x.startswith('1_') and idx%3==0]
|
131 |
-
pose_files = test_pose_files
|
132 |
-
img_files = test_img_files
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
# ray directions for all pixels, same for all images (same H, W, focal)
|
137 |
-
self.directions = get_ray_directions(self.img_wh[1], self.img_wh[0], [self.intrinsics[0,0],self.intrinsics[1,1]], center=self.intrinsics[:2,2]) # (h, w, 3)
|
138 |
-
self.directions = self.directions / torch.norm(self.directions, dim=-1, keepdim=True)
|
139 |
-
|
140 |
-
w, h = self.img_wh
|
141 |
-
|
142 |
-
self.poses = []
|
143 |
-
self.all_rays = []
|
144 |
-
self.all_rgbs = []
|
145 |
-
self.all_masks = []
|
146 |
-
|
147 |
-
assert len(img_files) == len(pose_files)
|
148 |
-
for img_fname, pose_fname in tqdm(zip(img_files, pose_files), desc=f'Loading data {self.split} ({len(img_files)})'):
|
149 |
-
image_path = os.path.join(self.root_dir, 'rgb', img_fname)
|
150 |
-
img = Image.open(image_path)
|
151 |
-
if self.downsample!=1.0:
|
152 |
-
img = img.resize(self.img_wh, Image.LANCZOS)
|
153 |
-
img = self.transform(img) # (3, h, w)
|
154 |
-
img = img.view(img.shape[0], -1).permute(1, 0) # (h*w, 3) RGBA
|
155 |
-
mask = torch.where(
|
156 |
-
img.sum(-1, keepdim=True) == 3.,
|
157 |
-
1.,
|
158 |
-
0.
|
159 |
-
)
|
160 |
-
self.all_masks.append(mask.reshape(h,w,1)) # (h, w, 1) A
|
161 |
-
|
162 |
-
if img.shape[-1]==4:
|
163 |
-
img = img[:, :3] * img[:, -1:] + (1 - img[:, -1:]) # blend A to RGB
|
164 |
-
self.all_rgbs.append(img)
|
165 |
-
|
166 |
-
|
167 |
-
c2w = np.loadtxt(os.path.join(self.root_dir, 'pose', pose_fname))# @ cam_trans
|
168 |
-
c2w = torch.FloatTensor(c2w)
|
169 |
-
self.poses.append(c2w) # C2W
|
170 |
-
rays_o, rays_d = get_rays(self.directions, c2w) # both (h*w, 3)
|
171 |
-
self.all_rays += [torch.cat([rays_o, rays_d], 1)] # (h*w, 8)
|
172 |
-
|
173 |
-
self.poses = torch.stack(self.poses)
|
174 |
-
|
175 |
-
center = torch.mean(self.scene_bbox, dim=0)
|
176 |
-
radius = torch.norm(self.scene_bbox[1]-center)*1.2
|
177 |
-
up = torch.mean(self.poses[:, :3, 1], dim=0).tolist()
|
178 |
-
pos_gen = circle(radius=radius, h=-0.2*up[1], axis='y')
|
179 |
-
self.render_path = gen_path(pos_gen, up=up,frames=100)
|
180 |
-
self.render_path[:, :3, 3] += center
|
181 |
-
|
182 |
-
|
183 |
-
all_rays = self.all_rays
|
184 |
-
all_rgbs = self.all_rgbs
|
185 |
-
self.all_masks = torch.stack(self.all_masks) # (n_frames, h, w, 1)
|
186 |
-
self.all_rays = torch.cat(self.all_rays, 0) # (len(self.meta['frames])*h*w,6)
|
187 |
-
self.all_rgbs = torch.cat(self.all_rgbs, 0) # (len(self.meta['frames])*h*w,3)
|
188 |
-
|
189 |
-
if self.is_stack:
|
190 |
-
self.all_rays_stack = torch.stack(all_rays, 0).reshape(-1,*self.img_wh[::-1], 6) # (len(self.meta['frames]),h,w,6)
|
191 |
-
avg_pool = torch.nn.AvgPool2d(4, ceil_mode=True)
|
192 |
-
self.ds_all_rays_stack = avg_pool(self.all_rays_stack.permute(0,3,1,2)).permute(0,2,3,1) # (len(self.meta['frames]),h/4,w/4,6)
|
193 |
-
self.all_rgbs_stack = torch.stack(all_rgbs, 0).reshape(-1,*self.img_wh[::-1], 3) # (len(self.meta['frames]),h,w,3)
|
194 |
-
|
195 |
-
@torch.no_grad()
|
196 |
-
def prepare_feature_data(self, encoder, chunk=4):
|
197 |
-
'''
|
198 |
-
Prepare feature maps as training data.
|
199 |
-
'''
|
200 |
-
assert self.is_stack, 'Dataset should contain original stacked taining data!'
|
201 |
-
print('====> prepare_feature_data ...')
|
202 |
-
|
203 |
-
frames_num, h, w, _ = self.all_rgbs_stack.size()
|
204 |
-
features = []
|
205 |
-
|
206 |
-
for chunk_idx in tqdm(range(frames_num // chunk + int(frames_num % chunk > 0))):
|
207 |
-
rgbs_chunk = self.all_rgbs_stack[chunk_idx*chunk : (chunk_idx+1)*chunk].cuda()
|
208 |
-
features_chunk = encoder(normalize_vgg(rgbs_chunk.permute(0,3,1,2))).relu3_1
|
209 |
-
# resize to the size of rgb map so that rays can match
|
210 |
-
features_chunk = T.functional.resize(features_chunk, size=(h,w),
|
211 |
-
interpolation=T.InterpolationMode.BILINEAR)
|
212 |
-
features.append(features_chunk.detach().cpu().requires_grad_(False))
|
213 |
-
|
214 |
-
self.all_features_stack = torch.cat(features).permute(0,2,3,1) # (len(self.meta['frames]),h,w,256)
|
215 |
-
self.all_features = self.all_features_stack.reshape(-1, 256)
|
216 |
-
print('prepare_feature_data Done!')
|
217 |
-
|
218 |
-
|
219 |
-
def define_transforms(self):
|
220 |
-
self.transform = T.ToTensor()
|
221 |
-
|
222 |
-
def define_proj_mat(self):
|
223 |
-
self.proj_mat = torch.from_numpy(self.intrinsics[:3,:3]).unsqueeze(0).float() @ torch.inverse(self.poses)[:,:3]
|
224 |
-
|
225 |
-
def world2ndc(self, points):
|
226 |
-
device = points.device
|
227 |
-
return (points - self.center.to(device)) / self.radius.to(device)
|
228 |
-
|
229 |
-
def __len__(self):
|
230 |
-
if self.split == 'train':
|
231 |
-
return len(self.all_rays)
|
232 |
-
return len(self.all_rgbs)
|
233 |
-
|
234 |
-
def __getitem__(self, idx):
|
235 |
-
|
236 |
-
if self.split == 'train': # use data in the buffers
|
237 |
-
sample = {'rays': self.all_rays[idx],
|
238 |
-
'rgbs': self.all_rgbs[idx]}
|
239 |
-
|
240 |
-
else: # create data for each image separately
|
241 |
-
|
242 |
-
img = self.all_rgbs[idx]
|
243 |
-
rays = self.all_rays[idx]
|
244 |
-
|
245 |
-
sample = {'rays': rays,
|
246 |
-
'rgbs': img}
|
247 |
-
return sample
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataLoader/your_own_data.py
DELETED
@@ -1,129 +0,0 @@
|
|
1 |
-
import torch,cv2
|
2 |
-
from torch.utils.data import Dataset
|
3 |
-
import json
|
4 |
-
from tqdm import tqdm
|
5 |
-
import os
|
6 |
-
from PIL import Image
|
7 |
-
from torchvision import transforms as T
|
8 |
-
|
9 |
-
|
10 |
-
from .ray_utils import *
|
11 |
-
|
12 |
-
|
13 |
-
class YourOwnDataset(Dataset):
|
14 |
-
def __init__(self, datadir, split='train', downsample=1.0, is_stack=False, N_vis=-1):
|
15 |
-
|
16 |
-
self.N_vis = N_vis
|
17 |
-
self.root_dir = datadir
|
18 |
-
self.split = split
|
19 |
-
self.is_stack = is_stack
|
20 |
-
self.downsample = downsample
|
21 |
-
self.define_transforms()
|
22 |
-
|
23 |
-
self.scene_bbox = torch.tensor([[-1.5, -1.5, -1.5], [1.5, 1.5, 1.5]])
|
24 |
-
self.blender2opencv = np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
|
25 |
-
self.read_meta()
|
26 |
-
self.define_proj_mat()
|
27 |
-
|
28 |
-
self.white_bg = True
|
29 |
-
self.near_far = [0.1,100.0]
|
30 |
-
|
31 |
-
self.center = torch.mean(self.scene_bbox, axis=0).float().view(1, 1, 3)
|
32 |
-
self.radius = (self.scene_bbox[1] - self.center).float().view(1, 1, 3)
|
33 |
-
self.downsample=downsample
|
34 |
-
|
35 |
-
def read_depth(self, filename):
|
36 |
-
depth = np.array(read_pfm(filename)[0], dtype=np.float32) # (800, 800)
|
37 |
-
return depth
|
38 |
-
|
39 |
-
def read_meta(self):
|
40 |
-
|
41 |
-
with open(os.path.join(self.root_dir, f"transforms_{self.split}.json"), 'r') as f:
|
42 |
-
self.meta = json.load(f)
|
43 |
-
|
44 |
-
w, h = int(self.meta['w']/self.downsample), int(self.meta['h']/self.downsample)
|
45 |
-
self.img_wh = [w,h]
|
46 |
-
self.focal_x = 0.5 * w / np.tan(0.5 * self.meta['camera_angle_x']) # original focal length
|
47 |
-
self.focal_y = 0.5 * h / np.tan(0.5 * self.meta['camera_angle_y']) # original focal length
|
48 |
-
self.cx, self.cy = self.meta['cx'],self.meta['cy']
|
49 |
-
|
50 |
-
|
51 |
-
# ray directions for all pixels, same for all images (same H, W, focal)
|
52 |
-
self.directions = get_ray_directions(h, w, [self.focal_x,self.focal_y], center=[self.cx, self.cy]) # (h, w, 3)
|
53 |
-
self.directions = self.directions / torch.norm(self.directions, dim=-1, keepdim=True)
|
54 |
-
self.intrinsics = torch.tensor([[self.focal_x,0,self.cx],[0,self.focal_y,self.cy],[0,0,1]]).float()
|
55 |
-
|
56 |
-
self.image_paths = []
|
57 |
-
self.poses = []
|
58 |
-
self.all_rays = []
|
59 |
-
self.all_rgbs = []
|
60 |
-
self.all_masks = []
|
61 |
-
self.all_depth = []
|
62 |
-
|
63 |
-
|
64 |
-
img_eval_interval = 1 if self.N_vis < 0 else len(self.meta['frames']) // self.N_vis
|
65 |
-
idxs = list(range(0, len(self.meta['frames']), img_eval_interval))
|
66 |
-
for i in tqdm(idxs, desc=f'Loading data {self.split} ({len(idxs)})'):#img_list:#
|
67 |
-
|
68 |
-
frame = self.meta['frames'][i]
|
69 |
-
pose = np.array(frame['transform_matrix']) @ self.blender2opencv
|
70 |
-
c2w = torch.FloatTensor(pose)
|
71 |
-
self.poses += [c2w]
|
72 |
-
|
73 |
-
image_path = os.path.join(self.root_dir, f"{frame['file_path']}.png")
|
74 |
-
self.image_paths += [image_path]
|
75 |
-
img = Image.open(image_path)
|
76 |
-
|
77 |
-
if self.downsample!=1.0:
|
78 |
-
img = img.resize(self.img_wh, Image.LANCZOS)
|
79 |
-
img = self.transform(img) # (4, h, w)
|
80 |
-
img = img.view(-1, w*h).permute(1, 0) # (h*w, 4) RGBA
|
81 |
-
if img.shape[-1]==4:
|
82 |
-
img = img[:, :3] * img[:, -1:] + (1 - img[:, -1:]) # blend A to RGB
|
83 |
-
self.all_rgbs += [img]
|
84 |
-
|
85 |
-
|
86 |
-
rays_o, rays_d = get_rays(self.directions, c2w) # both (h*w, 3)
|
87 |
-
self.all_rays += [torch.cat([rays_o, rays_d], 1)] # (h*w, 6)
|
88 |
-
|
89 |
-
|
90 |
-
self.poses = torch.stack(self.poses)
|
91 |
-
if not self.is_stack:
|
92 |
-
self.all_rays = torch.cat(self.all_rays, 0) # (len(self.meta['frames])*h*w, 3)
|
93 |
-
self.all_rgbs = torch.cat(self.all_rgbs, 0) # (len(self.meta['frames])*h*w, 3)
|
94 |
-
|
95 |
-
# self.all_depth = torch.cat(self.all_depth, 0) # (len(self.meta['frames])*h*w, 3)
|
96 |
-
else:
|
97 |
-
self.all_rays = torch.stack(self.all_rays, 0) # (len(self.meta['frames]),h*w, 3)
|
98 |
-
self.all_rgbs = torch.stack(self.all_rgbs, 0).reshape(-1,*self.img_wh[::-1], 3) # (len(self.meta['frames]),h,w,3)
|
99 |
-
# self.all_masks = torch.stack(self.all_masks, 0).reshape(-1,*self.img_wh[::-1]) # (len(self.meta['frames]),h,w,3)
|
100 |
-
|
101 |
-
|
102 |
-
def define_transforms(self):
|
103 |
-
self.transform = T.ToTensor()
|
104 |
-
|
105 |
-
def define_proj_mat(self):
|
106 |
-
self.proj_mat = self.intrinsics.unsqueeze(0) @ torch.inverse(self.poses)[:,:3]
|
107 |
-
|
108 |
-
def world2ndc(self,points,lindisp=None):
|
109 |
-
device = points.device
|
110 |
-
return (points - self.center.to(device)) / self.radius.to(device)
|
111 |
-
|
112 |
-
def __len__(self):
|
113 |
-
return len(self.all_rgbs)
|
114 |
-
|
115 |
-
def __getitem__(self, idx):
|
116 |
-
|
117 |
-
if self.split == 'train': # use data in the buffers
|
118 |
-
sample = {'rays': self.all_rays[idx],
|
119 |
-
'rgbs': self.all_rgbs[idx]}
|
120 |
-
|
121 |
-
else: # create data for each image separately
|
122 |
-
|
123 |
-
img = self.all_rgbs[idx]
|
124 |
-
rays = self.all_rays[idx]
|
125 |
-
mask = self.all_masks[idx] # for quantity evaluation
|
126 |
-
|
127 |
-
sample = {'rays': rays,
|
128 |
-
'rgbs': img}
|
129 |
-
return sample
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extra/auto_run_paramsets.py
DELETED
@@ -1,207 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import threading, queue
|
3 |
-
import numpy as np
|
4 |
-
import time
|
5 |
-
|
6 |
-
|
7 |
-
def getFolderLocker(logFolder):
|
8 |
-
while True:
|
9 |
-
try:
|
10 |
-
os.makedirs(logFolder+"/lockFolder")
|
11 |
-
break
|
12 |
-
except:
|
13 |
-
time.sleep(0.01)
|
14 |
-
|
15 |
-
def releaseFolderLocker(logFolder):
|
16 |
-
os.removedirs(logFolder+"/lockFolder")
|
17 |
-
|
18 |
-
def getStopFolder(logFolder):
|
19 |
-
return os.path.isdir(logFolder+"/stopFolder")
|
20 |
-
|
21 |
-
|
22 |
-
def get_param_str(key, val):
|
23 |
-
if key == 'data_name':
|
24 |
-
return f'--datadir {datafolder}/{val} '
|
25 |
-
else:
|
26 |
-
return f'--{key} {val} '
|
27 |
-
|
28 |
-
def get_param_list(param_dict):
|
29 |
-
param_keys = list(param_dict.keys())
|
30 |
-
param_modes = len(param_keys)
|
31 |
-
param_nums = [len(param_dict[key]) for key in param_keys]
|
32 |
-
|
33 |
-
param_ids = np.zeros(param_nums+[param_modes], dtype=int)
|
34 |
-
for i in range(param_modes):
|
35 |
-
broad_tuple = np.ones(param_modes, dtype=int).tolist()
|
36 |
-
broad_tuple[i] = param_nums[i]
|
37 |
-
broad_tuple = tuple(broad_tuple)
|
38 |
-
print(broad_tuple)
|
39 |
-
param_ids[...,i] = np.arange(param_nums[i]).reshape(broad_tuple)
|
40 |
-
param_ids = param_ids.reshape(-1, param_modes)
|
41 |
-
# print(param_ids)
|
42 |
-
print(len(param_ids))
|
43 |
-
|
44 |
-
params = []
|
45 |
-
expnames = []
|
46 |
-
for i in range(param_ids.shape[0]):
|
47 |
-
one = ""
|
48 |
-
name = ""
|
49 |
-
param_id = param_ids[i]
|
50 |
-
for j in range(param_modes):
|
51 |
-
key = param_keys[j]
|
52 |
-
val = param_dict[key][param_id[j]]
|
53 |
-
if type(key) is tuple:
|
54 |
-
assert len(key) == len(val)
|
55 |
-
for k in range(len(key)):
|
56 |
-
one += get_param_str(key[k], val[k])
|
57 |
-
name += f'{val[k]},'
|
58 |
-
name=name[:-1]+'-'
|
59 |
-
else:
|
60 |
-
one += get_param_str(key, val)
|
61 |
-
name += f'{val}-'
|
62 |
-
params.append(one)
|
63 |
-
name=name.replace(' ','')
|
64 |
-
print(name)
|
65 |
-
expnames.append(name[:-1])
|
66 |
-
# print(params)
|
67 |
-
return params, expnames
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
if __name__ == '__main__':
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
# nerf
|
80 |
-
expFolder = "nerf/"
|
81 |
-
# parameters to iterate, use tuple to couple multiple parameters
|
82 |
-
datafolder = '/mnt/new_disk_2/anpei/Dataset/nerf_synthetic/'
|
83 |
-
param_dict = {
|
84 |
-
'data_name': ['ship', 'mic', 'chair', 'lego', 'drums', 'ficus', 'hotdog', 'materials'],
|
85 |
-
'data_dim_color': [13, 27, 54]
|
86 |
-
}
|
87 |
-
|
88 |
-
# n_iters = 30000
|
89 |
-
# for data_name in ['Robot']:#'Bike','Lifestyle','Palace','Robot','Spaceship','Steamtrain','Toad','Wineholder'
|
90 |
-
# cmd = f'CUDA_VISIBLE_DEVICES={cuda} python train.py ' \
|
91 |
-
# f'--dataset_name nsvf --datadir /mnt/new_disk_2/anpei/Dataset/TeRF/Synthetic_NSVF/{data_name} '\
|
92 |
-
# f'--expname {data_name} --batch_size {batch_size} ' \
|
93 |
-
# f'--n_iters {n_iters} ' \
|
94 |
-
# f'--N_voxel_init {128**3} --N_voxel_final {300**3} '\
|
95 |
-
# f'--N_vis {5} ' \
|
96 |
-
# f'--n_lamb_sigma "[16,16,16]" --n_lamb_sh "[48,48,48]" ' \
|
97 |
-
# f'--upsamp_list "[2000, 3000, 4000, 5500,7000]" --update_AlphaMask_list "[3000,4000]" ' \
|
98 |
-
# f'--shadingMode MLP_Fea --fea2denseAct softplus --view_pe {2} --fea_pe {2} ' \
|
99 |
-
# f'--L1_weight_inital {8e-5} --L1_weight_rest {4e-5} --rm_weight_mask_thre {1e-4} --add_timestamp 0 ' \
|
100 |
-
# f'--render_test 1 '
|
101 |
-
# print(cmd)
|
102 |
-
# os.system(cmd)
|
103 |
-
|
104 |
-
# nsvf
|
105 |
-
# expFolder = "nsvf_0227/"
|
106 |
-
# datafolder = '/mnt/new_disk_2/anpei/Dataset/TeRF/Synthetic_NSVF/'
|
107 |
-
# param_dict = {
|
108 |
-
# 'data_name': ['Robot','Steamtrain','Bike','Lifestyle','Palace','Spaceship','Toad','Wineholder'],#'Bike','Lifestyle','Palace','Robot','Spaceship','Steamtrain','Toad','Wineholder'
|
109 |
-
# 'shadingMode': ['SH'],
|
110 |
-
# ('n_lamb_sigma', 'n_lamb_sh'): [ ("[8,8,8]", "[8,8,8]")],
|
111 |
-
# ('view_pe', 'fea_pe', 'featureC','fea2denseAct','N_voxel_init') : [(2, 2, 128, 'softplus',128**3)],
|
112 |
-
# ('L1_weight_inital', 'L1_weight_rest', 'rm_weight_mask_thre'):[(4e-5, 4e-5, 1e-4)],
|
113 |
-
# ('n_iters','N_voxel_final'): [(30000,300**3)],
|
114 |
-
# ('dataset_name','N_vis','render_test') : [("nsvf",5,1)],
|
115 |
-
# ('upsamp_list','update_AlphaMask_list'): [("[2000,3000,4000,5500,7000]","[3000,4000]")]
|
116 |
-
#
|
117 |
-
# }
|
118 |
-
|
119 |
-
# tankstemple
|
120 |
-
# expFolder = "tankstemple_0304/"
|
121 |
-
# datafolder = '/mnt/new_disk_2/anpei/Dataset/TeRF/TanksAndTemple/'
|
122 |
-
# param_dict = {
|
123 |
-
# 'data_name': ['Truck','Barn','Caterpillar','Family','Ignatius'],
|
124 |
-
# 'shadingMode': ['MLP_Fea'],
|
125 |
-
# ('n_lamb_sigma', 'n_lamb_sh'): [("[16,16,16]", "[48,48,48]")],
|
126 |
-
# ('view_pe', 'fea_pe','fea2denseAct','N_voxel_init','render_test') : [(2, 2, 'softplus',128**3,1)],
|
127 |
-
# ('TV_weight_density','TV_weight_app'):[(0.1,0.01)],
|
128 |
-
# # ('L1_weight_inital', 'L1_weight_rest', 'rm_weight_mask_thre'): [(4e-5, 4e-5, 1e-4)],
|
129 |
-
# ('n_iters','N_voxel_final'): [(15000,300**3)],
|
130 |
-
# ('dataset_name','N_vis') : [("tankstemple",5)],
|
131 |
-
# ('upsamp_list','update_AlphaMask_list'): [("[2000,3000,4000,5500,7000]","[2000,4000]")]
|
132 |
-
# }
|
133 |
-
|
134 |
-
# llff
|
135 |
-
# expFolder = "real_iconic/"
|
136 |
-
# datafolder = '/mnt/new_disk_2/anpei/Dataset/MVSNeRF/real_iconic/'
|
137 |
-
# List = os.listdir(datafolder)
|
138 |
-
# param_dict = {
|
139 |
-
# 'data_name': List,
|
140 |
-
# ('shadingMode', 'view_pe', 'fea_pe','fea2denseAct', 'nSamples','N_voxel_init') : [('MLP_Fea', 0, 0, 'relu',512,128**3)],
|
141 |
-
# ('n_lamb_sigma', 'n_lamb_sh') : [("[16,4,4]", "[48,12,12]")],
|
142 |
-
# ('TV_weight_density', 'TV_weight_app'):[(1.0,1.0)],
|
143 |
-
# ('n_iters','N_voxel_final'): [(25000,640**3)],
|
144 |
-
# ('dataset_name','downsample_train','ndc_ray','N_vis','render_path') : [("llff",4.0, 1,-1,1)],
|
145 |
-
# ('upsamp_list','update_AlphaMask_list'): [("[2000,3000,4000,5500,7000]","[2500]")],
|
146 |
-
# }
|
147 |
-
|
148 |
-
# expFolder = "llff/"
|
149 |
-
# datafolder = '/mnt/new_disk_2/anpei/Dataset/MVSNeRF/nerf_llff_data'
|
150 |
-
# param_dict = {
|
151 |
-
# 'data_name': ['fern', 'flower', 'room', 'leaves', 'horns', 'trex', 'fortress', 'orchids'],#'fern', 'flower', 'room', 'leaves', 'horns', 'trex', 'fortress', 'orchids'
|
152 |
-
# ('n_lamb_sigma', 'n_lamb_sh'): [("[16,4,4]", "[48,12,12]")],
|
153 |
-
# ('shadingMode', 'view_pe', 'fea_pe', 'featureC','fea2denseAct', 'nSamples','N_voxel_init') : [('MLP_Fea', 0, 0, 128, 'relu',512,128**3),('SH', 0, 0, 128, 'relu',512,128**3)],
|
154 |
-
# ('TV_weight_density', 'TV_weight_app'):[(1.0,1.0)],
|
155 |
-
# ('n_iters','N_voxel_final'): [(25000,640**3)],
|
156 |
-
# ('dataset_name','downsample_train','ndc_ray','N_vis','render_test','render_path') : [("llff",4.0, 1,-1,1,1)],
|
157 |
-
# ('upsamp_list','update_AlphaMask_list'): [("[2000,3000,4000,5500,7000]","[2500]")],
|
158 |
-
# }
|
159 |
-
|
160 |
-
#setting available gpus
|
161 |
-
gpus_que = queue.Queue(3)
|
162 |
-
for i in [1,2,3]:
|
163 |
-
gpus_que.put(i)
|
164 |
-
|
165 |
-
os.makedirs(f"log/{expFolder}", exist_ok=True)
|
166 |
-
|
167 |
-
def run_program(gpu, expname, param):
|
168 |
-
cmd = f'CUDA_VISIBLE_DEVICES={gpu} python train.py ' \
|
169 |
-
f'--expname {expname} --basedir ./log/{expFolder} --config configs/lego.txt ' \
|
170 |
-
f'{param}' \
|
171 |
-
f'> "log/{expFolder}{expname}/{expname}.txt"'
|
172 |
-
print(cmd)
|
173 |
-
os.system(cmd)
|
174 |
-
gpus_que.put(gpu)
|
175 |
-
|
176 |
-
params, expnames = get_param_list(param_dict)
|
177 |
-
|
178 |
-
|
179 |
-
logFolder=f"log/{expFolder}"
|
180 |
-
os.makedirs(logFolder, exist_ok=True)
|
181 |
-
|
182 |
-
ths = []
|
183 |
-
for i in range(len(params)):
|
184 |
-
|
185 |
-
if getStopFolder(logFolder):
|
186 |
-
break
|
187 |
-
|
188 |
-
|
189 |
-
targetFolder = f"log/{expFolder}{expnames[i]}"
|
190 |
-
gpu = gpus_que.get()
|
191 |
-
getFolderLocker(logFolder)
|
192 |
-
if os.path.isdir(targetFolder):
|
193 |
-
releaseFolderLocker(logFolder)
|
194 |
-
gpus_que.put(gpu)
|
195 |
-
continue
|
196 |
-
else:
|
197 |
-
os.makedirs(targetFolder, exist_ok=True)
|
198 |
-
print("making",targetFolder, "running",expnames[i], params[i])
|
199 |
-
releaseFolderLocker(logFolder)
|
200 |
-
|
201 |
-
|
202 |
-
t = threading.Thread(target=run_program, args=(gpu, expnames[i], params[i]), daemon=True)
|
203 |
-
t.start()
|
204 |
-
ths.append(t)
|
205 |
-
|
206 |
-
for th in ths:
|
207 |
-
th.join()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inference.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
import torch
|
5 |
+
from lightning_fabric import seed_everything
|
6 |
+
from PIL import Image, ImageFile
|
7 |
+
|
8 |
+
from src.dataset import DATASET_REGISTRY
|
9 |
+
from src.decoder import DECODER_REGISTRY
|
10 |
+
from src.utils.opt import Opts
|
11 |
+
import torchvision.transforms as T
|
12 |
+
|
13 |
+
from src.utils.renderer import evaluation_feature, evaluation_feature_path, OctreeRender_trilinear_fast
|
14 |
+
|
15 |
+
|
16 |
+
def inference(cfg, render_mode: str, image=None):
|
17 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
+
|
19 |
+
ckpt = torch.load(cfg["model"]["tensorf"]["ckpt"], map_location=device)
|
20 |
+
kwargs = ckpt['kwargs']
|
21 |
+
kwargs.update({'device': device})
|
22 |
+
print(device)
|
23 |
+
tensorf = DECODER_REGISTRY.get(cfg["model"]["tensorf"]["model_name"])(**kwargs)
|
24 |
+
tensorf.change_to_feature_mod(cfg["model"]["tensorf"]["lamb_sh"], device)
|
25 |
+
tensorf.change_to_style_mod(device)
|
26 |
+
tensorf.load(ckpt)
|
27 |
+
tensorf.eval()
|
28 |
+
tensorf.rayMarch_weight_thres = cfg["model"]["tensorf"]["rm_weight_mask_thre"]
|
29 |
+
|
30 |
+
logfolder = os.path.dirname("./checkpoints")
|
31 |
+
renderer= OctreeRender_trilinear_fast
|
32 |
+
|
33 |
+
trans = T.Compose([T.Resize(size=(256, 256)), T.ToTensor()])
|
34 |
+
if image:
|
35 |
+
style_img = trans(image).cuda()[None, ...]
|
36 |
+
else:
|
37 |
+
style_img = trans(Image.open(cfg["global"]["style_img"])).cuda()[None, ...]
|
38 |
+
style_name = Path(cfg["global"]["style_img"]).stem
|
39 |
+
|
40 |
+
if render_mode == "render_train":
|
41 |
+
dataset = DATASET_REGISTRY.get(cfg["dataset"]["name"])(
|
42 |
+
**cfg["dataset"]["train"]["params"],
|
43 |
+
)
|
44 |
+
os.makedirs(f'{logfolder}/{cfg["global"]["expname"]}/imgs_train_all/{style_name}', exist_ok=True)
|
45 |
+
result = evaluation_feature(dataset, tensorf, renderer, cfg["sampler"]["params"]["chunk_size"],
|
46 |
+
f'{logfolder}/{cfg["global"]["expname"]}/imgs_train_all/{style_name}',
|
47 |
+
N_vis=-1, N_samples=-1, white_bg=dataset.white_bg, ndc_ray=cfg["model"]["tensorf"]["ndc_ray"],
|
48 |
+
style_img=style_img, device=device)
|
49 |
+
|
50 |
+
if render_mode == "render_test":
|
51 |
+
dataset = DATASET_REGISTRY.get(cfg["dataset"]["name"])(
|
52 |
+
**cfg["dataset"]["val"]["params"],
|
53 |
+
)
|
54 |
+
os.makedirs(f'{logfolder}/{cfg["global"]["expname"]}/imgs_train_all/{style_name}', exist_ok=True)
|
55 |
+
result = evaluation_feature(dataset, tensorf, renderer, cfg["sampler"]["params"]["chunk_size"],
|
56 |
+
f'{logfolder}/{cfg["global"]["expname"]}/imgs_train_all/{style_name}',
|
57 |
+
N_vis=-1, N_samples=-1, white_bg=dataset.white_bg, ndc_ray=cfg["model"]["tensorf"]["ndc_ray"],
|
58 |
+
style_img=style_img, device=device)
|
59 |
+
|
60 |
+
if render_mode == "render_path":
|
61 |
+
dataset = DATASET_REGISTRY.get(cfg["dataset"]["name"])(
|
62 |
+
**cfg["dataset"]["val"]["params"],
|
63 |
+
)
|
64 |
+
c2ws = dataset.render_path
|
65 |
+
os.makedirs(f'{logfolder}/{cfg["global"]["expname"]}/imgs_path_all/{style_name}', exist_ok=True)
|
66 |
+
result = evaluation_feature_path(dataset, tensorf, c2ws, renderer, cfg["sampler"]["params"]["chunk_size"],
|
67 |
+
f'{logfolder}/{cfg["global"]["expname"]}/imgs_path_all/{style_name}',
|
68 |
+
N_vis=-1, N_samples=-1, white_bg=dataset.white_bg, ndc_ray=cfg["model"]["tensorf"]["ndc_ray"],
|
69 |
+
style_img=style_img, device=device)
|
70 |
+
return result
|
71 |
+
|
72 |
+
if __name__ == "__main__":
|
73 |
+
cfg = Opts(cfg="configs/style_inference.yml").parse_args()
|
74 |
+
seed_everything(seed=cfg["global"]["SEED"])
|
75 |
+
inference(cfg, "render_test")
|
main.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import imageio.v3 as iio
|
4 |
+
from inference import inference
|
5 |
+
from src.utils.opt import Opts
|
6 |
+
import os
|
7 |
+
|
8 |
+
st.set_page_config(layout='wide')
|
9 |
+
|
10 |
+
st.markdown(
|
11 |
+
"""
|
12 |
+
<style>
|
13 |
+
div[data-testid="column"]:nth-of-type(1)
|
14 |
+
{
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
div[data-testid="column"]:nth-of-type(2)
|
19 |
+
{
|
20 |
+
|
21 |
+
}
|
22 |
+
</style>
|
23 |
+
""",unsafe_allow_html=True
|
24 |
+
)
|
25 |
+
|
26 |
+
col1, col2, col3 = st.columns(3)
|
27 |
+
|
28 |
+
if 'counter' not in st.session_state:
|
29 |
+
st.session_state.video_path = None
|
30 |
+
st.session_state.image = None
|
31 |
+
st.session_state.counter = 0
|
32 |
+
|
33 |
+
def showVideo(image):
|
34 |
+
if st.session_state.image is not None:
|
35 |
+
cfg = Opts(cfg="configs/style_inference.yml").parse_args()
|
36 |
+
result = inference(cfg, "render_test", image=image)
|
37 |
+
st.session_state.video_path = result["video_path"]
|
38 |
+
st.session_state.counter += 1
|
39 |
+
else:
|
40 |
+
col2.write("No uploaded image")
|
41 |
+
|
42 |
+
with col1:
|
43 |
+
col1.subheader("Source multiview images")
|
44 |
+
filteredImages = []
|
45 |
+
for image_file in os.listdir('data/nerf_llff_data/trex/streamlit_images'):
|
46 |
+
filteredImages.append(Image.open(os.path.join('data/nerf_llff_data/trex/streamlit_images', image_file)))
|
47 |
+
id = 0
|
48 |
+
for img in range(0, len(filteredImages), 4):
|
49 |
+
cols = col1.columns(4)
|
50 |
+
cols[0].image(filteredImages[id], use_column_width=True)
|
51 |
+
id +=1
|
52 |
+
cols[1].image(filteredImages[id], use_column_width=True)
|
53 |
+
id +=1
|
54 |
+
cols[2].image(filteredImages[id], use_column_width=True)
|
55 |
+
id +=1
|
56 |
+
cols[3].image(filteredImages[id], use_column_width=True)
|
57 |
+
id +=1
|
58 |
+
|
59 |
+
|
60 |
+
with col2:
|
61 |
+
col2.subheader("Style image")
|
62 |
+
uploaded_file = col2.file_uploader("Choose a image file")
|
63 |
+
if uploaded_file:
|
64 |
+
st.session_state.image = Image.open(uploaded_file)
|
65 |
+
img = col2.image(st.session_state.image, caption='Style Image', use_column_width=True)
|
66 |
+
col2.button('Run Style Transfer', on_click=showVideo, args=([st.session_state.image]))
|
67 |
+
|
68 |
+
|
69 |
+
col3.subheader("Style videos")
|
70 |
+
if st.session_state.counter > 0:
|
71 |
+
video_file = open(st.session_state.video_path, 'rb')
|
72 |
+
video_bytes = video_file.read()
|
73 |
+
col3.video(video_bytes)
|
74 |
+
|
75 |
+
|
models/__pycache__/__init__.cpython-38.pyc
DELETED
Binary file (142 Bytes)
|
|
opt.py
DELETED
@@ -1,153 +0,0 @@
|
|
1 |
-
import configargparse
|
2 |
-
|
3 |
-
def config_parser(cmd=None):
|
4 |
-
parser = configargparse.ArgumentParser()
|
5 |
-
parser.add_argument('--config', is_config_file=True,
|
6 |
-
help='config file path')
|
7 |
-
parser.add_argument("--expname", type=str,
|
8 |
-
help='experiment name')
|
9 |
-
parser.add_argument("--basedir", type=str, default='./log',
|
10 |
-
help='where to store ckpts and logs')
|
11 |
-
parser.add_argument("--add_timestamp", type=int, default=0,
|
12 |
-
help='add timestamp to dir')
|
13 |
-
parser.add_argument("--datadir", type=str, default='./data/llff/fern',
|
14 |
-
help='input data directory')
|
15 |
-
parser.add_argument("--wikiartdir", type=str, default='./data/WikiArt',
|
16 |
-
help='input data directory')
|
17 |
-
parser.add_argument("--progress_refresh_rate", type=int, default=10,
|
18 |
-
help='how many iterations to show psnrs or iters')
|
19 |
-
|
20 |
-
parser.add_argument('--with_depth', action='store_true')
|
21 |
-
parser.add_argument('--downsample_train', type=float, default=1.0)
|
22 |
-
parser.add_argument('--downsample_test', type=float, default=1.0)
|
23 |
-
|
24 |
-
parser.add_argument('--model_name', type=str, default='TensorVMSplit',
|
25 |
-
choices=['TensorVMSplit', 'TensorCP'])
|
26 |
-
|
27 |
-
# loader options
|
28 |
-
parser.add_argument("--batch_size", type=int, default=4096)
|
29 |
-
parser.add_argument("--n_iters", type=int, default=30000)
|
30 |
-
parser.add_argument('--dataset_name', type=str, default='blender',
|
31 |
-
choices=['blender', 'llff', 'nsvf', 'dtu','tankstemple', 'own_data'])
|
32 |
-
|
33 |
-
|
34 |
-
# training options
|
35 |
-
parser.add_argument("--patch_size", type=int, default=256,
|
36 |
-
help='patch_size for training')
|
37 |
-
parser.add_argument("--chunk_size", type=int, default=4096,
|
38 |
-
help='chunk_size for training')
|
39 |
-
# learning rate
|
40 |
-
parser.add_argument("--lr_init", type=float, default=0.02,
|
41 |
-
help='learning rate')
|
42 |
-
parser.add_argument("--lr_basis", type=float, default=1e-4,
|
43 |
-
help='learning rate')
|
44 |
-
parser.add_argument("--lr_finetune", type=float, default=1e-5,
|
45 |
-
help='learning rate')
|
46 |
-
parser.add_argument("--lr_decay_iters", type=int, default=-1,
|
47 |
-
help = 'number of iterations the lr will decay to the target ratio; -1 will set it to n_iters')
|
48 |
-
parser.add_argument("--lr_decay_target_ratio", type=float, default=0.1,
|
49 |
-
help='the target decay ratio; after decay_iters inital lr decays to lr*ratio')
|
50 |
-
parser.add_argument("--lr_upsample_reset", type=int, default=1,
|
51 |
-
help='reset lr to inital after upsampling')
|
52 |
-
|
53 |
-
# loss
|
54 |
-
parser.add_argument("--L1_weight_inital", type=float, default=0.0,
|
55 |
-
help='loss weight')
|
56 |
-
parser.add_argument("--L1_weight_rest", type=float, default=0,
|
57 |
-
help='loss weight')
|
58 |
-
parser.add_argument("--Ortho_weight", type=float, default=0.0,
|
59 |
-
help='loss weight')
|
60 |
-
parser.add_argument("--TV_weight_density", type=float, default=0.0,
|
61 |
-
help='loss weight')
|
62 |
-
parser.add_argument("--TV_weight_app", type=float, default=0.0,
|
63 |
-
help='loss weight')
|
64 |
-
parser.add_argument("--TV_weight_feature", type=float, default=0.0,
|
65 |
-
help='loss weight')
|
66 |
-
parser.add_argument("--style_weight", type=float, default=0,
|
67 |
-
help='loss weight')
|
68 |
-
parser.add_argument("--content_weight", type=float, default=0,
|
69 |
-
help='loss weight')
|
70 |
-
parser.add_argument("--image_tv_weight", type=float, default=0,
|
71 |
-
help='loss weight')
|
72 |
-
parser.add_argument("--featuremap_tv_weight", type=float, default=0,
|
73 |
-
help='loss weight')
|
74 |
-
|
75 |
-
|
76 |
-
# model
|
77 |
-
# volume options
|
78 |
-
parser.add_argument("--n_lamb_sigma", type=int, action="append")
|
79 |
-
parser.add_argument("--n_lamb_sh", type=int, action="append")
|
80 |
-
parser.add_argument("--data_dim_color", type=int, default=27)
|
81 |
-
|
82 |
-
parser.add_argument("--rm_weight_mask_thre", type=float, default=0.0001,
|
83 |
-
help='mask points in ray marching')
|
84 |
-
parser.add_argument("--alpha_mask_thre", type=float, default=0.0001,
|
85 |
-
help='threshold for creating alpha mask volume')
|
86 |
-
parser.add_argument("--distance_scale", type=float, default=25,
|
87 |
-
help='scaling sampling distance for computation')
|
88 |
-
parser.add_argument("--density_shift", type=float, default=-10,
|
89 |
-
help='shift density in softplus; making density = 0 when feature == 0')
|
90 |
-
|
91 |
-
# network decoder
|
92 |
-
parser.add_argument("--shadingMode", type=str, default="MLP_Fea",
|
93 |
-
help='which shading mode to use')
|
94 |
-
parser.add_argument("--pos_pe", type=int, default=6,
|
95 |
-
help='number of pe for pos')
|
96 |
-
parser.add_argument("--view_pe", type=int, default=6,
|
97 |
-
help='number of pe for view')
|
98 |
-
parser.add_argument("--fea_pe", type=int, default=6,
|
99 |
-
help='number of pe for features')
|
100 |
-
parser.add_argument("--featureC", type=int, default=128,
|
101 |
-
help='hidden feature channel in MLP')
|
102 |
-
|
103 |
-
|
104 |
-
# test option
|
105 |
-
parser.add_argument("--ckpt", type=str, default=None,
|
106 |
-
help='specific weights npy file to reload for coarse network')
|
107 |
-
parser.add_argument("--render_only", type=int, default=0)
|
108 |
-
parser.add_argument("--render_test", type=int, default=0)
|
109 |
-
parser.add_argument("--render_train", type=int, default=0)
|
110 |
-
parser.add_argument("--render_path", type=int, default=0)
|
111 |
-
parser.add_argument("--export_mesh", type=int, default=0)
|
112 |
-
parser.add_argument("--style_img", type=str, required=False)
|
113 |
-
|
114 |
-
# rendering options
|
115 |
-
parser.add_argument('--lindisp', default=False, action="store_true",
|
116 |
-
help='use disparity depth sampling')
|
117 |
-
parser.add_argument("--perturb", type=float, default=1.,
|
118 |
-
help='set to 0. for no jitter, 1. for jitter')
|
119 |
-
parser.add_argument("--accumulate_decay", type=float, default=0.998)
|
120 |
-
parser.add_argument("--fea2denseAct", type=str, default='softplus')
|
121 |
-
parser.add_argument('--ndc_ray', type=int, default=0)
|
122 |
-
parser.add_argument('--nSamples', type=int, default=1e6,
|
123 |
-
help='sample point each ray, pass 1e6 if automatic adjust')
|
124 |
-
parser.add_argument('--step_ratio',type=float,default=0.5)
|
125 |
-
|
126 |
-
|
127 |
-
## blender flags
|
128 |
-
parser.add_argument("--white_bkgd", action='store_true',
|
129 |
-
help='set to render synthetic data on a white bkgd (always use for dvoxels)')
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
parser.add_argument('--N_voxel_init',
|
134 |
-
type=int,
|
135 |
-
default=100**3)
|
136 |
-
parser.add_argument('--N_voxel_final',
|
137 |
-
type=int,
|
138 |
-
default=300**3)
|
139 |
-
parser.add_argument("--upsamp_list", type=int, action="append")
|
140 |
-
parser.add_argument("--update_AlphaMask_list", type=int, action="append")
|
141 |
-
|
142 |
-
parser.add_argument('--idx_view',
|
143 |
-
type=int,
|
144 |
-
default=0)
|
145 |
-
# logging/saving options
|
146 |
-
parser.add_argument("--N_vis", type=int, default=5,
|
147 |
-
help='N images to vis')
|
148 |
-
parser.add_argument("--vis_every", type=int, default=10000,
|
149 |
-
help='frequency of visualize the image')
|
150 |
-
if cmd is not None:
|
151 |
-
return parser.parse_args(cmd)
|
152 |
-
else:
|
153 |
-
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,11 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
tqdm
|
2 |
configargparse
|
3 |
Pillow
|
4 |
imageio
|
5 |
kornia
|
6 |
opencv-python
|
7 |
-
torch
|
8 |
-
torchvision
|
9 |
scipy
|
10 |
plyfile
|
11 |
streamlit
|
|
|
|
|
|
|
|
1 |
+
pytorch_lightning==1.9.0
|
2 |
+
transformers==4.26.1
|
3 |
+
pytorch_metric_learning==2.0.1
|
4 |
+
pandas==1.5.3
|
5 |
+
pymeshlab
|
6 |
+
tabulate
|
7 |
+
torchvision
|
8 |
+
matplotlib
|
9 |
+
wandb==0.13.10
|
10 |
tqdm
|
11 |
configargparse
|
12 |
Pillow
|
13 |
imageio
|
14 |
kornia
|
15 |
opencv-python
|
|
|
|
|
16 |
scipy
|
17 |
plyfile
|
18 |
streamlit
|
19 |
+
lpips
|
20 |
+
imageio[ffmpeg]
|
21 |
+
pdf2image
|
scripts/test.sh
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
CUDA_VISIBLE_DEVICES=$1 python train.py \
|
2 |
-
--config configs/llff.txt \
|
3 |
-
--ckpt log/trex/trex.th \
|
4 |
-
--render_only 1
|
5 |
-
--render_test 1
|
|
|
|
|
|
|
|
|
|
|
|
scripts/test_feature.sh
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
expname=trex
|
2 |
-
CUDA_VISIBLE_DEVICES=$1 python train_feature.py \
|
3 |
-
--config configs/llff_feature.txt \
|
4 |
-
--datadir ./data/nerf_llff_data/trex \
|
5 |
-
--expname $expname \
|
6 |
-
--ckpt ./log_feature/$expname/$expname.th \
|
7 |
-
--render_only 1 \
|
8 |
-
--render_test 0 \
|
9 |
-
--render_path 1 \
|
10 |
-
--chunk_size 1024
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/test_style.sh
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
expname=trex
|
2 |
-
python train_style.py \
|
3 |
-
--config configs/llff_style.txt \
|
4 |
-
--datadir ./data/nerf_llff_data/trex \
|
5 |
-
--expname $expname \
|
6 |
-
--ckpt log_style/$expname/$expname.th \
|
7 |
-
--style_img image_style/example.jpg \
|
8 |
-
--render_only 1 \
|
9 |
-
--render_train 0 \
|
10 |
-
--render_test 0 \
|
11 |
-
--render_path 1 \
|
12 |
-
--chunk_size 1024 \
|
13 |
-
--rm_weight_mask_thre 0.0001 \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/train.sh
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
CUDA_VISIBLE_DEVICES=$1 python train.py --config=configs/llff.txt
|
|
|
|
scripts/train_feature.sh
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
CUDA_VISIBLE_DEVICES=$1 python train_feature.py --config=configs/llff_feature.txt
|
|
|
|
scripts/train_style.sh
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
CUDA_VISIBLE_DEVICES=$1 python train_style.py --config=configs/llff_style.txt
|
|
|
|
{models β src}/__init__.py
RENAMED
File without changes
|
src/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (154 Bytes). View file
|
|
src/callback/__init__.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pytorch_lightning.callbacks import (
|
2 |
+
ModelCheckpoint,
|
3 |
+
LearningRateMonitor,
|
4 |
+
EarlyStopping,
|
5 |
+
)
|
6 |
+
from src.utils.registry import Registry
|
7 |
+
|
8 |
+
# from src.callback.visualizer_callbacks import VisualizerCallback
|
9 |
+
|
10 |
+
CALLBACK_REGISTRY = Registry("CALLBACK")
|
11 |
+
|
12 |
+
CALLBACK_REGISTRY.register(EarlyStopping)
|
13 |
+
CALLBACK_REGISTRY.register(ModelCheckpoint)
|
14 |
+
CALLBACK_REGISTRY.register(LearningRateMonitor)
|
15 |
+
# TODO: add WandB visualizer callback
|
16 |
+
# CALLBACK_REGISTRY.register(VisualizerCallback)
|
src/callback/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (420 Bytes). View file
|
|
src/dataset/__init__.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from src.dataset.blender_dataset import BlenderDataset
|
2 |
+
from src.dataset.llff_dataset import LLFFDataset
|
3 |
+
from src.dataset.style_dataset import StyleDataset
|
4 |
+
from src.utils.registry import Registry
|
5 |
+
|
6 |
+
DATASET_REGISTRY = Registry("DATASET")
|
7 |
+
|
8 |
+
DATASET_REGISTRY.register(BlenderDataset)
|
9 |
+
DATASET_REGISTRY.register(LLFFDataset)
|
10 |
+
DATASET_REGISTRY.register(StyleDataset)
|
src/dataset/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (484 Bytes). View file
|
|
dataLoader/__pycache__/blender.cpython-38.pyc β src/dataset/__pycache__/blender_dataset.cpython-38.pyc
RENAMED
Binary files a/dataLoader/__pycache__/blender.cpython-38.pyc and b/src/dataset/__pycache__/blender_dataset.cpython-38.pyc differ
|
|
dataLoader/__pycache__/llff.cpython-38.pyc β src/dataset/__pycache__/llff_dataset.cpython-38.pyc
RENAMED
Binary files a/dataLoader/__pycache__/llff.cpython-38.pyc and b/src/dataset/__pycache__/llff_dataset.cpython-38.pyc differ
|
|
{dataLoader β src/dataset}/__pycache__/ray_utils.cpython-38.pyc
RENAMED
Binary files a/dataLoader/__pycache__/ray_utils.cpython-38.pyc and b/src/dataset/__pycache__/ray_utils.cpython-38.pyc differ
|
|
src/dataset/__pycache__/style_dataset.cpython-38.pyc
ADDED
Binary file (954 Bytes). View file
|
|