Spaces:
Running
Running
depth
#1
by
nomii
- opened
- README.md +2 -2
- app.py +7 -6
- requirements.txt +1 -1
README.md
CHANGED
@@ -4,9 +4,9 @@ emoji: ⚡
|
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 2.8.13
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
CHANGED
@@ -1,17 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
import torch
|
4 |
import numpy as np
|
5 |
from PIL import Image
|
6 |
|
7 |
torch.hub.download_url_to_file('http://images.cocodataset.org/val2017/000000039769.jpg', 'cats.jpg')
|
8 |
|
9 |
-
|
10 |
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
11 |
|
12 |
def process_image(image):
|
13 |
# prepare image for the model
|
14 |
-
encoding =
|
15 |
|
16 |
# forward pass
|
17 |
with torch.no_grad():
|
@@ -37,9 +37,10 @@ description = "Demo for Intel's DPT, a Dense Prediction Transformer for state-of
|
|
37 |
examples =[['cats.jpg']]
|
38 |
|
39 |
iface = gr.Interface(fn=process_image,
|
40 |
-
inputs=gr.Image(type="pil"),
|
41 |
-
outputs=gr.Image(type="pil", label="predicted depth"),
|
42 |
title=title,
|
43 |
description=description,
|
44 |
-
examples=examples
|
|
|
45 |
iface.launch(debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import DPTFeatureExtractor, DPTForDepthEstimation
|
3 |
import torch
|
4 |
import numpy as np
|
5 |
from PIL import Image
|
6 |
|
7 |
torch.hub.download_url_to_file('http://images.cocodataset.org/val2017/000000039769.jpg', 'cats.jpg')
|
8 |
|
9 |
+
feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
10 |
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
11 |
|
12 |
def process_image(image):
|
13 |
# prepare image for the model
|
14 |
+
encoding = feature_extractor(image, return_tensors="pt")
|
15 |
|
16 |
# forward pass
|
17 |
with torch.no_grad():
|
|
|
37 |
examples =[['cats.jpg']]
|
38 |
|
39 |
iface = gr.Interface(fn=process_image,
|
40 |
+
inputs=gr.inputs.Image(type="pil"),
|
41 |
+
outputs=gr.outputs.Image(type="pil", label="predicted depth"),
|
42 |
title=title,
|
43 |
description=description,
|
44 |
+
examples=examples,
|
45 |
+
enable_queue=True)
|
46 |
iface.launch(debug=True)
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
torch
|
2 |
-
transformers
|
3 |
numpy
|
4 |
Pillow
|
|
|
1 |
torch
|
2 |
+
git+https://github.com/nielsrogge/transformers.git@add_dpt_redesign#egg=transformers
|
3 |
numpy
|
4 |
Pillow
|