Spaces:
Runtime error
Runtime error
Commit
·
5d7e7c2
1
Parent(s):
65af420
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import sys
|
| 2 |
import os
|
| 3 |
import os
|
| 4 |
import html
|
|
@@ -10,10 +9,8 @@ from tqdm import tqdm
|
|
| 10 |
|
| 11 |
os.system("git clone https://github.com/FrozenBurning/SceneDreamer.git")
|
| 12 |
|
| 13 |
-
import torch
|
| 14 |
-
|
| 15 |
pretrained_model = dict(file_url='https://drive.google.com/uc?id=1IFu1vNrgF1EaRqPizyEgN_5Vt7Fyg0Mj',
|
| 16 |
-
alt_url='', file_size=330571863,
|
| 17 |
file_path='./scenedreamer_released.pt',)
|
| 18 |
|
| 19 |
|
|
@@ -106,8 +103,7 @@ from PIL import Image
|
|
| 106 |
|
| 107 |
def parse_args():
|
| 108 |
parser = argparse.ArgumentParser(description='Training')
|
| 109 |
-
parser.add_argument('--config', type=str, default='./configs/scenedreamer_inference.yaml'
|
| 110 |
-
help='Path to the training config file.')
|
| 111 |
parser.add_argument('--checkpoint', default='./scenedreamer_released.pt',
|
| 112 |
help='Checkpoint path.')
|
| 113 |
parser.add_argument('--output_dir', type=str, default='./test/',
|
|
@@ -151,10 +147,11 @@ def get_bev(seed):
|
|
| 151 |
print('[PCGGenerator] Generating BEV scene representation...')
|
| 152 |
os.system('python terrain_generator.py --size {} --seed {} --outdir {}'.format(net_G.voxel.sample_size, seed, world_dir))
|
| 153 |
heightmap_path = os.path.join(world_dir, 'heightmap.png')
|
| 154 |
-
semantic_path = os.path.join(world_dir, '
|
| 155 |
heightmap = Image.open(heightmap_path)
|
| 156 |
semantic = Image.open(semantic_path)
|
| 157 |
return semantic, heightmap
|
|
|
|
| 158 |
def get_video(seed, num_frames):
|
| 159 |
device = torch.device('cuda')
|
| 160 |
rng_cuda = torch.Generator(device=device)
|
|
@@ -168,13 +165,12 @@ def get_video(seed, num_frames):
|
|
| 168 |
z = torch.empty(1, net_G.style_dims, dtype=torch.float32, device=device)
|
| 169 |
z.normal_(generator=rng_cuda)
|
| 170 |
net_G.inference_givenstyle(z, current_outdir, **vars(cfg.inference_args))
|
| 171 |
-
return os.path.join(current_outdir
|
| 172 |
|
| 173 |
markdown=f'''
|
| 174 |
# SceneDreamer: Unbounded 3D Scene Generation from 2D Image Collections
|
| 175 |
|
| 176 |
Authored by Zhaoxi Chen, Guangcong Wang, Ziwei Liu
|
| 177 |
-
|
| 178 |
### Useful links:
|
| 179 |
- [Official Github Repo](https://github.com/FrozenBurning/SceneDreamer)
|
| 180 |
- [Project Page](https://scene-dreamer.github.io/)
|
|
@@ -190,17 +186,17 @@ with gr.Blocks() as demo:
|
|
| 190 |
with gr.Column():
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column():
|
| 193 |
-
semantic = gr.Image(type="pil",shape=(2048, 2048))
|
| 194 |
with gr.Column():
|
| 195 |
-
height = gr.Image(type="pil",shape=(2048, 2048))
|
| 196 |
with gr.Row():
|
| 197 |
# with gr.Column():
|
| 198 |
# image = gr.Image(type='pil', shape(540, 960))
|
| 199 |
with gr.Column():
|
| 200 |
video=gr.Video()
|
| 201 |
with gr.Row():
|
| 202 |
-
num_frames = gr.Slider(minimum=
|
| 203 |
-
user_seed = gr.Slider(minimum=0, maximum=999999, value=8888, label='Random seed
|
| 204 |
|
| 205 |
with gr.Row():
|
| 206 |
btn = gr.Button(value="Generate BEV")
|
|
@@ -209,4 +205,4 @@ with gr.Blocks() as demo:
|
|
| 209 |
btn.click(get_bev,[user_seed],[semantic, height])
|
| 210 |
btn_2.click(get_video,[user_seed, num_frames],[video])
|
| 211 |
|
| 212 |
-
demo.launch(debug=True)
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import os
|
| 3 |
import html
|
|
|
|
| 9 |
|
| 10 |
os.system("git clone https://github.com/FrozenBurning/SceneDreamer.git")
|
| 11 |
|
|
|
|
|
|
|
| 12 |
pretrained_model = dict(file_url='https://drive.google.com/uc?id=1IFu1vNrgF1EaRqPizyEgN_5Vt7Fyg0Mj',
|
| 13 |
+
alt_url='', file_size=330571863,
|
| 14 |
file_path='./scenedreamer_released.pt',)
|
| 15 |
|
| 16 |
|
|
|
|
| 103 |
|
| 104 |
def parse_args():
|
| 105 |
parser = argparse.ArgumentParser(description='Training')
|
| 106 |
+
parser.add_argument('--config', type=str, default='./configs/scenedreamer_inference.yaml', help='Path to the training config file.')
|
|
|
|
| 107 |
parser.add_argument('--checkpoint', default='./scenedreamer_released.pt',
|
| 108 |
help='Checkpoint path.')
|
| 109 |
parser.add_argument('--output_dir', type=str, default='./test/',
|
|
|
|
| 147 |
print('[PCGGenerator] Generating BEV scene representation...')
|
| 148 |
os.system('python terrain_generator.py --size {} --seed {} --outdir {}'.format(net_G.voxel.sample_size, seed, world_dir))
|
| 149 |
heightmap_path = os.path.join(world_dir, 'heightmap.png')
|
| 150 |
+
semantic_path = os.path.join(world_dir, 'colormap.png')
|
| 151 |
heightmap = Image.open(heightmap_path)
|
| 152 |
semantic = Image.open(semantic_path)
|
| 153 |
return semantic, heightmap
|
| 154 |
+
|
| 155 |
def get_video(seed, num_frames):
|
| 156 |
device = torch.device('cuda')
|
| 157 |
rng_cuda = torch.Generator(device=device)
|
|
|
|
| 165 |
z = torch.empty(1, net_G.style_dims, dtype=torch.float32, device=device)
|
| 166 |
z.normal_(generator=rng_cuda)
|
| 167 |
net_G.inference_givenstyle(z, current_outdir, **vars(cfg.inference_args))
|
| 168 |
+
return os.path.join(current_outdir, 'rgb_render.mp4')
|
| 169 |
|
| 170 |
markdown=f'''
|
| 171 |
# SceneDreamer: Unbounded 3D Scene Generation from 2D Image Collections
|
| 172 |
|
| 173 |
Authored by Zhaoxi Chen, Guangcong Wang, Ziwei Liu
|
|
|
|
| 174 |
### Useful links:
|
| 175 |
- [Official Github Repo](https://github.com/FrozenBurning/SceneDreamer)
|
| 176 |
- [Project Page](https://scene-dreamer.github.io/)
|
|
|
|
| 186 |
with gr.Column():
|
| 187 |
with gr.Row():
|
| 188 |
with gr.Column():
|
| 189 |
+
semantic = gr.Image(type="pil", shape=(2048, 2048))
|
| 190 |
with gr.Column():
|
| 191 |
+
height = gr.Image(type="pil", shape=(2048, 2048))
|
| 192 |
with gr.Row():
|
| 193 |
# with gr.Column():
|
| 194 |
# image = gr.Image(type='pil', shape(540, 960))
|
| 195 |
with gr.Column():
|
| 196 |
video=gr.Video()
|
| 197 |
with gr.Row():
|
| 198 |
+
num_frames = gr.Slider(minimum=10, maximum=200, value=10, label='Number of rendered frames')
|
| 199 |
+
user_seed = gr.Slider(minimum=0, maximum=999999, value=8888, label='Random seed')
|
| 200 |
|
| 201 |
with gr.Row():
|
| 202 |
btn = gr.Button(value="Generate BEV")
|
|
|
|
| 205 |
btn.click(get_bev,[user_seed],[semantic, height])
|
| 206 |
btn_2.click(get_video,[user_seed, num_frames],[video])
|
| 207 |
|
| 208 |
+
demo.launch(debug=True)
|