haotongl commited on
Commit
94c12b7
1 Parent(s): dd53be2

inital version

Browse files
Files changed (2) hide show
  1. app.py +17 -16
  2. promptda/utils/io_wrapper.py +3 -3
app.py CHANGED
@@ -45,6 +45,8 @@ def delete_later(path: Union[str, os.PathLike], delay: int = 300):
45
 
46
  @spaces.GPU
47
  def run_with_gpu(image, prompt_depth):
 
 
48
  depth = model.predict(image, prompt_depth)
49
  depth = depth[0, 0].detach().cpu().numpy()
50
  return depth
@@ -121,6 +123,8 @@ def run(input_file, resolution):
121
  DESCRIPTION = """
122
  # Estimate accurate and high-resolution depth maps from your iPhone capture.
123
 
 
 
124
  ## Requirements:
125
  1. iPhone 12 Pro or later Pro models, iPad 2020 Pro or later Pro models
126
  2. Free iOS App: [Stray Scanner App](https://apps.apple.com/us/app/stray-scanner/id1557051662)
@@ -140,35 +144,24 @@ Note:
140
  def main(share: bool):
141
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
142
  gr.Markdown(DESCRIPTION)
143
-
144
-
145
 
146
  with gr.Row():
147
- input_file = gr.File(type="filepath", label="Upload a stray scanner app capture zip file")
148
  resolution = gr.Dropdown(choices=['756x1008', '1428x1904'], value='756x1008', label="Inference resolution")
149
  submit_btn = gr.Button("Submit")
150
 
151
- gr.Examples(examples=[
152
- ["data/assets/example0_chair.zip", "756x1008"]
153
- ],
154
- inputs=[input_file, resolution],
155
- # outputs=[output_rgb, output_depths, output_3d_model, output_ply, output_depth_map],
156
- label="Examples",
157
- )
158
-
159
  with gr.Row():
160
  with gr.Column():
161
  output_rgb = gr.Image(type="numpy", label="RGB Image")
162
  with gr.Column():
163
- output_depths = ImageSlider(label="Depth map / prompt depth", position=0.5)
164
 
165
  with gr.Row():
166
  with gr.Column():
167
  output_3d_model = gr.Model3D(label="3D Viewer", display_mode='solid', clear_color=[1.0, 1.0, 1.0, 1.0])
168
  with gr.Column():
169
- output_ply = gr.File(type="filepath", label="Download the unprojected point cloud as .ply file")
170
- output_depth_map = gr.File(type="filepath", label="Download the depth map as .png file")
171
-
172
  outputs = [
173
  output_rgb,
174
  output_depths,
@@ -176,7 +169,15 @@ def main(share: bool):
176
  output_ply,
177
  output_depth_map,
178
  ]
179
-
 
 
 
 
 
 
 
 
180
  submit_btn.click(run,
181
  inputs=[input_file, resolution],
182
  outputs=outputs)
 
45
 
46
  @spaces.GPU
47
  def run_with_gpu(image, prompt_depth):
48
+ image = image.to(DEVICE)
49
+ prompt_depth = prompt_depth.to(DEVICE)
50
  depth = model.predict(image, prompt_depth)
51
  depth = depth[0, 0].detach().cpu().numpy()
52
  return depth
 
123
  DESCRIPTION = """
124
  # Estimate accurate and high-resolution depth maps from your iPhone capture.
125
 
126
+ Project Page: [Prompt Depth Anything](https://promptda.github.io/)
127
+
128
  ## Requirements:
129
  1. iPhone 12 Pro or later Pro models, iPad 2020 Pro or later Pro models
130
  2. Free iOS App: [Stray Scanner App](https://apps.apple.com/us/app/stray-scanner/id1557051662)
 
144
  def main(share: bool):
145
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
146
  gr.Markdown(DESCRIPTION)
 
 
147
 
148
  with gr.Row():
149
+ input_file = gr.File(type="filepath", label="Stray scanner app capture zip file")
150
  resolution = gr.Dropdown(choices=['756x1008', '1428x1904'], value='756x1008', label="Inference resolution")
151
  submit_btn = gr.Button("Submit")
152
 
 
 
 
 
 
 
 
 
153
  with gr.Row():
154
  with gr.Column():
155
  output_rgb = gr.Image(type="numpy", label="RGB Image")
156
  with gr.Column():
157
+ output_depths = ImageSlider(label="Output depth / prompt depth", position=0.5)
158
 
159
  with gr.Row():
160
  with gr.Column():
161
  output_3d_model = gr.Model3D(label="3D Viewer", display_mode='solid', clear_color=[1.0, 1.0, 1.0, 1.0])
162
  with gr.Column():
163
+ output_ply = gr.File(type="filepath", label="Download the unprojected point cloud as .ply file", height=30)
164
+ output_depth_map = gr.File(type="filepath", label="Download the depth map as .png file", height=30)
 
165
  outputs = [
166
  output_rgb,
167
  output_depths,
 
169
  output_ply,
170
  output_depth_map,
171
  ]
172
+ gr.Examples(examples=[
173
+ ["data/assets/example0_chair.zip", "756x1008"]
174
+ ],
175
+ fn=run,
176
+ inputs=[input_file, resolution],
177
+ outputs=outputs,
178
+ label="Examples",
179
+ cache_examples=True,
180
+ )
181
  submit_btn.click(run,
182
  inputs=[input_file, resolution],
183
  outputs=outputs)
promptda/utils/io_wrapper.py CHANGED
@@ -7,14 +7,14 @@ import cv2
7
 
8
  from promptda.utils.logger import Log
9
 
10
- DEVICE = 'cuda' if torch.cuda.is_available(
11
- ) else 'mps' if torch.backends.mps.is_available() else 'cpu'
12
 
13
 
14
  def to_tensor_func(arr):
15
  if arr.ndim == 2:
16
  arr = arr[:, :, np.newaxis]
17
- return torch.from_numpy(arr).permute(2, 0, 1).unsqueeze(0).to(DEVICE)
18
 
19
 
20
  def to_numpy_func(tensor):
 
7
 
8
  from promptda.utils.logger import Log
9
 
10
+ # DEVICE = 'cuda' if torch.cuda.is_available(
11
+ # ) else 'mps' if torch.backends.mps.is_available() else 'cpu'
12
 
13
 
14
  def to_tensor_func(arr):
15
  if arr.ndim == 2:
16
  arr = arr[:, :, np.newaxis]
17
+ return torch.from_numpy(arr).permute(2, 0, 1).unsqueeze(0)
18
 
19
 
20
  def to_numpy_func(tensor):