Skip to content

Commit cc3af5b

Browse files
committed
voxel model, [duration,fps,cuda] opts for video
1 parent d5bcb17 commit cc3af5b

File tree

4 files changed

+408
-85
lines changed

4 files changed

+408
-85
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/videos
33

44
__pycache__/
5-
.vscode/
5+
.vscode/
6+
.ipynb_checkpoints

Main.ipynb

Lines changed: 80 additions & 80 deletions
Large diffs are not rendered by default.

Voxels.ipynb

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

gen_video.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from dataset import get_rays
1010

11-
def gen_video(dataset, model, path):
11+
def gen_video(dataset, model, path, duration=2, fps=12, cuda=True):
1212
camxs = dataset.poses[:, 0, -1]
1313
camzs = dataset.poses[:, 2, -1]
1414
cam_left_id = np.argmin(camxs + camzs)
@@ -21,6 +21,7 @@ def gen_video(dataset, model, path):
2121
ease_quad = lambda x: 2 * x**2 if x < 0.5 else 1 - (-2 * x + 2)**2 / 2
2222

2323
def make_frame(t):
24+
t = t * 2 / duration
2425
t = ease_quad(saw(t))
2526

2627
a = np.array
@@ -34,12 +35,14 @@ def make_frame(t):
3435

3536
H, W, focal = dataset.H, dataset.W, dataset.focal
3637
with torch.no_grad():
37-
rays = get_rays(H, W, focal, pose_t).cuda()
38+
rays = get_rays(H, W, focal, pose_t)
39+
if cuda:
40+
rays = rays.cuda()
3841
pred = model(rays)
3942
pred_r = transforms.Resize(256)(pred.clip(0, 1).reshape(H, W, 3).permute(2,0,1))
4043
img = pred_r.permute(1,2,0).multiply(255).int().cpu().numpy()
4144
return img
4245

4346
os.makedirs(os.path.dirname(path), exist_ok=True)
44-
clip = mpy.VideoClip(make_frame, duration=2)
45-
clip.write_videofile(path, fps=12)
47+
clip = mpy.VideoClip(make_frame, duration=duration)
48+
clip.write_videofile(path, fps=fps)

0 commit comments

Comments
 (0)