@@ -31,10 +31,10 @@ def picture_anisotropic():
31
31
32
32
33
33
def _picture (base_dir , scale_set , indices ):
34
- for name in tqdm ([
34
+ for name in tqdm (args_or ( [
35
35
"bbq" , "cliffs" , "colosseo" , "crystals" , "firenze" , "firewood" , "mutter" , "peak" , "portal" , "rue" ,
36
36
"schaumbrunnen" , "steepshore" , "toomuchbleach" , "tunnelrampe" , "zebras"
37
- ], desc = "name" , leave = False ):
37
+ ]) , desc = "name" , leave = False ):
38
38
for index in tqdm (indices , desc = "scale" , leave = False ):
39
39
gauss_img = _prepare_picture_image (ngssf .results .load_benchmark ("gauss" , "picture" , name , scale_set , index ))
40
40
pred_img = _prepare_picture_image (ngssf .results .load_benchmark ("neural" , "picture" , name , scale_set , index ))
@@ -45,12 +45,14 @@ def _picture(base_dir, scale_set, indices):
45
45
46
46
47
47
def picture_foveation ():
48
- field = ngssf .results .load_neural_field ("neural" , "picture" , "squirrel" ).cuda ()
48
+ name = arg_or ("squirrel" )
49
+ field = ngssf .results .load_neural_field ("neural" , "picture" , name ).cuda ()
49
50
res = 512
50
51
X = ngssf .util .grid_coords (res , 2 , device = "cuda" )
51
52
with torch .no_grad ():
52
53
pred_img = field (X , (X .norm (dim = 1 ) - 0.35 ).clamp (0 ) ** 3 / 200 ).T .reshape (3 , res , res )
53
- _write_image (ngssf .results .visualizations_dir () / "picture_foveation.jpg" , _prepare_picture_image (pred_img ))
54
+ img = _prepare_picture_image (pred_img )
55
+ _write_image (ngssf .results .visualizations_dir () / "picture_foveation" / f"{ name } .jpg" , img )
54
56
55
57
56
58
def _prepare_picture_image (img ):
@@ -59,7 +61,7 @@ def _prepare_picture_image(img):
59
61
60
62
def mesh_isotropic ():
61
63
scale_set = "variance_benchmark"
62
- for name in tqdm (ngssf .data .names ("mesh" ), desc = "name" , leave = False ):
64
+ for name in tqdm (args_or ( ngssf .data .names ("mesh" ) ), desc = "name" , leave = False ):
63
65
d = ngssf .results .visualizations_dir () / "mesh_isotropic"
64
66
dg = d / name / "gauss"
65
67
dn = d / name / "neural"
@@ -73,9 +75,10 @@ def mesh_isotropic():
73
75
74
76
75
77
def mesh_anisotropic ():
76
- d = ngssf .results .visualizations_dir () / "mesh_anisotropic"
78
+ name = arg_or ("thai" )
79
+ d = ngssf .results .visualizations_dir () / "mesh_anisotropic" / name
77
80
d .mkdir (parents = True , exist_ok = True )
78
- field = ngssf .results .load_neural_field ("neural" , "mesh" , "thai" ).cuda ()
81
+ field = ngssf .results .load_neural_field ("neural" , "mesh" , name ).cuda ()
79
82
for label , variances in [
80
83
("isotropic" , [1e-2 , 1e-2 , 1e-2 ]),
81
84
("anisotropic_horizontal" , [1e-2 , 1e-8 , 1e-2 ]),
@@ -84,12 +87,13 @@ def mesh_anisotropic():
84
87
scale = torch .diag (torch .tensor (variances ))
85
88
with torch .no_grad ():
86
89
grid = ngssf .util .eval_grid (256 , field , scale .cuda (), batch_size = 2 ** 18 ).cpu ()
87
- ngssf .util .mesh_from_grid (grid ).export (d / f"thai_ { label } .ply" )
90
+ ngssf .util .mesh_from_grid (grid ).export (d / f"{ label } .ply" )
88
91
89
92
90
93
def lightstage ():
94
+ name = arg_or ("cute" )
91
95
light_positions = ngssf .data .lightstage_light_positions ()
92
- field = ngssf .results .load_neural_field ("neural" , "lightstage" , "cute" ).cuda ()
96
+ field = ngssf .results .load_neural_field ("neural" , "lightstage" , name ).cuda ()
93
97
w , h = 512 , 384
94
98
X = torch .cat ([
95
99
torch .cartesian_prod (torch .linspace (- 0.75 , 0.75 , h ), torch .linspace (- 1 , 1 , w )).flip (1 ),
@@ -99,7 +103,7 @@ def lightstage():
99
103
with torch .no_grad ():
100
104
Y = field (X .cuda (), scale )
101
105
img = _prepare_image (Y .T .reshape (3 , h , w ))
102
- _write_image (ngssf .results .visualizations_dir () / "lightstage" / f"{ i } .jpg" , img )
106
+ _write_image (ngssf .results .visualizations_dir () / "lightstage" / name / f"{ i } .jpg" , img )
103
107
104
108
105
109
def picture_video ():
@@ -114,7 +118,7 @@ def picture_video():
114
118
spectrum_label = _label ("Spectrum" , 1300 , (128 , 32 ), overlay = True )
115
119
cov_label = _label ("Covariance" , 1300 , (128 , 32 ))
116
120
117
- for name in tqdm (["bbq" , "firewood" , "schaumbrunnen" , "tunnelrampe" ], leave = False ):
121
+ for name in tqdm (args_or ( ["bbq" , "firewood" , "schaumbrunnen" , "tunnelrampe" ]) , leave = False ):
118
122
orig_picture = torch .as_tensor (resize (ngssf .data .load ("picture" , name ).numpy (), (3 , 512 , 512 )), device = "cuda" )
119
123
neural_field = ngssf .results .load_neural_field ("neural" , "picture" , name ).cuda ()
120
124
gauss_field = ngssf .GaussianMonteCarloSmoothableField (ngssf .GridField (orig_picture , padding_mode = "reflection" ))
@@ -146,7 +150,7 @@ def _spectrum(picture):
146
150
def mesh_video_objects ():
147
151
cov_mats = torch .tensor (_mesh_video_covariance_matrices (), dtype = torch .float32 , device = "cuda" )
148
152
149
- for name in tqdm (ngssf .data .names ("mesh" ), leave = False ):
153
+ for name in tqdm (args_or ( ngssf .data .names ("mesh" ) ), leave = False ):
150
154
orig_mesh = ngssf .data .load ("mesh" , name )
151
155
neural_field = ngssf .results .load_neural_field ("neural" , "mesh" , name ).cuda ()
152
156
gauss_field = ngssf .GaussianMonteCarloSmoothableField (
@@ -191,12 +195,13 @@ def _mesh_video_covariance_matrices():
191
195
192
196
193
197
def lightstage_video ():
194
- d = ngssf .results .visualizations_dir ()
198
+ name = arg_or ("cute" )
199
+ d = ngssf .results .visualizations_dir () / "lightstage_video"
195
200
d .mkdir (parents = True , exist_ok = True )
196
201
197
- light_shots = ngssf .data .load ("lightstage" , "cute" )
202
+ light_shots = ngssf .data .load ("lightstage" , name )
198
203
light_pos = ngssf .data .lightstage_light_positions ()
199
- neural_field = ngssf .results .load_neural_field ("neural" , "lightstage" , "cute" ).cuda ()
204
+ neural_field = ngssf .results .load_neural_field ("neural" , "lightstage" , name ).cuda ()
200
205
neural_field .calibration_factors [1 ] = 500
201
206
gauss_field = ngssf .GaussianMonteCarloSmoothableField (ngssf .LightStageField (light_shots , light_pos ), {2 , 3 }).cuda ()
202
207
@@ -218,7 +223,7 @@ def lightstage_video():
218
223
cov_label = _label ("Covariance" , 1300 , (128 , 32 ))
219
224
plotted_pos = light_pos [(light_pos - (light_pos [2 ] + light_pos [22 ]) / 2 ).norm (dim = 1 ) < 0.15 ]
220
225
221
- video = VideoWriter (str (d / "lightstage_video .mp4" ), VideoWriter .fourcc ('a' , 'v' , 'c' , '1' ), 60 , (1152 , 384 ))
226
+ video = VideoWriter (str (d / f" { name } .mp4" ), VideoWriter .fourcc ('a' , 'v' , 'c' , '1' ), 60 , (1152 , 384 ))
222
227
for x_light , cov_mat in tqdm (list (zip (xs_light , cov_mats )), leave = False ):
223
228
X = torch .cat ([X_pixel , x_light .tile (w * h , 1 )], dim = 1 ).cuda ()
224
229
with torch .no_grad ():
@@ -304,5 +309,13 @@ def _write_image(file, img):
304
309
iio .imwrite (file , (img * 255 ).astype (np .uint8 ), quality = 90 )
305
310
306
311
312
+ def arg_or (default ):
313
+ return sys .argv [2 ] if len (sys .argv ) > 2 else default
314
+
315
+
316
+ def args_or (default ):
317
+ return sys .argv [2 :] if len (sys .argv ) > 2 else default
318
+
319
+
307
320
if __name__ == "__main__" :
308
321
globals ()[sys .argv [1 ]]()
0 commit comments