File size: 913 Bytes
ccd0c5e
 
6f2a79e
ccd0c5e
 
6f2a79e
 
ccd0c5e
 
d1c9b62
6f2a79e
 
 
 
d1c9b62
6f2a79e
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd0c5e
6f2a79e
b4bbe67
ccd0c5e
b4bbe67
6f2a79e
 
ccd0c5e
6f2a79e
ccd0c5e
6f2a79e
 
ccd0c5e
 
6f2a79e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

import gradio as gr

import matplotlib.pyplot as plt
import cv2
import torch
import timm
import numpy as np

midas = torch.hub.load('intel-isl/MiDaS', 'DPT_Hybrid')
midas.to('cpu')
midas.eval()

transforms = torch.hub.load('intel-isl/MiDaS', 'transforms')
transform = transforms.dpt_transform

def predict_image(img): 
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

  input_batch = transform(img).to('cpu')
  with torch.no_grad():
    prediction = midas(input_batch)

    prediction = torch.nn.functional.interpolate(
        prediction.unsqueeze(1),
        size=img.shape[:2],
        mode="bicubic",
        align_corners=False,
    ).squeeze()

  img = prediction.cpu().numpy()
  a = img.max() 

  img = (img / a)*255
  out = (img).astype(np.uint8)
 

  return out

    
image = gr.inputs.Image()

label = gr.outputs.Label('ok')
gr.Interface(fn=predict_image, inputs=image, outputs=image).launch(debug='True')