hysts HF staff commited on
Commit
469bdef
1 Parent(s): ae67675

Visualize intermediate results

Browse files
Files changed (2) hide show
  1. app.py +12 -4
  2. model.py +28 -4
app.py CHANGED
@@ -42,8 +42,14 @@ with gr.Blocks(css='style.css') as demo:
42
  step=0.1)
43
  run_button = gr.Button('Run')
44
  with gr.Column():
45
- result = gr.Video(label='Result')
46
- output_file = gr.File(label='Output mesh file')
 
 
 
 
 
 
47
  with gr.Row():
48
  examples = [
49
  ['shapes/dragon1.obj', 'a photo of a dragon', 0, 7.5],
@@ -60,7 +66,7 @@ with gr.Blocks(css='style.css') as demo:
60
  guidance_scale,
61
  ],
62
  outputs=[
63
- result,
64
  output_file,
65
  ],
66
  cache_examples=False)
@@ -73,8 +79,10 @@ with gr.Blocks(css='style.css') as demo:
73
  guidance_scale,
74
  ],
75
  outputs=[
76
- result,
 
77
  output_file,
 
78
  ])
79
 
80
  demo.queue(max_size=5).launch(debug=True)
 
42
  step=0.1)
43
  run_button = gr.Button('Run')
44
  with gr.Column():
45
+ progress_text = gr.Text(label='Progress')
46
+ with gr.Tabs():
47
+ with gr.TabItem(label='Images from each viewpoint'):
48
+ viewpoint_images = gr.Gallery(show_label=False)
49
+ with gr.TabItem(label='Result video'):
50
+ result_video = gr.Video(show_label=False)
51
+ with gr.TabItem(label='Output mesh file'):
52
+ output_file = gr.File(show_label=False)
53
  with gr.Row():
54
  examples = [
55
  ['shapes/dragon1.obj', 'a photo of a dragon', 0, 7.5],
 
66
  guidance_scale,
67
  ],
68
  outputs=[
69
+ result_video,
70
  output_file,
71
  ],
72
  cache_examples=False)
 
79
  guidance_scale,
80
  ],
81
  outputs=[
82
+ viewpoint_images,
83
+ result_video,
84
  output_file,
85
+ progress_text,
86
  ])
87
 
88
  demo.queue(max_size=5).launch(debug=True)
model.py CHANGED
@@ -5,8 +5,10 @@ import pathlib
5
  import shlex
6
  import subprocess
7
  import sys
 
8
 
9
  import gradio as gr
 
10
 
11
  sys.path.append('TEXTurePaper')
12
 
@@ -48,8 +50,9 @@ class Model:
48
  subprocess.run(shlex.split(f'zip -r {out_path} {mesh_dir}'))
49
  return out_path
50
 
51
- def run(self, shape_path: str, text: str, seed: int,
52
- guidance_scale: float) -> tuple[str, str]:
 
53
  if not shape_path.endswith('.obj'):
54
  raise gr.Error('The input file is not .obj file.')
55
  if not self.check_num_faces(shape_path):
@@ -57,7 +60,28 @@ class Model:
57
 
58
  config = self.load_config(shape_path, text, seed, guidance_scale)
59
  trainer = TEXTure(config)
60
- trainer.paint()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  video_path = config.log.exp_dir / 'results' / 'step_00010_rgb.mp4'
62
  zip_path = self.zip_results(config.log.exp_dir)
63
- return video_path.as_posix(), zip_path
 
5
  import shlex
6
  import subprocess
7
  import sys
8
+ from typing import Generator
9
 
10
  import gradio as gr
11
+ import tqdm
12
 
13
  sys.path.append('TEXTurePaper')
14
 
 
50
  subprocess.run(shlex.split(f'zip -r {out_path} {mesh_dir}'))
51
  return out_path
52
 
53
+ def run(
54
+ self, shape_path: str, text: str, seed: int, guidance_scale: float
55
+ ) -> Generator[tuple[list[str], str | None, str | None, str], None, None]:
56
  if not shape_path.endswith('.obj'):
57
  raise gr.Error('The input file is not .obj file.')
58
  if not self.check_num_faces(shape_path):
 
60
 
61
  config = self.load_config(shape_path, text, seed, guidance_scale)
62
  trainer = TEXTure(config)
63
+
64
+ trainer.mesh_model.train()
65
+
66
+ total_steps = len(trainer.dataloaders['train'])
67
+ for step, data in enumerate(trainer.dataloaders['train'], start=1):
68
+ trainer.paint_step += 1
69
+ trainer.paint_viewpoint(data)
70
+ trainer.evaluate(trainer.dataloaders['val'],
71
+ trainer.eval_renders_path)
72
+ trainer.mesh_model.train()
73
+
74
+ sample_image_dir = config.log.exp_dir / 'vis' / 'eval'
75
+ sample_image_paths = sorted(
76
+ sample_image_dir.glob(f'step_{trainer.paint_step:05d}_*.jpg'))
77
+ sample_image_paths = [
78
+ path.as_posix() for path in sample_image_paths
79
+ ]
80
+ yield sample_image_paths, None, None, f'{step}/{total_steps}'
81
+
82
+ trainer.mesh_model.change_default_to_median()
83
+ trainer.full_eval()
84
+
85
  video_path = config.log.exp_dir / 'results' / 'step_00010_rgb.mp4'
86
  zip_path = self.zip_results(config.log.exp_dir)
87
+ yield sample_image_paths, video_path.as_posix(), zip_path, 'Done!'