File size: 1,508 Bytes
3675918
 
 
 
 
 
1d64876
3675918
 
 
1d64876
3675918
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455b61a
 
3675918
 
455b61a
5366ab7
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
from layers import BilinearUpSampling2D
from tensorflow.keras.models import load_model
from utils import load_images, predict
import matplotlib.pyplot as plt
import numpy as np
import gradio as gr
from huggingface_hub import from_pretrained_keras

custom_objects = {'BilinearUpSampling2D': BilinearUpSampling2D, 'depth_loss_function': None}
print('Loading model...')
model = from_pretrained_keras("keras-io/monocular-depth-estimation", custom_objects=custom_objects, compile=False)
print('Successfully loaded model...')
examples = ['examples/00015_colors.png', 'examples/00084_colors.png', 'examples/00033_colors.png']


def infer(image):
    inputs = load_images([image])
    outputs = predict(model, inputs)
    plasma = plt.get_cmap('plasma')
    rescaled = outputs[0][:, :, 0]
    rescaled = rescaled - np.min(rescaled)
    rescaled = rescaled / np.max(rescaled)
    image_out = plasma(rescaled)[:, :, :3]
    return image_out


iface = gr.Interface(
    fn=infer,
    title="Monocular Depth Estimation",
    description = "Keras Implementation of Unet architecture with Densenet201 backbone for estimating the depth of image 📏",
    inputs=[gr.inputs.Image(label="image", type="numpy", shape=(640, 480))],
    outputs="image",
    article = "Author: <a href=\"https://huggingface.co/vumichien\">Vu Minh Chien</a>. The ideal based on the keras example from <a href=\"https://keras.io/examples/vision/depth_estimation/\">Victor Basu</a>",
    examples=examples, cache_examples=True).launch(debug=True)