geetu040 commited on
Commit
cb54bbf
·
1 Parent(s): 0744519

upload app

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.jpg filter=lfs diff=lfs merge=lfs -text
37
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
38
+ *.png filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from model import predict
4
+
5
+ examples_dir = "assets/examples/"
6
+ examples = [[os.path.join(examples_dir, filename)] for filename in os.listdir(examples_dir)]
7
+
8
+ interface = gr.Interface(
9
+ fn=predict,
10
+ inputs=gr.Image(type="pil"),
11
+ outputs=gr.Image(type="pil"),
12
+ title="DepthPro: Monocular Depth Estimation",
13
+ examples=examples,
14
+ )
15
+
16
+ if __name__ == "__main__":
17
+ interface.launch()
assets/examples/Jordi_cat_portrait.jpg ADDED

Git LFS Details

  • SHA256: 97f35029e548ecd745c2efd1e1d9e55732445f041ef5cac52888f1cabeed3948
  • Pointer size: 132 Bytes
  • Size of remote file: 6.5 MB
assets/examples/cubes.png ADDED

Git LFS Details

  • SHA256: 74d8b7d6a0a3b1ecbd4e64b66de139642df05e995fdfddfaa64e4023445df96c
  • Pointer size: 131 Bytes
  • Size of remote file: 929 kB
assets/examples/girl_on_desk.jpg ADDED

Git LFS Details

  • SHA256: 90c2df73b532c220071c2ec6ca8e1598fa2bf5a1143a78f32f6c11f93d3436a9
  • Pointer size: 131 Bytes
  • Size of remote file: 125 kB
assets/examples/girl_praying.jpg ADDED

Git LFS Details

  • SHA256: fa4543017252b5e3d5ab74a92922454a82a935f59222d6d04a544a6bd0a67e20
  • Pointer size: 131 Bytes
  • Size of remote file: 156 kB
assets/examples/tiger.jpg ADDED

Git LFS Details

  • SHA256: d98e8954c3ca5a3f01b9848f8d1b11331fcdd3e2373b8b0b1a639ef2055612aa
  • Pointer size: 131 Bytes
  • Size of remote file: 433 kB
model.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import torch
3
+
4
+ # custom installation from this PR: https://github.com/huggingface/transformers/pull/34583
5
+ # !pip install git+https://github.com/geetu040/transformers.git@depth-pro-projects#egg=transformers
6
+ from transformers import DepthProImageProcessorFast, DepthProForDepthEstimation
7
+
8
+ # initialize processor and model
9
+ checkpoint = "geetu040/DepthPro"
10
+ revision = "project"
11
+ image_processor = DepthProImageProcessorFast.from_pretrained(checkpoint, revision=revision)
12
+ model = DepthProForDepthEstimation.from_pretrained(checkpoint, revision=revision)
13
+ model = model.to('cuda')
14
+
15
+ def predict(image):
16
+ # inference
17
+
18
+ # prepare image for the model
19
+ inputs = image_processor(images=image, return_tensors="pt")
20
+ inputs = {k: v.to('cuda') for k, v in inputs.items()}
21
+
22
+ with torch.no_grad():
23
+ outputs = model(**inputs)
24
+
25
+ # interpolate to original size
26
+ post_processed_output = image_processor.post_process_depth_estimation(
27
+ outputs, target_sizes=[(image.height, image.width)],
28
+ )
29
+
30
+ # visualize the prediction
31
+ depth = post_processed_output[0]["predicted_depth"]
32
+ depth = (depth - depth.min()) / depth.max()
33
+ depth = depth * 255.
34
+ depth = depth.detach().cpu().numpy()
35
+ depth = Image.fromarray(depth.astype("uint8"))
36
+
37
+ return depth
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ pillow
4
+ torch
5
+ torchvision
6
+ git+https://github.com/geetu040/transformers.git@depth-pro-projects#egg=transformers