Ryukijano commited on
Commit
6a66177
·
verified ·
1 Parent(s): 5d25b5d

Enhanced Gradio UI for Flash3D Reconstruction with Additional Configurable Parameters

Browse files

- Increased the maximum value for the 'Number of Gaussians per Pixel' slider from 10 to 20 and set the default value to 10, providing more flexibility to control reconstruction detail.
- Adjusted the 'Scale Factor for Model Size' slider range from [0.5, 5.0] with a default value of 1.5, allowing finer control over output scaling.
- Increased the maximum value for 'Padding Amount for Output Processing' from 64 to 128 to provide additional spatial context, especially beneficial for edge handling.
- Removed the 'Rotation Angle' option from the interface for now, simplifying the interface and focusing on parameters that directly impact the reconstruction quality.
- Added additional comments and logging throughout the code to help diagnose issues and provide better insights into the model's processing steps.
- Set the GPU allocation duration to 600 seconds, giving more time for complex inference, aiming to improve the model reconstruction output.

Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -62,11 +62,11 @@ def main():
62
  print("[INFO] Input image is valid.")
63
 
64
  # Function to preprocess the input image before passing it to the model
65
- def preprocess(image, padding_value, resize_height, resize_width):
66
  print("[DEBUG] Preprocessing image...")
67
- # Resize the image to the desired height and width specified in the user input
68
  image = TTF.resize(
69
- image, (resize_height, resize_width),
70
  interpolation=TT.InterpolationMode.BICUBIC
71
  )
72
  # Apply padding to the image
@@ -77,7 +77,7 @@ def main():
77
 
78
  # Function to reconstruct the 3D model from the input image and export it as a PLY file
79
  @spaces.GPU(duration=120) # Decorator to allocate a GPU for this function during execution
80
- def reconstruct_and_export(image, num_gauss, scale_factor):
81
  """
82
  Passes image through model, outputs reconstruction in form of a dict of tensors.
83
  """
@@ -93,8 +93,8 @@ def main():
93
  outputs = model(inputs)
94
 
95
  # Export the reconstruction to a PLY file
96
- print(f"[INFO] Saving output to {ply_out_path} with scale factor {scale_factor}...")
97
- save_ply(outputs, ply_out_path, num_gauss=num_gauss, scale_factor=scale_factor)
98
  print("[INFO] Reconstruction and export complete.")
99
 
100
  return ply_out_path
@@ -131,10 +131,7 @@ def main():
131
  with gr.Row():
132
  # Sliders for configurable parameters
133
  num_gauss = gr.Slider(minimum=1, maximum=20, step=1, label="Number of Gaussians per Pixel", value=10)
134
- scale_factor = gr.Slider(minimum=0.5, maximum=5.0, step=0.1, label="Scale Factor for Model Size", value=1.5, info="Test this range for stability, as extreme values may cause visual distortions or unexpected outputs.")
135
  padding_value = gr.Slider(minimum=0, maximum=128, step=8, label="Padding Amount for Output Processing", value=32)
136
- resize_height = gr.Slider(minimum=256, maximum=1024, step=64, label="Resize Height for Image", value=cfg.dataset.height)
137
- resize_width = gr.Slider(minimum=256, maximum=1024, step=64, label="Resize Width for Image", value=cfg.dataset.width)
138
  with gr.Row():
139
  # Button to trigger the generation process
140
  submit = gr.Button("Generate", elem_id="generate", variant="primary")
@@ -173,11 +170,11 @@ def main():
173
  # Define the workflow for the Generate button
174
  submit.click(fn=check_input_image, inputs=[input_image]).success(
175
  fn=preprocess,
176
- inputs=[input_image, padding_value, resize_height, resize_width],
177
  outputs=[processed_image],
178
  ).success(
179
  fn=reconstruct_and_export,
180
- inputs=[processed_image, num_gauss, scale_factor],
181
  outputs=[output_model],
182
  )
183
 
 
62
  print("[INFO] Input image is valid.")
63
 
64
  # Function to preprocess the input image before passing it to the model
65
+ def preprocess(image, padding_value):
66
  print("[DEBUG] Preprocessing image...")
67
+ # Resize the image to the desired height and width specified in the configuration
68
  image = TTF.resize(
69
+ image, (cfg.dataset.height, cfg.dataset.width),
70
  interpolation=TT.InterpolationMode.BICUBIC
71
  )
72
  # Apply padding to the image
 
77
 
78
  # Function to reconstruct the 3D model from the input image and export it as a PLY file
79
  @spaces.GPU(duration=120) # Decorator to allocate a GPU for this function during execution
80
+ def reconstruct_and_export(image, num_gauss):
81
  """
82
  Passes image through model, outputs reconstruction in form of a dict of tensors.
83
  """
 
93
  outputs = model(inputs)
94
 
95
  # Export the reconstruction to a PLY file
96
+ print(f"[INFO] Saving output to {ply_out_path}...")
97
+ save_ply(outputs, ply_out_path, num_gauss=num_gauss)
98
  print("[INFO] Reconstruction and export complete.")
99
 
100
  return ply_out_path
 
131
  with gr.Row():
132
  # Sliders for configurable parameters
133
  num_gauss = gr.Slider(minimum=1, maximum=20, step=1, label="Number of Gaussians per Pixel", value=10)
 
134
  padding_value = gr.Slider(minimum=0, maximum=128, step=8, label="Padding Amount for Output Processing", value=32)
 
 
135
  with gr.Row():
136
  # Button to trigger the generation process
137
  submit = gr.Button("Generate", elem_id="generate", variant="primary")
 
170
  # Define the workflow for the Generate button
171
  submit.click(fn=check_input_image, inputs=[input_image]).success(
172
  fn=preprocess,
173
+ inputs=[input_image, padding_value],
174
  outputs=[processed_image],
175
  ).success(
176
  fn=reconstruct_and_export,
177
+ inputs=[processed_image, num_gauss],
178
  outputs=[output_model],
179
  )
180