lyndonzheng commited on
Commit
3afeb70
1 Parent(s): cecdd84

support free image ratios

Browse files
Files changed (1) hide show
  1. app.py +37 -10
app.py CHANGED
@@ -37,12 +37,25 @@ def main():
37
  if input_image is None:
38
  raise gr.Error("No image uploaded!")
39
 
40
- def preprocess(image):
41
- image = TTF.resize(
42
- image, (cfg.dataset.height, cfg.dataset.width),
43
- interpolation=TT.InterpolationMode.BICUBIC
44
- )
45
- image = pad_border_fn(image)
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  return image
47
 
48
  @spaces.GPU()
@@ -58,7 +71,12 @@ def main():
58
  outputs = model(inputs)
59
 
60
  # export reconstruction to ply
61
- save_ply(outputs, ply_out_path, num_gauss=2)
 
 
 
 
 
62
 
63
  return ply_out_path
64
 
@@ -93,6 +111,10 @@ def main():
93
  )
94
  with gr.Row():
95
  submit = gr.Button("Generate", elem_id="generate", variant="primary")
 
 
 
 
96
 
97
  with gr.Row(variant="panel"):
98
  gr.Examples(
@@ -102,6 +124,11 @@ def main():
102
  './demo_examples/kitti_03.png',
103
  './demo_examples/re10k_05.jpg',
104
  './demo_examples/re10k_06.jpg',
 
 
 
 
 
105
  ],
106
  inputs=[input_image],
107
  cache_examples=False,
@@ -116,7 +143,7 @@ def main():
116
  with gr.Row():
117
  with gr.Tab("Reconstruction"):
118
  output_model = gr.Model3D(
119
- height=512,
120
  label="Output Model",
121
  interactive=False
122
  )
@@ -124,7 +151,7 @@ def main():
124
  gr.Markdown(
125
  """
126
  ## Comments:
127
- 1. If you run the demo online, the first example you upload should take about 25 seconds (with preprocessing, saving and overhead), the following take about 14s.
128
  2. The 3D viewer shows a .ply mesh extracted from a mix of 3D Gaussians. This is only an approximations and artefacts might show.
129
  3. Known limitations include:
130
  - a black dot appearing on the model from some viewpoints
@@ -145,7 +172,7 @@ def main():
145
 
146
  submit.click(fn=check_input_image, inputs=[input_image]).success(
147
  fn=preprocess,
148
- inputs=[input_image],
149
  outputs=[processed_image],
150
  ).success(
151
  fn=reconstruct_and_export,
 
37
  if input_image is None:
38
  raise gr.Error("No image uploaded!")
39
 
40
+ def preprocess(image, dynamic_size=False, padding=True):
41
+ w, h = image.size
42
+ size = 32
43
+ if dynamic_size:
44
+ while max(h, w) // size > 20:
45
+ size *=2
46
+ image = TTF.center_crop(image, (h // size * size, w // size * size))
47
+ image = TTF.resize(image, (h // size * 32, w // size * 32), interpolation=TT.InterpolationMode.BICUBIC)
48
+ model.cfg.dataset.width, model.cfg.dataset.height = image.size
49
+ model.set_backproject()
50
+ else:
51
+ image = TTF.resize(
52
+ image, (cfg.dataset.height, cfg.dataset.width),
53
+ interpolation=TT.InterpolationMode.BICUBIC
54
+ )
55
+ if padding:
56
+ image = pad_border_fn(image)
57
+ else:
58
+ model.cfg.dataset.pad_border_aug = 0
59
  return image
60
 
61
  @spaces.GPU()
 
71
  outputs = model(inputs)
72
 
73
  # export reconstruction to ply
74
+ save_ply(outputs,
75
+ ply_out_path,
76
+ num_gauss=model.cfg.model.gaussians_per_pixel,
77
+ h=model.cfg.dataset.height,
78
+ w=model.cfg.dataset.width,
79
+ pad=model.cfg.dataset.pad_border_aug)
80
 
81
  return ply_out_path
82
 
 
111
  )
112
  with gr.Row():
113
  submit = gr.Button("Generate", elem_id="generate", variant="primary")
114
+
115
+ with gr.Row():
116
+ dynamic_size = gr.Checkbox(True, interactive=True, label='Use the original image ration')
117
+ padding = gr.Checkbox(True, interactive=True, label='add padding to the image')
118
 
119
  with gr.Row(variant="panel"):
120
  gr.Examples(
 
124
  './demo_examples/kitti_03.png',
125
  './demo_examples/re10k_05.jpg',
126
  './demo_examples/re10k_06.jpg',
127
+ './demo_examples/christ_church_cathedral.png',
128
+ './demo_examples/radcliffe.png',
129
+ './demo_examples/blenheim_palace_bedroom.png',
130
+ './demo_examples/blenheim_palace_living.png',
131
+ './demo_examples/blenheim_palace.JPG',
132
  ],
133
  inputs=[input_image],
134
  cache_examples=False,
 
143
  with gr.Row():
144
  with gr.Tab("Reconstruction"):
145
  output_model = gr.Model3D(
146
+ height=640,
147
  label="Output Model",
148
  interactive=False
149
  )
 
151
  gr.Markdown(
152
  """
153
  ## Comments:
154
+ 1. If you run the demo online, the first example you upload should take about 25 seconds (with preprocessing, saving and overhead), the following take about 14s (due to the .ply visualisation).
155
  2. The 3D viewer shows a .ply mesh extracted from a mix of 3D Gaussians. This is only an approximations and artefacts might show.
156
  3. Known limitations include:
157
  - a black dot appearing on the model from some viewpoints
 
172
 
173
  submit.click(fn=check_input_image, inputs=[input_image]).success(
174
  fn=preprocess,
175
+ inputs=[input_image, dynamic_size, padding],
176
  outputs=[processed_image],
177
  ).success(
178
  fn=reconstruct_and_export,