atwang commited on
Commit
3f76c42
1 Parent(s): 3a59b45

attempt to fix hf space setup

Browse files
Files changed (3) hide show
  1. Dockerfile +2 -2
  2. README.md +0 -1
  3. app.py +98 -95
Dockerfile CHANGED
@@ -4,7 +4,7 @@ FROM nvidia/cuda:11.7.1-devel-ubuntu22.04
4
  ENV LC_ALL C.UTF-8
5
  ENV LANG C.UTF-8
6
  ARG UID=1000
7
- ARG UNAME=ubuntu
8
  ARG DEBIAN_FRONTEND=noninteractive
9
  ENV PATH="/home/$UNAME/.local/bin:$PATH"
10
 
@@ -58,4 +58,4 @@ ENV PYTHONPATH="/usr/local/lib/python3.10/dist-packages/MultiScaleDeformableAtte
58
 
59
  WORKDIR /home/$UNAME/opdmulti-demo
60
 
61
- RUN python3.10 app.py
 
4
  ENV LC_ALL C.UTF-8
5
  ENV LANG C.UTF-8
6
  ARG UID=1000
7
+ ARG UNAME=user
8
  ARG DEBIAN_FRONTEND=noninteractive
9
  ENV PATH="/home/$UNAME/.local/bin:$PATH"
10
 
 
58
 
59
  WORKDIR /home/$UNAME/opdmulti-demo
60
 
61
+ CMD ["python3.10", "app.py"]
README.md CHANGED
@@ -4,7 +4,6 @@ emoji: 🌍
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: docker
7
- app_port: 7860
8
  pinned: false
9
  license: mit
10
  ---
 
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: docker
 
7
  pinned: false
8
  license: mit
9
  ---
app.py CHANGED
@@ -174,103 +174,106 @@ def clear_outputs():
174
  return [gr.update(value=None, visible=(idx == 0)) for idx in range(MAX_PARTS)]
175
 
176
 
177
- print("Starting up app...")
178
-
179
- with gr.Blocks() as demo:
180
- gr.Markdown(
 
 
 
 
 
 
 
 
 
 
181
  """
182
- # OPDMulti Demo
183
- We tackle the openable-part-detection (OPD) problem where we identify in a single-view image parts that are openable and their motion parameters. Our OPDFORMER architecture outputs segmentations for openable parts on potentially multiple objects, along with each part’s motion parameters: motion type (translation or rotation, indicated by blue or purple mask), motion axis and origin (see green arrows and points). For each openable part, we predict the motion parameters (axis and origin) in object coordinates along with an object pose prediction to convert to camera coordinates.
184
-
185
- More information about the project, including code, can be found [here](https://3dlg-hcvc.github.io/OPDMulti/).
186
-
187
- Upload an image to see a visualization of its range of motion below. Only the RGB image is needed for the model itself, but the depth image is required as of now for the visualization of motion.
188
-
189
- If you know the intrinsic matrix of your camera, you can specify that here or otherwise use the default matrix which will work with any of the provided examples.
190
-
191
- You can also change the number of samples to define the number of states in the visualization generated.
192
- """
193
- )
194
-
195
- # inputs
196
- with gr.Row():
197
- rgb_image = gr.Image(
198
- image_mode="RGB", source="upload", type="filepath", label="RGB Image", show_label=True, interactive=True
199
- )
200
- depth_image = gr.Image(
201
- image_mode="I;16", source="upload", type="filepath", label="Depth Image", show_label=True, interactive=True
202
  )
203
-
204
- intrinsic = gr.Dataframe(
205
- value=[
206
- [
207
- 214.85935872395834,
208
- 0.0,
209
- 125.90160319010417,
210
- ],
211
- [
212
- 0.0,
213
- 214.85935872395834,
214
- 95.13726399739583,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  ],
216
- [
217
- 0.0,
218
- 0.0,
219
- 1.0,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  ],
221
- ],
222
- row_count=(3, "fixed"),
223
- col_count=(3, "fixed"),
224
- datatype="number",
225
- type="numpy",
226
- label="Intrinsic matrix",
227
- show_label=True,
228
- interactive=True,
229
- )
230
- num_samples = gr.Number(
231
- value=NUM_SAMPLES,
232
- label="Number of samples",
233
- show_label=True,
234
- interactive=True,
235
- precision=0,
236
- minimum=3,
237
- maximum=20,
238
- )
239
-
240
- # specify examples which can be used to start
241
- examples = gr.Examples(
242
- examples=[
243
- ["examples/59-4860.png", "examples/59-4860_d.png"],
244
- ["examples/174-8460.png", "examples/174-8460_d.png"],
245
- ["examples/187-0.png", "examples/187-0_d.png"],
246
- ["examples/187-23040.png", "examples/187-23040_d.png"],
247
- ],
248
- inputs=[rgb_image, depth_image],
249
- api_name=False,
250
- examples_per_page=2,
251
- )
252
-
253
- submit_btn = gr.Button("Run model")
254
-
255
- # output
256
- explanation = gr.Markdown(
257
- value=f"# Output\nClick on an image to see an animation of the part motion. As of now, only up to {MAX_PARTS} parts can be visualized due to limitations of the visualizer."
258
- )
259
-
260
- images = [
261
- gr.Image(type="pil", label=f"Part {idx + 1}", show_download_button=False, visible=(idx == 0))
262
- for idx in range(MAX_PARTS)
263
- ]
264
- for idx, image_comp in enumerate(images):
265
- image_comp.select(get_trigger(idx), inputs=rgb_image, outputs=image_comp, api_name=False)
266
-
267
- # if user changes input, clear output images
268
- rgb_image.change(clear_outputs, inputs=[], outputs=images, api_name=False)
269
- depth_image.change(clear_outputs, inputs=[], outputs=images, api_name=False)
270
-
271
- submit_btn.click(
272
- fn=predict, inputs=[rgb_image, depth_image, intrinsic, num_samples], outputs=images, api_name=False
273
- )
274
 
275
- demo.queue(api_open=False)
276
- demo.launch()
 
 
174
  return [gr.update(value=None, visible=(idx == 0)) for idx in range(MAX_PARTS)]
175
 
176
 
177
+ def run():
178
+ with gr.Blocks() as demo:
179
+ gr.Markdown(
180
+ """
181
+ # OPDMulti Demo
182
+ We tackle the openable-part-detection (OPD) problem where we identify in a single-view image parts that are openable and their motion parameters. Our OPDFORMER architecture outputs segmentations for openable parts on potentially multiple objects, along with each part’s motion parameters: motion type (translation or rotation, indicated by blue or purple mask), motion axis and origin (see green arrows and points). For each openable part, we predict the motion parameters (axis and origin) in object coordinates along with an object pose prediction to convert to camera coordinates.
183
+
184
+ More information about the project, including code, can be found [here](https://3dlg-hcvc.github.io/OPDMulti/).
185
+
186
+ Upload an image to see a visualization of its range of motion below. Only the RGB image is needed for the model itself, but the depth image is required as of now for the visualization of motion.
187
+
188
+ If you know the intrinsic matrix of your camera, you can specify that here or otherwise use the default matrix which will work with any of the provided examples.
189
+
190
+ You can also change the number of samples to define the number of states in the visualization generated.
191
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  )
193
+
194
+ # inputs
195
+ with gr.Row():
196
+ rgb_image = gr.Image(
197
+ image_mode="RGB", source="upload", type="filepath", label="RGB Image", show_label=True, interactive=True
198
+ )
199
+ depth_image = gr.Image(
200
+ image_mode="I;16", source="upload", type="filepath", label="Depth Image", show_label=True, interactive=True
201
+ )
202
+
203
+ intrinsic = gr.Dataframe(
204
+ value=[
205
+ [
206
+ 214.85935872395834,
207
+ 0.0,
208
+ 125.90160319010417,
209
+ ],
210
+ [
211
+ 0.0,
212
+ 214.85935872395834,
213
+ 95.13726399739583,
214
+ ],
215
+ [
216
+ 0.0,
217
+ 0.0,
218
+ 1.0,
219
+ ],
220
  ],
221
+ row_count=(3, "fixed"),
222
+ col_count=(3, "fixed"),
223
+ datatype="number",
224
+ type="numpy",
225
+ label="Intrinsic matrix",
226
+ show_label=True,
227
+ interactive=True,
228
+ )
229
+ num_samples = gr.Number(
230
+ value=NUM_SAMPLES,
231
+ label="Number of samples",
232
+ show_label=True,
233
+ interactive=True,
234
+ precision=0,
235
+ minimum=3,
236
+ maximum=20,
237
+ )
238
+
239
+ # specify examples which can be used to start
240
+ examples = gr.Examples(
241
+ examples=[
242
+ ["examples/59-4860.png", "examples/59-4860_d.png"],
243
+ ["examples/174-8460.png", "examples/174-8460_d.png"],
244
+ ["examples/187-0.png", "examples/187-0_d.png"],
245
+ ["examples/187-23040.png", "examples/187-23040_d.png"],
246
  ],
247
+ inputs=[rgb_image, depth_image],
248
+ api_name=False,
249
+ examples_per_page=2,
250
+ )
251
+
252
+ submit_btn = gr.Button("Run model")
253
+
254
+ # output
255
+ explanation = gr.Markdown(
256
+ value=f"# Output\nClick on an image to see an animation of the part motion. As of now, only up to {MAX_PARTS} parts can be visualized due to limitations of the visualizer."
257
+ )
258
+
259
+ images = [
260
+ gr.Image(type="pil", label=f"Part {idx + 1}", show_download_button=False, visible=(idx == 0))
261
+ for idx in range(MAX_PARTS)
262
+ ]
263
+ for idx, image_comp in enumerate(images):
264
+ image_comp.select(get_trigger(idx), inputs=rgb_image, outputs=image_comp, api_name=False)
265
+
266
+ # if user changes input, clear output images
267
+ rgb_image.change(clear_outputs, inputs=[], outputs=images, api_name=False)
268
+ depth_image.change(clear_outputs, inputs=[], outputs=images, api_name=False)
269
+
270
+ submit_btn.click(
271
+ fn=predict, inputs=[rgb_image, depth_image, intrinsic, num_samples], outputs=images, api_name=False
272
+ )
273
+
274
+ demo.queue(api_open=False)
275
+ demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
 
277
+ if __name__ == "__main__":
278
+ print("Starting up app...")
279
+ run()